Commits

Anonymous committed e3636b0

Added log_event view

Comments (0)

Files changed (2)

+
+from django import forms
+
+from .models import audit
+
+class AuditForm(forms.ModelForm):
+    class Meta:
+        model = Audit
+        exclude = ('user',)
+
+
+from .models import Audit
+from .forms import AuditForm
+
+from django import http
+from django.views.decorators.http import require_POST
+
+@require_POST
+def log_event(request):
+    if not request.user.is_authenticated():
+        return http.HttpResponseForbidden()
+
+    form = AuditForm(request.POST)
+    if form.is_valid():
+        obj = form.save(commit=False)
+        obj.user = request.user
+        obj.save()
+
+        return http.HttpResponse(obj.id, status=202)
+
+    return http.HttpResponseBadRequest()
+