Skip to content

Commit

Permalink
Remove dict format from legacy grid helper
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Dec 10, 2017
1 parent d2752dc commit 96b9b15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 144 deletions.
167 changes: 24 additions & 143 deletions lib/galaxy/webapps/reports/framework/grids.py
Expand Up @@ -65,7 +65,6 @@ def __call__(self, trans, **kwargs):
# FIXME: pretty sure this is only here to pass along, can likely be eliminated
status = kwargs.get('status', None)
message = kwargs.get('message', None)
dict_format = kwargs.get('dict_format', False)
# Build a base filter and sort key that is the combination of the saved state and defaults.
# Saved state takes preference over defaults.
base_filter = {}
Expand Down Expand Up @@ -286,149 +285,31 @@ def url(*args, **kwargs):
# utf-8 unicode; however, this would require encoding the object as utf-8 before returning the grid
# results via a controller method, which is require substantial changes. Hence, for now, return grid
# as str.
if not dict_format:
page = trans.fill_template(iff(async_request, self.async_template, self.template),
grid=self,
query=query,
cur_page_num=page_num,
num_pages=num_pages,
num_page_links=self.num_page_links,
default_filter_dict=self.default_filter,
cur_filter_dict=cur_filter_dict,
sort_key=sort_key,
current_item=current_item,
ids=kwargs.get('id', []),
url=url,
status=status,
message=message,
info_text=self.info_text,
use_panels=self.use_panels,
use_hide_message=self.use_hide_message,
advanced_search=self.advanced_search,
show_item_checkboxes=(self.show_item_checkboxes or
kwargs.get('show_item_checkboxes', '') in ['True', 'true']),
# Pass back kwargs so that grid template can set and use args without
# grid explicitly having to pass them.
kwargs=kwargs)
trans.log_action(trans.get_user(), text_type("grid.view"), context, params)
return page

grid_config = {
'title' : self.title,
'url_base' : trans.request.path_url,
'async' : self.use_async,
'async_ops' : [],
'categorical_filters' : {},
'filters' : cur_filter_dict,
'sort_key' : sort_key,
'show_item_checkboxes' : self.show_item_checkboxes or kwargs.get('show_item_checkboxes', '') in ['True', 'true'],
'cur_page_num' : page_num,
'num_pages' : num_pages,
'num_page_links' : self.num_page_links,
'status' : status,
'message' : restore_text(message),
'global_actions' : [],
'operations' : [],
'items' : [],
'columns' : [],
'model_class' : str(self.model_class),
'use_paging' : self.use_paging,
'legend' : self.legend,
'current_item_id' : False,
'use_hide_message' : self.use_hide_message,
'default_filter_dict' : self.default_filter,
'advanced_search' : self.advanced_search,
'info_text' : self.info_text,
'url' : url(dict()),
'refresh_frames' : kwargs.get('refresh_frames', [])
}
if current_item:
grid_config['current_item_id'] = current_item.id
for column in self.columns:
href = None
extra = ''
if column.sortable:
if sort_key.endswith(column.key):
if not sort_key.startswith("-"):
href = url(sort=("-" + column.key))
extra = "↓"
else:
href = url(sort=(column.key))
extra = "↑"
else:
href = url(sort=column.key)
grid_config['columns'].append({
'key' : column.key,
'visible' : column.visible,
'nowrap' : column.nowrap,
'attach_popup' : column.attach_popup,
'label_id_prefix' : column.label_id_prefix,
'sortable' : column.sortable,
'label' : column.label,
'filterable' : column.filterable,
'is_text' : isinstance(column, TextColumn),
'href' : href,
'extra' : extra
})
for operation in self.operations:
grid_config['operations'].append({
'allow_multiple' : operation.allow_multiple,
'allow_popup' : operation.allow_popup,
'target' : operation.target,
'label' : operation.label,
'confirm' : operation.confirm,
'href' : url(**operation.url_args) if isinstance(operation.url_args, dict) else None,
'global_operation' : False
})
if operation.allow_multiple:
grid_config['show_item_checkboxes'] = True
if operation.global_operation:
grid_config['global_operation'] = url(** (operation.global_operation()))
for action in self.global_actions:
grid_config['global_actions'].append({
'url_args' : url(**action.url_args),
'label' : action.label,
'target' : action.target
})
for operation in [op for op in self.operations if op.async_compatible]:
grid_config['async_ops'].append(operation.label.lower())
for column in self.columns:
if column.filterable is not None and not isinstance(column, TextColumn):
grid_config['categorical_filters'][column.key] = dict([(filter.label, filter.args) for filter in column.get_accepted_filters()])
for i, item in enumerate(query):
item_dict = {
'id' : item.id,
'encode_id' : trans.security.encode_id(item.id),
'link' : [],
'operation_config' : {},
'column_config' : {}
}
for column in self.columns:
if column.visible:
link = column.get_link(trans, self, item)
if link:
link = url(**link)
else:
link = None
target = column.target
value = column.get_value(trans, self, item)
if isinstance(value, str):
value = text_type(value, 'utf-8')
value = value.replace('/', '//')
item_dict['column_config'][column.label] = {
'link' : link,
'value' : value,
'target' : target
}
for operation in self.operations:
item_dict['operation_config'][operation.label] = {
'allowed' : operation.allowed(item),
'url_args' : url(**operation.get_url_args(item)),
'target' : operation.target
}
grid_config['items'].append(item_dict)
page = trans.fill_template(iff(async_request, self.async_template, self.template),
grid=self,
query=query,
cur_page_num=page_num,
num_pages=num_pages,
num_page_links=self.num_page_links,
default_filter_dict=self.default_filter,
cur_filter_dict=cur_filter_dict,
sort_key=sort_key,
current_item=current_item,
ids=kwargs.get('id', []),
url=url,
status=status,
message=message,
info_text=self.info_text,
use_panels=self.use_panels,
use_hide_message=self.use_hide_message,
advanced_search=self.advanced_search,
show_item_checkboxes=(self.show_item_checkboxes or
kwargs.get('show_item_checkboxes', '') in ['True', 'true']),
# Pass back kwargs so that grid template can set and use args without
# grid explicitly having to pass them.
kwargs=kwargs)
trans.log_action(trans.get_user(), text_type("grid.view"), context, params)
return grid_config
return page

def get_ids(self, **kwargs):
id = []
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/grids/repository_grids.py
Expand Up @@ -7,7 +7,7 @@
import tool_shed.grids.util as grids_util
import tool_shed.repository_types.util as rt_util
import tool_shed.util.shed_util_common as suc
from galaxy.web.framework.helpers import grids
from galaxy.webapps.reports.framework import grids
from galaxy.webapps.tool_shed import model
from tool_shed.util import hg_util, metadata_util, repository_util

Expand Down

0 comments on commit 96b9b15

Please sign in to comment.