Ejemplo n.º 1
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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
def list_presence(request):
    if request.method != "GET":
        return HttpResponse(status=405)  # method not allowed
    return [p.nick for p in presence.list_people()]
Ejemplo n.º 4
0
def list_presence(request):
  if request.method != "GET":
    return HttpResponse(status = 405) # method not allowed
  return [p.nick for p in presence.list_people()]