Statistics
| Branch: | Tag: | Revision:

root / commissioning / servers / django_server / server_app / views.py @ 9f1a1bd0

History | View | Annotate | Download (1.1 kB)

1

    
2
from django.http import HttpResponse
3
from django.db import transaction 
4
from django.conf import settings
5
from commissioning import CommissionException, get_callpoint
6

    
7
import json
8

    
9
def _get_body(request):
10
    body = request.raw_post_data
11
    if body is None:
12
        body = request.GET.get('body', None)
13
    return body
14

    
15
callpoints = {}
16

    
17
@transaction.commit_on_success
18
def view(request, appname=None, version=None, callname=None):
19
    if (appname, version) not in callpoints:
20
        pointname = 'servers.' + appname
21
        Callpoint = get_callpoint(pointname, version=version)
22

    
23
        callpoint = Callpoint()
24
        callpoints[(appname, version)] = callpoint
25

    
26
    callpoint = callpoints[(appname, version)]
27
    body = _get_body(request)
28
    try:
29
        body = callpoint.make_call_from_json(callname, body)
30
        status = 200
31
    except CommissionException, e:
32
        if hasattr(callpoint, 'http_exception'):
33
            status, body = callpoint.http_exception(e)
34
        else:
35
            status, body = 500, 'Unknown Error'
36

    
37
    return HttpResponse(status=status, content=body)
38