From e34df16f34008aa7019a5240689a5e0e7f64e18d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Jan 2011 17:05:14 +0100 Subject: Manage ordering - default item - save last search in session (refs #142) --- ishtar/furnitures/forms.py | 2 +- ishtar/furnitures/views.py | 19 +++++++++++++++---- ishtar/furnitures/widgets.py | 19 +++++++++++++------ static/media/style.css | 4 ++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 2725815b4..a7f31999e 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -1079,7 +1079,7 @@ class OperationFormSelection(forms.Form): form_label = _("Operation") associated_models = {'pk':models.Operation} currents = {'pk':models.Operation} - pk = forms.IntegerField(label=_("Operation"), required=False, + pk = forms.IntegerField(label="", required=False, widget=widgets.JQueryJqGrid(reverse_lazy('json-operation'), OperationSelect(), ['operation_type', 'year']), validators=[models.valid_id(models.Operation)]) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 811618449..b266bed63 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -157,7 +157,14 @@ def json_operation(request, non_closed=True): continue dct[request_keys[k]] = q if not dct: - return HttpResponse(mimetype='text/plain') + if 'json_operation' in request.session: + dct = request.session['json_operation'] + elif 'operation' in request.session: + dct = {"pk":request.session['operation']} + if not dct: + return HttpResponse(mimetype='text/plain') + else: + request.session['json_operation'] = dct query = Q(**dct) operations = models.Operation.objects.filter(query) q = request.GET.get('sidx') @@ -166,9 +173,13 @@ def json_operation(request, non_closed=True): if k.endswith("__pk"): k = k[:-len("__pk")] + "__label" q = request.GET.get('sord') - if q and q == u'desc': - k = "-" + k - operations.order_by(k) + sign = q and q == u'desc' and "-" or '' + if k == "name": + k = "operation_code" + operations = operations.order_by(sign + 'year').order_by( + sign + 'operation_code') + else: + operations = operations.order_by(sign + k) data = json.dumps({ "records":len(operations), "rows":[{"id":unicode(operation.pk), diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index b1d49f660..af22c7b3e 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -148,7 +148,8 @@ class JQueryJqGrid(forms.RadioSelect): rendered += """ -""" % (name, unicode(_("Search"))) +

%s

+""" % (name, unicode(_("Search")), unicode(_("Search and select an item"))) extra_cols = [] col_names, col_idx = [], [] for k in self.form.fields: @@ -160,8 +161,9 @@ class JQueryJqGrid(forms.RadioSelect): col_names = col_names and ",".join([""]+col_names) or "" col_idx = col_idx and ",".join(col_idx) or "" extra_cols = extra_cols and ",".join([""]+extra_cols) or "" - rendered += """
-""" % (name, name, name) + rendered += """
+
+""" % (name, name, name, name) rendered += """ """ % {'name':name, 'col_names':col_names, 'extra_cols':extra_cols, 'name_label':unicode(_("Name")), 'source':unicode(self.source), - 'col_idx':col_idx} + 'col_idx':col_idx, 'no_result':unicode(_("No results")), + 'loading':unicode(_("Loading..."))} return rendered diff --git a/static/media/style.css b/static/media/style.css index b9cfc18f6..25616ac69 100644 --- a/static/media/style.css +++ b/static/media/style.css @@ -224,3 +224,7 @@ div.form .errorlist{ table.confirm tr.spacer td:last-child{ border-bottom:1px solid #922; } + +.jqgrid{ + cursor:pointer; +} -- cgit v1.2.3