details: http://www.bx.psu.edu/hg/galaxy/rev/2a15e0eca0b9 changeset: 2675:2a15e0eca0b9 user: jeremy goecks <jeremy.goecks@emory.edu> date: Thu Sep 10 16:48:11 2009 -0400 description: Support for (1) ordering tags and (2) page tags. 5 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/model/mapping.py lib/galaxy/model/migrate/versions/0018_ordered_tags_and_page_tags.py lib/galaxy/tags/tag_handler.py lib/galaxy/web/controllers/tag.py diffs (249 lines): diff -r dbbc63c0630a -r 2a15e0eca0b9 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Thu Sep 10 10:42:50 2009 -0400 +++ b/lib/galaxy/model/__init__.py Thu Sep 10 16:48:11 2009 -0400 @@ -1145,7 +1145,8 @@ return "Tag(id=%s, type=%i, parent_id=%s, name=%s)" % ( self.id, self.type, self.parent_id, self.name ) class ItemTagAssociation ( object ): - def __init__( self, item_id=None, tag_id=None, user_tname=None, value=None ): + def __init__( self, id=None, item_id=None, tag_id=None, user_tname=None, value=None ): + self.id = id self.item_id = item_id self.tag_id = tag_id self.user_tname = user_tname @@ -1165,6 +1166,8 @@ class HistoryDatasetAssociationTagAssociation ( ItemTagAssociation ): pass +class PageTagAssociation ( ItemTagAssociation ): + pass ## ---- Utility methods ------------------------------------------------------- diff -r dbbc63c0630a -r 2a15e0eca0b9 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Thu Sep 10 10:42:50 2009 -0400 +++ b/lib/galaxy/model/mapping.py Thu Sep 10 16:48:11 2009 -0400 @@ -552,6 +552,7 @@ UniqueConstraint( "name" ) ) HistoryTagAssociation.table = Table( "history_tag_association", metadata, + Column( "id", Integer, primary_key=True ), Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), Column( "user_tname", TrimmedString(255), index=True), @@ -559,6 +560,7 @@ Column( "user_value", TrimmedString(255), index=True) ) DatasetTagAssociation.table = Table( "dataset_tag_association", metadata, + Column( "id", Integer, primary_key=True ), Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ), Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), Column( "user_tname", TrimmedString(255), index=True), @@ -566,7 +568,16 @@ Column( "user_value", TrimmedString(255), index=True) ) HistoryDatasetAssociationTagAssociation.table = Table( "history_dataset_association_tag_association", metadata, + Column( "id", Integer, primary_key=True ), Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ), + Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), + Column( "user_tname", TrimmedString(255), index=True), + Column( "value", TrimmedString(255), index=True), + Column( "user_value", TrimmedString(255), index=True) ) + +PageTagAssociation.table = Table( "page_tag_association", metadata, + Column( "id", Integer, primary_key=True ), + Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ), Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), Column( "user_tname", TrimmedString(255), index=True), Column( "value", TrimmedString(255), index=True), @@ -672,7 +683,7 @@ visible_children=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.parent_id == HistoryDatasetAssociation.table.c.id ) & ( HistoryDatasetAssociation.table.c.visible == True ) ) ), - tags=relation(HistoryDatasetAssociationTagAssociation, backref='history_tag_associations') + tags=relation(HistoryDatasetAssociationTagAssociation, order_by=HistoryDatasetAssociationTagAssociation.table.c.id, backref='history_tag_associations') ) ) assign_mapper( context, Dataset, Dataset.table, @@ -689,7 +700,7 @@ active_library_associations=relation( LibraryDatasetDatasetAssociation, primaryjoin=( ( Dataset.table.c.id == LibraryDatasetDatasetAssociation.table.c.dataset_id ) & ( LibraryDatasetDatasetAssociation.table.c.deleted == False ) ) ), - tags=relation(DatasetTagAssociation, backref='datasets') + tags=relation(DatasetTagAssociation, order_by=DatasetTagAssociation.table.c.id, backref='datasets') ) ) assign_mapper( context, HistoryDatasetAssociationDisplayAtAuthorization, HistoryDatasetAssociationDisplayAtAuthorization.table, @@ -709,7 +720,7 @@ properties=dict( galaxy_sessions=relation( GalaxySessionToHistoryAssociation ), datasets=relation( HistoryDatasetAssociation, backref="history", order_by=asc(HistoryDatasetAssociation.table.c.hid) ), active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), viewonly=True ), - tags=relation(HistoryTagAssociation, backref="histories") + tags=relation(HistoryTagAssociation, order_by=HistoryTagAssociation.table.c.id, backref="histories") ) ) assign_mapper( context, HistoryUserShareAssociation, HistoryUserShareAssociation.table, @@ -967,7 +978,8 @@ primaryjoin=( Page.table.c.id == PageRevision.table.c.page_id ) ), latest_revision=relation( PageRevision, post_update=True, primaryjoin=( Page.table.c.latest_revision_id == PageRevision.table.c.id ), - lazy=False ) + lazy=False ), + tags=relation(PageTagAssociation, order_by=PageTagAssociation.table.c.id, backref="pages") ) ) assign_mapper( context, Tag, Tag.table, @@ -988,6 +1000,11 @@ properties=dict( tag=relation(Tag, backref="tagged_history_dataset_associations") ), primary_key=[HistoryDatasetAssociationTagAssociation.table.c.history_dataset_association_id, HistoryDatasetAssociationTagAssociation.table.c.tag_id] ) + +assign_mapper( context, PageTagAssociation, PageTagAssociation.table, + properties=dict( tag=relation(Tag, backref="tagged_pages") ), + primary_key=[PageTagAssociation.table.c.page_id, PageTagAssociation.table.c.tag_id] + ) def db_next_hid( self ): """ diff -r dbbc63c0630a -r 2a15e0eca0b9 lib/galaxy/model/migrate/versions/0018_ordered_tags_and_page_tags.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0018_ordered_tags_and_page_tags.py Thu Sep 10 16:48:11 2009 -0400 @@ -0,0 +1,116 @@ +""" +This migration script provides support for (a) ordering tags by recency and +(b) tagging pages. This script deletes all existing tags. +""" + +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.exceptions import * +from migrate import * +import migrate.changeset + +import datetime +now = datetime.datetime.utcnow + +# Need our custom types, but don't import anything else from model +from galaxy.model.custom_types import * + +import logging +log = logging.getLogger( __name__ ) + +metadata = MetaData( migrate_engine ) + +def display_migration_details(): + print "" + print "This migration script provides support for (a) ordering tags by recency and" + print "(b) tagging pages. This script deletes all existing tags." + +HistoryTagAssociation_table = Table( "history_tag_association", metadata, + Column( "id", Integer, primary_key=True ), + Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), + Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), + Column( "user_tname", TrimmedString(255), index=True), + Column( "value", TrimmedString(255), index=True), + Column( "user_value", TrimmedString(255), index=True) ) + +DatasetTagAssociation_table = Table( "dataset_tag_association", metadata, + Column( "id", Integer, primary_key=True ), + Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ), + Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), + Column( "user_tname", TrimmedString(255), index=True), + Column( "value", TrimmedString(255), index=True), + Column( "user_value", TrimmedString(255), index=True) ) + +HistoryDatasetAssociationTagAssociation_table = Table( "history_dataset_association_tag_association", metadata, + Column( "id", Integer, primary_key=True ), + Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ), + Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), + Column( "user_tname", TrimmedString(255), index=True), + Column( "value", TrimmedString(255), index=True), + Column( "user_value", TrimmedString(255), index=True) ) + +PageTagAssociation_table = Table( "page_tag_association", metadata, + Column( "id", Integer, primary_key=True ), + Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ), + Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), + Column( "user_tname", TrimmedString(255), index=True), + Column( "value", TrimmedString(255), index=True), + Column( "user_value", TrimmedString(255), index=True) ) + +def upgrade(): + display_migration_details() + metadata.reflect() + + # + # Recreate tables. + # + try: + HistoryTagAssociation_table.drop() + HistoryTagAssociation_table.create() + except Exception, e: + print "Recreating history_tag_association table failed: %s" % str( e ) + log.debug( "Recreating history_tag_association table failed: %s" % str( e ) ) + + try: + DatasetTagAssociation_table.drop() + DatasetTagAssociation_table.create() + except Exception, e: + print str(e) + log.debug( "Recreating dataset_tag_association table failed: %s" % str( e ) ) + + try: + HistoryDatasetAssociationTagAssociation_table.drop() + HistoryDatasetAssociationTagAssociation_table.create() + except OperationalError, e: + # Handle error that results from and index name that is too long; this occurs + # in MySQL. + if str(e).find("CREATE INDEX") != -1: + # Manually create index. + i = Index( "ix_hda_ta_history_dataset_association_id", HistoryDatasetAssociationTagAssociation_table.c.history_dataset_association_id ) + try: + i.create() + except Exception, e: + print str(e) + log.debug( "Adding index 'ix_hda_ta_history_dataset_association_id' to table 'history_dataset_association_tag_association' table failed: %s" % str( e ) ) + except Exception, e: + print str(e) + log.debug( "Recreating history_dataset_association_tag_association table failed: %s" % str( e ) ) + + # Create page_tag_association table. + try: + PageTagAssociation_table.create() + except Exception, e: + print str(e) + log.debug( "Creating page_tag_association table failed: %s" % str( e ) ) + +def downgrade(): + metadata.reflect() + + # No need to downgrade other tagging tables. They work fine with verision 16 code. + + # Drop page_tag_association table. + try: + PageTagAssociation_table.drop() + except Exception, e: + print str(e) + log.debug( "Dropping page_tag_association table failed: %s" % str( e ) ) diff -r dbbc63c0630a -r 2a15e0eca0b9 lib/galaxy/tags/tag_handler.py --- a/lib/galaxy/tags/tag_handler.py Thu Sep 10 10:42:50 2009 -0400 +++ b/lib/galaxy/tags/tag_handler.py Thu Sep 10 16:48:11 2009 -0400 @@ -1,4 +1,4 @@ -from galaxy.model import Tag, History, HistoryTagAssociation, Dataset, DatasetTagAssociation, HistoryDatasetAssociation, HistoryDatasetAssociationTagAssociation +from galaxy.model import Tag import re class TagHandler( object ): diff -r dbbc63c0630a -r 2a15e0eca0b9 lib/galaxy/web/controllers/tag.py --- a/lib/galaxy/web/controllers/tag.py Thu Sep 10 10:42:50 2009 -0400 +++ b/lib/galaxy/web/controllers/tag.py Thu Sep 10 16:48:11 2009 -0400 @@ -1,6 +1,9 @@ """ Tags Controller: handles tagging/untagging of entities and provides autocomplete support. """ + +from galaxy.model import History, HistoryTagAssociation, Dataset, DatasetTagAssociation, \ + HistoryDatasetAssociation, HistoryDatasetAssociationTagAssociation, Page, PageTagAssociation from galaxy.web.base.controller import * from galaxy.tags.tag_handler import *