[hg] galaxy 2994: Make pages grid compatible with new grid frame...
details: http://www.bx.psu.edu/hg/galaxy/rev/1a438bb4dac2 changeset: 2994:1a438bb4dac2 user: jeremy goecks <jeremy.goecks@emory.edu> date: Mon Nov 09 16:55:52 2009 -0500 description: Make pages grid compatible with new grid framework. diffstat: lib/galaxy/web/controllers/page.py | 118 ++++----------------------------------- templates/grid_base.mako | 2 +- templates/grid_common.mako | 2 +- 3 files changed, 15 insertions(+), 107 deletions(-) diffs (171 lines): diff -r 50c64a663d24 -r 1a438bb4dac2 lib/galaxy/web/controllers/page.py --- a/lib/galaxy/web/controllers/page.py Mon Nov 09 16:40:59 2009 -0500 +++ b/lib/galaxy/web/controllers/page.py Mon Nov 09 16:55:52 2009 -0500 @@ -33,9 +33,9 @@ model_class = model.Page default_sort_key = "-create_time" columns = [ - grids.GridColumn( "Title", key="title", attach_popup=True ), + grids.TextColumn( "Title", key="title", model_class=model.Page, attach_popup=True, filterable="standard" ), PublicURLColumn( "Public URL" ), - grids.GridColumn( "Published", key="published", format=format_bool ), + grids.GridColumn( "Published", key="published", format=format_bool, filterable="advanced" ), grids.GridColumn( "Created", key="create_time", format=time_ago ), grids.GridColumn( "Last Updated", key="update_time", format=time_ago ), ] @@ -68,120 +68,28 @@ ] def apply_default_filter( self, trans, query, **kwargs ): return query.filter_by( deleted=False, published=True ) - -# Custom column types -class NameColumn( grids.GridColumn ): - def __init( self, key, link, attach_popup, filterable ): - grids.GridColumn.__init__(self, key, link, attach_popup) - def get_value( self, trans, grid, history ): + +class NameColumn( grids.TextColumn ): + def get_value(self, trans, grid, history): return history.get_display_name() - - def filter( self, db_session, query, column_filter ): - """ Modify query to filter histories by name. """ - if column_filter == "All": - pass - elif column_filter: - query = query.filter( func.lower( History.name ).like( "%" + column_filter.lower() + "%" ) ) - return query - def get_accepted_filters( self ): - """ Returns a list of accepted filters for this column. """ - accepted_filter_labels_and_vals = odict() - accepted_filter_labels_and_vals["FREETEXT"] = "FREETEXT" - accepted_filters = [] - for label, val in accepted_filter_labels_and_vals.iteritems(): - args = { self.key: val } - accepted_filters.append( grids.GridColumnFilter( label, args) ) - return accepted_filters - -class TagsColumn( grids.GridColumn ): - def __init__( self, col_name, key, filterable ): - grids.GridColumn.__init__(self, col_name, key=key, filterable=filterable) - # Tags cannot be sorted. - self.sortable = False - self.tag_elt_id_gen = 0 - def get_value( self, trans, grid, history ): - self.tag_elt_id_gen += 1 - elt_id="tagging-elt" + str( self.tag_elt_id_gen ) - div_elt = "<div id=%s></div>" % elt_id - return div_elt + trans.fill_template( "/tagging_common.mako", trans=trans, tagged_item=history, - elt_id = elt_id, in_form="true", input_size="20", tag_click_fn="add_tag_to_grid_filter" ) - def filter( self, db_session, query, column_filter ): - """ Modify query to filter histories by tag. """ - if column_filter == "All": - pass - elif column_filter: - # Parse filter to extract multiple tags. - tag_handler = TagHandler() - raw_tags = tag_handler.parse_tags( column_filter.encode("utf-8") ) - for name, value in raw_tags.items(): - if name: - # Search for tag names. - query = query.filter( History.tags.any( func.lower( model.HistoryTagAssociation.user_tname ).like( "%" + name.lower() + "%" ) ) ) - if value: - # Search for tag values. - query = query.filter( History.tags.any( func.lower( model.HistoryTagAssociation.user_value ).like( "%" + value.lower() + "%" ) ) ) - return query - def get_accepted_filters( self ): - """ Returns a list of accepted filters for this column. """ - accepted_filter_labels_and_vals = odict() - accepted_filter_labels_and_vals["FREETEXT"] = "FREETEXT" - accepted_filters = [] - for label, val in accepted_filter_labels_and_vals.iteritems(): - args = { self.key: val } - accepted_filters.append( grids.GridColumnFilter( label, args) ) - return accepted_filters - -class FreeTextSearchColumn( grids.GridColumn ): - def filter( self, db_session, query, column_filter ): - """ Modify query to search tags and history names. """ - if column_filter == "All": - pass - elif column_filter: - # Build tags filter. - tag_handler = TagHandler() - raw_tags = tag_handler.parse_tags( column_filter.encode("utf-8") ) - tags_filter = None - for name, value in raw_tags.items(): - if name: - # Search for tag names. - tags_filter = History.tags.any( func.lower( model.HistoryTagAssociation.user_tname ).like( "%" + name.lower() + "%" ) ) - if value: - # Search for tag values. - tags_filter = and_( tags_filter, func.lower( History.tags.any( model.HistoryTagAssociation.user_value ).like( "%" + value.lower() + "%" ) ) ) - - # Build history name filter. - history_name_filter = func.lower( History.name ).like( "%" + column_filter.lower() + "%" ) - - # Apply filters to query. - if tags_filter: - query = query.filter( or_( tags_filter, history_name_filter ) ) - else: - query = query.filter( history_name_filter ) - return query - def get_accepted_filters( self ): - """ Returns a list of accepted filters for this column. """ - accepted_filter_labels_and_vals = odict() - accepted_filter_labels_and_vals["FREETEXT"] = "FREETEXT" - accepted_filters = [] - for label, val in accepted_filter_labels_and_vals.iteritems(): - args = { self.key: val } - accepted_filters.append( grids.GridColumnFilter( label, args) ) - return accepted_filters class HistorySelectionGrid( grids.Grid ): # Grid definition. - template='/page/history_selection_grid.mako' title = "Saved Histories" model_class = model.History default_sort_key = "-update_time" columns = [ - NameColumn( "Name", key="name", filterable=True ), - TagsColumn( "Tags", key="tags", filterable=True), + NameColumn( "Name", key="name", model_class=model.History, filterable="advanced" ), + grids.TagsColumn( "Tags", "tags", model.History, model.HistoryTagAssociation, filterable="advanced"), grids.GridColumn( "Last Updated", key="update_time", format=time_ago ), - # Columns that are valid for filtering but are not visible. - FreeTextSearchColumn( "Search", key="free-text-search", visible=False ) # Not filterable because it's the default search. ] + columns.append( + grids.MulticolFilterColumn( + "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", visible=False, filterable="standard" ) + ) class PageController( BaseController ): diff -r 50c64a663d24 -r 1a438bb4dac2 templates/grid_base.mako --- a/templates/grid_base.mako Mon Nov 09 16:40:59 2009 -0500 +++ b/templates/grid_base.mako Mon Nov 09 16:55:52 2009 -0500 @@ -286,7 +286,7 @@ if operation.target: target = "target='" + operation.target + "'" %> - <a class="action-button" ${target} href="${url( operation=operation.label, id=item.id )}">${operation.label}</a> + <a class="action-button" ${target} href="${ url( **operation.get_url_args( item ) ) }">${operation.label}</a> %endif %endfor </div> diff -r 50c64a663d24 -r 1a438bb4dac2 templates/grid_common.mako --- a/templates/grid_common.mako Mon Nov 09 16:40:59 2009 -0500 +++ b/templates/grid_common.mako Mon Nov 09 16:55:52 2009 -0500 @@ -60,7 +60,7 @@ %if i > 0: <span>|</span> %endif - %if cur_filter_dict[column.key] == filter.args[column.key]: + %if column.key in cur_filter_dict and column.key in filter.args and cur_filter_dict[column.key] == filter.args[column.key]: <span class="filter" style="font-style: italic">${filter.label}</span> %else: <span class="filter"><a href="${url( filter.get_url_args() )}">${filter.label}</a></span>
participants (1)
-
Greg Von Kuster