diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 11:12:29 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 11:12:29 +0200 |
commit | ac2b15d6bbfaade80562a2c6267e2e843c77d968 (patch) | |
tree | 0bf45d962905dfed603db781e5b6f67ddb30f363 /ishtar_common | |
parent | b3de02632568b4e65cbe96387e57506077c66ed8 (diff) | |
download | Ishtar-ac2b15d6bbfaade80562a2c6267e2e843c77d968.tar.bz2 Ishtar-ac2b15d6bbfaade80562a2c6267e2e843c77d968.zip |
JQueryJqGrid by default sorting is made using ordering in meta
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/templates/blocks/JQueryJqGrid.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html | 2 | ||||
-rw-r--r-- | ishtar_common/views.py | 38 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 24 |
4 files changed, 48 insertions, 18 deletions
diff --git a/ishtar_common/templates/blocks/JQueryJqGrid.html b/ishtar_common/templates/blocks/JQueryJqGrid.html index faa2d9e93..607f81f7d 100644 --- a/ishtar_common/templates/blocks/JQueryJqGrid.html +++ b/ishtar_common/templates/blocks/JQueryJqGrid.html @@ -84,7 +84,7 @@ jQuery(document).ready(function(){ {{extra_cols|safe}} ], height: 300, - sortname: 'value', + sortname: '__default__', viewrecords: true, sortorder: "asc", emptyrecords: "{{no_result}}", diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html index 4a81a64fb..f751cebe3 100644 --- a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html +++ b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html @@ -27,7 +27,7 @@ setTimeout( {name:'link', index:'link', width:30}, {{extra_cols|safe}} ], - sortname: 'value', + sortname: '__default__', viewrecords: true, sortorder: "asc", emptyrecords: "{{no_result}}", diff --git a/ishtar_common/views.py b/ishtar_common/views.py index bc5e5ef1d..cd34a2019 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -25,6 +25,7 @@ import cStringIO as StringIO import datetime import ho.pisa as pisa import json +import logging from markdown import markdown import optparse import re @@ -75,6 +76,8 @@ import models CSV_OPTIONS = {'delimiter': ';', 'quotechar': '"', 'quoting': csv.QUOTE_ALL} ENCODING = settings.ENCODING or 'utf-8' +logger = logging.getLogger(__name__) + def index(request): """ @@ -334,7 +337,7 @@ def update_current_item(request, item_type=None, pk=None): request.session['SHORTCUT_SEARCH'] = 'all' currents = get_current_items(request) - # reinit when descending item are not relevant + # re-init when descending item are not relevant if item_type == 'file' and currents['file'] and currents['operation'] and \ currents['operation'].associated_file != currents['file']: request.session["operation"] = '' @@ -428,7 +431,6 @@ def autocomplete_person(request, person_types=None, attached_to=None, pass if is_ishtar_user: query = query & Q(ishtaruser__isnull=False) - limit = 20 persons = models.Person.objects.filter(query)[:limit] data = json.dumps([{'id': person.pk, 'value': unicode(person)} for person in persons if person]) @@ -696,7 +698,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[], dct[k] = not dct[k] # check also for empty value with image field field_name = k.split('__')[0] - # TODO: can be improved in later evrsion of Django + # TODO: can be improved in later version of Django try: c_field = model._meta.get_field(field_name) if k.endswith('__isnull') and \ @@ -811,7 +813,6 @@ def get_item(model, func_name, default_name, extra_request_keys=[], items = model.objects.filter(query).distinct() # print(items.query) - q = request_items.get('sidx') # table cols if own_table_cols: @@ -841,7 +842,12 @@ def get_item(model, func_name, default_name, extra_request_keys=[], manual_sort_key = None order = request_items.get('sord') sign = order and order == u'desc' and "-" or '' - if q and q in request_keys: + + q = request_items.get('sidx') + if q == '__default__' and model._meta.ordering: + orders = [sign + k for k in model._meta.ordering] + items = items.order_by(*orders) + elif q and q in request_keys: ks = request_keys[q] if type(ks) not in (list, tuple): ks = [ks] @@ -859,6 +865,8 @@ def get_item(model, func_name, default_name, extra_request_keys=[], ke = ke[0] if ke.endswith(q): manual_sort_key = ke + logger.warning("**WARN get_item - {}**: manual sort key '{" + "}'".format(func_name, q)) break if not manual_sort_key and model._meta.ordering: orders = [sign + k for k in model._meta.ordering] @@ -903,7 +911,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[], my_vals = [] for k in keys: vals = [item] - # foreign key may be splited by "." or "__" + # foreign key may be divided by "." or "__" splitted_k = [] for ky in k.split('.'): if '__' in ky: @@ -973,8 +981,9 @@ def get_item(model, func_name, default_name, extra_request_keys=[], lnk = link_template % reverse('show-' + default_name, args=[data[0], '']) except NoReverseMatch: - print '"show-' + default_name + "\" args (" + \ - unicode(data[0]) + ") url not available" + print( + '"show-' + default_name + "\" args (" + + unicode(data[0]) + ") url not available") lnk = '' res = {'id': data[0], 'link': lnk} for idx, value in enumerate(data[1:]): @@ -983,7 +992,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[], if type(table_col) not in (list, tuple): table_col = [table_col] tab_cols = [] - # foreign key may be splited by "." or "__" + # foreign key may be divided by "." or "__" for tc in table_col: if '.' in tc: tab_cols.append(tc.split('.')[-1]) @@ -1073,7 +1082,9 @@ def show_item(model, name, extra_dct=None): dct['CURRENCY'] = get_current_profile().currency dct['ENCODING'] = settings.ENCODING dct['current_window_url'] = url_name - date = 'date' in dct and dct.pop('date') + date = None + if 'date' in dct: + date = dct.pop('date') dct['window_id'] = "%s-%d-%s" % ( name, item.pk, datetime.datetime.now().strftime('%M%s')) if hasattr(item, 'history'): @@ -1306,9 +1317,7 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs): return render_to_response('ishtar/dashboards/dashboard_main.html', dct, context_instance=RequestContext(request)) -DASHBOARD_FORMS = {} -DASHBOARD_FORMS['files'] = DashboardFormFile -DASHBOARD_FORMS['operations'] = DashboardFormOpe +DASHBOARD_FORMS = {'files': DashboardFormFile, 'operations': DashboardFormOpe} def dashboard_main_detail(request, item_name): @@ -1339,6 +1348,7 @@ def dashboard_main_detail(request, item_name): else: form = DASHBOARD_FORMS[item_name]() lbl, dashboard = None, None + dashboard_kwargs = {} if (item_name == 'files' and profile.files) \ or item_name == 'operations': dashboard_kwargs = {'slice': slicing, 'fltr': fltr, @@ -1375,7 +1385,7 @@ def dashboard_main_detail(request, item_name): def reset_wizards(request): - # dynamicaly execute each reset_wizards of each ishtar app + # dynamically execute each reset_wizards of each ishtar app for app in settings.INSTALLED_APPS: if app == 'ishtar_common': # no need for infinite recursion diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 9e656311b..d3a2c975e 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -516,10 +516,29 @@ class JQueryJqGrid(forms.RadioSelect): def __init__(self, source, form, associated_model, attrs={}, table_cols='TABLE_COLS', multiple=False, multiple_cols=[2], new=False, new_message="", source_full=None, - multiple_select=False): + multiple_select=False, sortname="__default__"): + """ + JQueryJqGrid widget init. + + :param source: url to get the item from -- get_item + :param form: + :param associated_model: model of the listed items + :param attrs: + :param table_cols: + :param multiple: + :param multiple_cols: + :param new: + :param new_message: + :param source_full: url to get full listing + :param multiple_select: + :param sortname: column name (model attribute) to use to sort + """ + super(JQueryJqGrid, self).__init__(attrs=attrs) self.source = source self.form = form - self.attrs = attrs + if not attrs: + attrs = {} + self.attrs = attrs.copy() self.associated_model = associated_model self.table_cols = table_cols self.multiple = multiple @@ -527,6 +546,7 @@ class JQueryJqGrid(forms.RadioSelect): self.multiple_cols = multiple_cols self.new, self.new_message = new, new_message self.source_full = source_full + self.sortname = sortname def get_cols(self, python=False): jq_col_names, extra_cols = [], [] |