diff options
Diffstat (limited to 'ishtar')
| -rw-r--r-- | ishtar/furnitures/forms.py | 23 | ||||
| -rw-r--r-- | ishtar/furnitures/urls.py | 2 | ||||
| -rw-r--r-- | ishtar/furnitures/views.py | 37 | ||||
| -rw-r--r-- | ishtar/furnitures/widgets.py | 92 | ||||
| -rw-r--r-- | ishtar/templates/base.html | 2 | ||||
| -rw-r--r-- | ishtar/templates/default_wizard.html | 5 |
6 files changed, 158 insertions, 3 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 82bfcb88e..2725815b4 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -1066,15 +1066,36 @@ class OperationWizard(Wizard): + datas return datas +class OperationSelect(forms.Form): + town = forms.IntegerField(label=_(u"Town"), + widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \ + 'autocomplete-town', associated_model=models.Town), + validators=[models.valid_id(models.Town)]) + operation_type = forms.ChoiceField(label=_("Operation type"), + choices=models.OperationType.get_types()) + year = forms.IntegerField(label=_("Year")) + class OperationFormSelection(forms.Form): form_label = _("Operation") associated_models = {'pk':models.Operation} currents = {'pk':models.Operation} + pk = forms.IntegerField(label=_("Operation"), required=False, + widget=widgets.JQueryJqGrid(reverse_lazy('json-operation'), + OperationSelect(), ['operation_type', 'year']), + validators=[models.valid_id(models.Operation)]) + + def clean(self): + cleaned_data = self.cleaned_data + if 'pk' not in cleaned_data or not cleaned_data['pk']: + raise forms.ValidationError(_(u"You should select an operation.")) + return cleaned_data + + """ pk = forms.IntegerField(label=_("Operation"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-operation'), associated_model=models.Operation), validators=[models.valid_id(models.Operation)]) - +""" class OperationFormGeneral(forms.Form): form_label = _("General") diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 08af1cd42..aafe0b3dd 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -71,6 +71,8 @@ urlpatterns += patterns('ishtar.furnitures.views', name='autocomplete-file'), url(BASE_URL + r'autocomplete-operation/$', 'autocomplete_operation', name='autocomplete-operation'), + url(BASE_URL + r'json-operation/$', 'json_operation', + name='json-operation'), url(BASE_URL + r'update-current-item/$', 'update_current_item', name='update-current-item'), ) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index c9ea7a0fd..811618449 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -141,6 +141,43 @@ def autocomplete_operation(request, non_closed=True): for operation in operations]) return HttpResponse(data, mimetype='text/plain') +def json_operation(request, non_closed=True): + if not request.GET: + return HttpResponse(mimetype='text/plain') + request_keys = {'town':'towns__pk', + 'operation_type':'operation_type__pk', + 'operation_code':'operation_code', + 'year':'year', + 'value':'name', + } + dct = {} + for k in request_keys: + q = request.GET.get(k) + if not q: + continue + dct[request_keys[k]] = q + if not dct: + return HttpResponse(mimetype='text/plain') + query = Q(**dct) + operations = models.Operation.objects.filter(query) + q = request.GET.get('sidx') + if q and q in request_keys: + k = request_keys[q] + 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) + data = json.dumps({ + "records":len(operations), + "rows":[{"id":unicode(operation.pk), + "cell":(unicode(operation.pk), unicode(operation), + unicode(operation.operation_type), unicode(operation.year))} + for operation in operations] + }) + return HttpResponse(data, mimetype='text/plain') + def autocomplete_organization(request, orga_type=None): if not request.GET.get('term'): return HttpResponse(mimetype='text/plain') diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index dc00f8676..b1d49f660 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -48,7 +48,6 @@ class JQueryDate(forms.TextInput): """ % (name, settings.COUNTRY)
return rendered
-
class JQueryAutoComplete(forms.TextInput):
def __init__(self, source, associated_model=None, options={}, attrs={}):
"""
@@ -121,3 +120,94 @@ objects.get(pk=value)) 'js' : self.render_js(name),
}
+class JQueryJqGrid(forms.RadioSelect):
+ COL_TPL = "{name:'%(idx)s', index:'%(idx)s', sortable:true}"
+ class Media:
+ js = ['%s/js/i18n/grid.locale-%s.js' % (settings.MEDIA_URL,
+ settings.COUNTRY),
+ '%s/js/jquery.jqGrid.min.js' % settings.MEDIA_URL,
+ ]
+ css = {'all':['%s/media/ui.jqgrid.css' % settings.MEDIA_URL]}
+
+ def __init__(self, source, form, cols, attrs={}):
+ self.source = source
+ self.form = form
+ self.attrs = attrs
+ self.cols = cols
+
+ def render(self, name, value=None, attrs=None):
+ rendered = unicode(self.form)
+ """
+ for k in self.form.fields:
+ field = self.form.fields[k]
+ print unicode(field)
+ print field.label_tag
+ rendered += u"<tr><td>%s</td><td>%s</td></tr>" % (field.label_tag,
+ unicode(field))
+ """
+ rendered += """
+</table>
+<button id='search_%s' class='submit'>%s</button>
+""" % (name, unicode(_("Search")))
+ extra_cols = []
+ col_names, col_idx = [], []
+ for k in self.form.fields:
+ field = self.form.fields[k]
+ col_idx.append(u'"%s"' % k)
+ if k in self.cols:
+ col_names.append(u'"%s"' % field.label)
+ extra_cols.append(self.COL_TPL % {'idx':k})
+ 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 += """<table id="grid_%s"></table>
+<input type="hidden" id="hidden_%s" name="%s">""" % (name, name, name)
+ rendered += """
+<script type="text/javascript">
+var query_vars = new Array(%(col_idx)s);
+jQuery(document).ready(function(){
+jQuery("#submit_form").click(function (){
+ var mygrid = jQuery("#grid_%(name)s");
+ jQuery("#hidden_%(name)s").val(mygrid.getGridParam('selrow'));
+ return true;
+});
+jQuery("#search_%(name)s").click(function (){
+ var data = "";
+ for (idx in query_vars)
+ {
+ var key = query_vars[idx];
+ var val = jQuery("#id_"+key).val();
+ if (val){
+ if (data) data += "&";
+ data += key + "=" + val;
+ }
+ }
+ var mygrid = jQuery("#grid_%(name)s");
+ var url = "%(source)s?" + data;
+ mygrid.setGridParam({url:url});
+ mygrid.trigger("reloadGrid");
+ return false;
+});
+jQuery("#grid_%(name)s").jqGrid({
+ url:'%(source)s',
+ datatype: "json",
+ mtype: 'GET',
+ colNames:['id', '%(name_label)s'%(col_names)s],
+ colModel:[
+{name:'id', index:'id', hidden:true},
+{name:'value', index:'value'}%(extra_cols)s
+ ],
+ jsonReader : {
+ },
+ sortname: 'value',
+ viewrecords: true,
+ sortorder: "asc",
+ width:500
+});
+});
+</script>
+""" % {'name':name, 'col_names':col_names, 'extra_cols':extra_cols,
+ 'name_label':unicode(_("Name")), 'source':unicode(self.source),
+ 'col_idx':col_idx}
+ return rendered
+
diff --git a/ishtar/templates/base.html b/ishtar/templates/base.html index e726cf782..22e6d4239 100644 --- a/ishtar/templates/base.html +++ b/ishtar/templates/base.html @@ -16,6 +16,8 @@ <script language="javascript" type="text/javascript" src="{{JQUERY_UI_URL}}ui/i18n/jquery.ui.datepicker-{{COUNTRY}}.js"></script> <script language="javascript" type="text/javascript" src="{{MEDIA_URL}}/js/ishtar.js"></script> <link type="text/css" href="{{JQUERY_UI_URL}}css/smoothness/jquery-ui.css" rel="stylesheet" /> + {% block extra_head %} + {% endblock %} </head> <body> <div id="header"> diff --git a/ishtar/templates/default_wizard.html b/ishtar/templates/default_wizard.html index ff1bc7975..1666b4979 100644 --- a/ishtar/templates/default_wizard.html +++ b/ishtar/templates/default_wizard.html @@ -1,6 +1,9 @@ {% extends "base.html" %} {% load i18n %} {% load range %} +{% block extra_head %} +{{form.media}} +{% endblock %} {% block content %} <form action="." method="post">{% csrf_token %} <ul id='form_path'> @@ -26,7 +29,7 @@ {% endif %} <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> {{ previous_fields|safe }} -<input type="submit" value="{% trans "Validate" %}"/> +<input type="submit" id="submit_form" value="{% trans "Validate" %}"/> </div> </form> {% endblock %} |
