Exemplo n.º 1
0
def report(request, form=None):
    # Choose the mode we're going to return report data back as
    mode = "full" if request.user.is_staff else "limited"

    # If we got a form
    if form:
        # save the report (form is guaranteed to be valid)
        new_report = form.save()
        # serialize the new report using the appropriate mode (turn into python dict)
        new_report_data = serial.serialize(new_report, mode=mode)
        # echo back the report
        return api.ok(report=new_report_data)
    else:
        # return the latest report
        try:
            # get the instance
            lastest_report = models.TestModel.objects.order_by("-pk").get()
            # serialize it using the appropriate mode (turn into python dict)
            lastest_report_data = serial.serialize(lastest_report, mode=mode)
            # return response as json
            return api.ok(latest_report=lastest_report_data)
        except models.TestModel.DoesNotExist:
            # latest report not found
            return api.error404()
Exemplo n.º 2
0
 def view(request, form=None):
     return api.ok(form=form.cleaned_data if form  else None, method=request.method)
Exemplo n.º 3
0
 def view(request, put=None):
     self.assertIsNotNone(put)
     return api.ok(put=put)
Exemplo n.º 4
0
 def view(request, form=None):
     return api.ok(data=form.cleaned_data if form else None)
Exemplo n.º 5
0
 def view(request, post=None):
     return api.ok(post=post)
Exemplo n.º 6
0
 def view(request):
     return api.ok(user=123)
Exemplo n.º 7
0
 def view(request, form=None):
     return api.ok(form=form.cleaned_data if form else None,
                   method=request.method)
Exemplo n.º 8
0
 def view(request, put=None):
     self.assertIsNotNone(put)
     return api.ok(put=put)
Exemplo n.º 9
0
 def view(request, form=None):
     return api.ok(data=form.cleaned_data if form else None)
Exemplo n.º 10
0
 def view(request, post=None):
     return api.ok(post=post)
Exemplo n.º 11
0
 def view(request):
     return api.ok(user=123)
Exemplo n.º 12
0
def home(request):
    """
    Return a standard welcome message
    """
    return api.ok(message="Welcome")