コード例 #1
0
ファイル: views.py プロジェクト: renton/totems-server-django
def simulate_app(request):

    c = {
        'zoom_override':18,
        'sim_mode':True,
    }

    #TODO proper form
    if request.method == "POST":
        if 'message' in request.POST and 'longitude' in request.POST and 'latitude' in request.POST:
            if request.POST['message'] != "":
                admin, created = Client.get_or_register_client("admin")
                wl1 = WorldLayer.objects.get(id=1)
                Totem.add_totem(admin,request.POST['longitude'],request.POST['latitude'],request.POST['message'],wl1)

    return render_to_response("custom_admin/simulator/map.html",c,context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: renton/totems-server-django
def totems_detail(request,TotemID):

    #TODO proper form
    if request.method == "POST":
        if 'message' in request.POST and 'parent_message_id' in request.POST:
            if request.POST['message'] != "":
                admin, created = Client.get_or_register_client("admin")
                parent = TotemMessage.objects.get(pk=request.POST['parent_message_id'])
                parent.reply_message(request.POST['message'],admin)

    totem = Totem.objects.get(pk=TotemID)
    parent = totem.get_parent_message()
    messages = parent.list_from_node()

    c = {
        'totem':totem,
        'messages':messages
    }

    return render_to_response("custom_admin/totems/detail.html",c,context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: renton/totems-server-django
def register(request):    

    if request.method == "POST":

        output = {}

        required_params = [
            'device_id',
            'device_name',
            'device_version',
            'device_platform',
            'registration_longitude',
            'registration_latitude',
            'timestamp',
            'secret',
        ]

        # all parameters must be sent
        for param in required_params:
            if param not in request.POST.keys():
                output['success'] = False
                output['alert'] = "missing parameters"
                return HttpResponse(simplejson.dumps(output), 'application/json')

        # device id must be non-empty
        if request.POST['device_id'] == "":
                output['success'] = False
                output['alert'] = "empty device id"
                return HttpResponse(simplejson.dumps(output), 'application/json')

        # decrypt sensitive fields
        # request.POST['device_id'] = decrypt(request.POST['device_id'])
        # request.POST['registration_longitude'] = decrypt(request.POST['registration_longitude'])
        # request.POST['registration_latitude'] = decrypt(request.POST['registration_latitude'])

        # authorize secret
        if _auth_secret([
                            request.POST['device_id'],
                            request.POST['registration_longitude'],
                            request.POST['registration_latitude'],
                            request.POST['timestamp']], request.POST['secret']) == False:

                output['success'] = False
                output['alert'] = "malformed request"
                return HttpResponse(simplejson.dumps(output), 'application/json')


        try:
            reg_latitude = float(request.POST['registration_latitude'])
            reg_longitude = float(request.POST['registration_longitude'])
        except:
            output['success'] = False
            output['alert'] = "malformed long/lat"
            output['data'] = request.POST['registration_longitude']
            return HttpResponse(simplejson.dumps(output), 'application/json')

        registered_client,created = Client.get_or_register_client(
            request.POST['device_id'],
            request.POST['device_name'],
            request.POST['device_platform'],
            request.POST['device_version'],
            reg_longitude,
            reg_latitude,
        )

        # REPLY NOTIFICATIONS
        output['reply_notifications'] = []
        output['show_notification_alert'] = False
        notifications = TotemMessage.get_all_reply_notifications_for_client(registered_client)
        for notification in notifications:
            if notification.reply_notification_read == False:
                notification.view_reply_notification()
                output['show_notification_alert'] = True
            output['reply_notifications'].append({'id':notification.id,'longitude':notification.totem.longitude,'latitude':notification.totem.latitude})

        output['is_banned'] = registered_client.is_banned
        output['is_active'] = registered_client.active
        output['created'] = created
        output['success'] = True

        print output
        return HttpResponse(simplejson.dumps(output), 'application/json')
    else:
        raise Http404