diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-09-09 20:04:26 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-09-09 20:04:26 +0200 | 
| commit | da926e6708b89dcaee865632784781c54ace833b (patch) | |
| tree | 7c7a7a01a5cf2be00a3e737341d65c18d264e7a7 /ishtar_common/views.py | |
| parent | 8cdbd67f679ba10668ba667371c27c2541aaa2fd (diff) | |
| download | Ishtar-da926e6708b89dcaee865632784781c54ace833b.tar.bz2 Ishtar-da926e6708b89dcaee865632784781c54ace833b.zip | |
Add many fields to finds - associated migrations, forms and autocomplete view (refs #2784)
Diffstat (limited to 'ishtar_common/views.py')
| -rw-r--r-- | ishtar_common/views.py | 16 | 
1 files changed, 16 insertions, 0 deletions
| diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 4f7adef39..c9211c219 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -136,6 +136,22 @@ account_management_wizard = wizards.AccountWizard.as_view(      url_name='account_management',) +def get_autocomplete_generic(model, extra={'available': True}): +    def func(request): +        q = request.GET.get('term') +        query = Q(**extra) +        for q in q.split(' '): +            if not q: +                continue +            query = query & Q(label__icontains=q) +        limit = 20 +        objects = model.objects.filter(query)[:limit] +        data = json.dumps([{'id': obj.pk, 'value': unicode(obj)} +                           for obj in objects]) +        return HttpResponse(data, mimetype='text/plain') +    return func + +  def update_current_item(request):      if not request.is_ajax() and not request.method == 'POST':          raise Http404 | 
