Changeset 9224


Ignore:
Timestamp:
May 31, 2011, 6:47:49 AM (13 years ago)
Author:
rick
Message:

Answer question of Dennis at http://lijst.wirelessleiden.nl/pipermail/techniek/2011-May/005516.html

Location:
src/django_gheat/website
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/website/filters.py

    r9217 r9224  
    5353  datasetlist = serializers.serialize('json', datasets, fields=('naam', 'gebruiker'))
    5454  return datasetlist
     55
     56
     57def foo_filter(request):
     58  """Example json input for dynamic filter using multiple objects example:
     59  http://lijst.wirelessleiden.nl/pipermail/techniek/2011-May/005516.html"""
     60  result = list()
     61  for user in Gebruiker.objects.all().order_by('naam'):
     62    entry = {'gebruiker' : user.naam}
     63    meetrondje_list = list()
     64    for mr in MeetRondje.objects.filter(gebruiker=user).order_by('naam'):
     65      # Get list if accespoints found in the specific 'Meting', and make this is list.
     66      wirelessleiden_ssid = Meting.objects.filter(meetrondje=mr,
     67        accespoint__ssid__contains='WirelessLeiden').\
     68        values_list('accespoint__ssid',flat=True).\
     69        order_by('accespoint__ssid').distinct()
     70      # The explicit cast to list is required as django lists are special and
     71      # cannot be handled by simplejson.
     72      meetrondje_list.append(
     73        {
     74          'naam' : mr.naam,
     75          'nodes' : list(wirelessleiden_ssid)
     76        }
     77      )
     78    entry['meetrondje'] = meetrondje_list
     79    result.append(entry)
     80
     81  # Pretty formatting, makes debugging the json responses more easy
     82  json_response = simplejson.dumps(result,indent=2*' ')
     83  return HttpResponse(json_response, content_type='application/javascript; charset=utf8')
  • src/django_gheat/website/urls.py

    r9217 r9224  
    4343        name = 'serve_filter',
    4444       ),
    45     )
     45    url(r'^foofilter/$', 'foo_filter'),
     46  )
Note: See TracChangeset for help on using the changeset viewer.