Commit c35eb1fe authored by Stauros Kroustouris's avatar Stauros Kroustouris

add commit_add, commit_edit, commit_delete hooks in drf viewsets.

parent 5b0e6618
......@@ -80,9 +80,12 @@ Same with Fragmentypes in `/api/fragmenttypes/<fragmenttype_id>/`, protocols in
Since we have the urls we want to connect with the rule we want to create, we can make a POST request like the following:
curl -X POST -H 'Authorization: Token <Your users token>' -F "name=Example" -F "comments=Description" -F "source=" -F "sourceport=" -F "destination="
And here is a PUT request example:
curl -X PUT -F "name=Example" -F "comments=Description" -F "source=" -F "sourceport=" -F "destination=" -H 'Authorization: Token <Your users token>'
from django.shortcuts import get_object_or_404
from rest_framework import status
from django.conf import settings
from rest_framework import viewsets
from flowspec.models import (
......@@ -41,7 +41,27 @@ class RouteViewSet(viewsets.ModelViewSet):
return Response(
def pre_save(self, obj):
obj.applier = self.request.user
if settings.DEBUG:
if self.request.user.is_anonymous():
from django.contrib.auth.models import User
obj.applier = User.objects.all()[0]
elif self.request.user.is_authenticated():
obj.applier = self.request.user
raise Exception('User is not Authenticated')
obj.applier = self.request.user
def post_save(self, obj, created):
if created:
if obj.status not in ['EXPIRED', 'INACTIVE', 'ADMININACTIVE']:
def pre_delete(self, obj):
class PortViewSet(viewsets.ModelViewSet):
......@@ -62,4 +82,3 @@ class FragmentTypeViewSet(viewsets.ModelViewSet):
class MatchProtocolViewSet(viewsets.ModelViewSet):
queryset = MatchProtocol.objects.all()
serializer_class = MatchProtocolSerializer
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment