Example #1
0
#!/usr/bin/python

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import django.shortcuts
import json

from wlokalu.api import presence

#-----------------------------------------------------------------------------

from wlokalu.logging import getLogger, message as log

logger = getLogger(__name__)

#-----------------------------------------------------------------------------


def return_json(function):
    def replacement(*args, **kwargs):
        reply = function(*args, **kwargs)
        if type(reply) in (dict, list, str, unicode):
            return HttpResponse(json.dumps(reply) + "\n",
                                content_type="text/json")
        return reply

    return replacement


#-----------------------------------------------------------------------------
Example #2
0
#!/usr/bin/python

from wlokalu.logging import getLogger, message

logger = getLogger('wlokalu.presence')

from models import Person, SimpleSensor, ComplexSensor
import datetime

#-----------------------------------------------------------------------------


def log(*args, **kwargs):
    context = kwargs.get('context')
    if context is not None:
        del kwargs['context']
        kwargs.update(context)
    return message(*args, **kwargs)


#-----------------------------------------------------------------------------


def person_entered(nick, context=None):
    if Person.objects.filter(nick=nick).count() == 0:
        Person(nick).save()  # add if not exists
        logger.info(log('person entered premises', nick=nick, context=context))


def person_left(nick, context=None):
    people = Person.objects.filter(nick=nick)
Example #3
0
#!/usr/bin/python

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import django.shortcuts
import json

from wlokalu.api import presence

#-----------------------------------------------------------------------------

from wlokalu.logging import getLogger, message as log
logger = getLogger(__name__)

#-----------------------------------------------------------------------------

def return_json(function):
  def replacement(*args, **kwargs):
    reply = function(*args, **kwargs)
    if type(reply) in (dict, list, str, unicode):
      return HttpResponse(json.dumps(reply) + "\n", content_type = "text/json")
    return reply

  return replacement

#-----------------------------------------------------------------------------

@csrf_exempt
@return_json
def list_elements(request, subpages):
  return subpages
Example #4
0
#!/usr/bin/python

from wlokalu.logging import getLogger, message
logger = getLogger('wlokalu.presence')

from models import Person, SimpleSensor, ComplexSensor
import datetime

#-----------------------------------------------------------------------------

def log(*args, **kwargs):
  context = kwargs.get('context')
  if context is not None:
    del kwargs['context']
    kwargs.update(context)
  return message(*args, **kwargs)

#-----------------------------------------------------------------------------

def person_entered(nick, context = None):
  if Person.objects.filter(nick = nick).count() == 0:
    Person(nick).save() # add if not exists
    logger.info(log('person entered premises', nick = nick, context = context))

def person_left(nick, context = None):
  people = Person.objects.filter(nick = nick)
  if people.count() > 0:
    people.delete()
    logger.info(log('person left premises', nick = nick, context = context))

def person(nick):