Пример #1
0
def list_sensors(request):
  if 'simple' in request.GET:
    return [s.sensor_id for s in presence.list_simple_sensors()]
  elif 'complex' in request.GET:
    complex_list = set([s['name'] for s in presence.list_complex_sensors()])
    return sorted(complex_list)
  else:
    complex_list = set([s['name'] for s in presence.list_complex_sensors()])
    return [s.sensor_id for s in presence.list_simple_sensors()] + \
           sorted(complex_list)
Пример #2
0
def list_sensors(request):
    if 'simple' in request.GET:
        return [s.sensor_id for s in presence.list_simple_sensors()]
    elif 'complex' in request.GET:
        complex_list = set(
            [s['name'] for s in presence.list_complex_sensors()])
        return sorted(complex_list)
    else:
        complex_list = set(
            [s['name'] for s in presence.list_complex_sensors()])
        return [s.sensor_id for s in presence.list_simple_sensors()] + \
               sorted(complex_list)
Пример #3
0
def list(request, nick = None):
  template = loader.get_template("list.html")

  from django.core.urlresolvers import reverse
  from forms import PresenceForm
  form = PresenceForm()
  if nick is not None:
    form.initial['nick'] = nick
    form_target = reverse(list, kwargs = {'nick': nick})
  else:
    form_target = reverse(list)

  if request.POST.get('nick', '') != '':
    context = {
      'address': request.META['REMOTE_ADDR'],
      'uri': request.get_full_path(),
    }
    if 'enter' in request.POST:
      presence.person_entered(request.POST['nick'], context)
    else: # 'leave' in request.POST
      presence.person_left(request.POST['nick'], context)
    # tell the browser to reload the page, but with GET request
    return django.shortcuts.redirect(request.path)

  context = RequestContext(request, {
    'form_target': form_target,
    'form': form,
    'present': presence.list_people(),
    'sensors': presence.list_simple_sensors(),
    'complex_sensors': presence.list_complex_sensors(),
  })
  return HttpResponse(template.render(context))
Пример #4
0
def list(request, nick=None):
    template = loader.get_template("list.html")

    from django.core.urlresolvers import reverse
    from forms import PresenceForm
    form = PresenceForm()
    if nick is not None:
        form.initial['nick'] = nick
        form_target = reverse(list, kwargs={'nick': nick})
    else:
        form_target = reverse(list)

    if request.POST.get('nick', '') != '':
        context = {
            'address': request.META['REMOTE_ADDR'],
            'uri': request.META['REQUEST_URI'],
        }
        if 'enter' in request.POST:
            presence.person_entered(request.POST['nick'], context)
        else:  # 'leave' in request.POST
            presence.person_left(request.POST['nick'], context)
        # tell the browser to reload the page, but with GET request
        return django.shortcuts.redirect(request.path)

    context = RequestContext(
        request, {
            'form_target': form_target,
            'form': form,
            'present': presence.list_people(),
            'sensors': presence.list_simple_sensors(),
            'complex_sensors': presence.list_complex_sensors(),
        })
    return HttpResponse(template.render(context))