1313from .models import *
1414
1515# Warning: Do not use retry_on_exception in an inner nested transaction.
16+
17+
1618def retry_on_exception (view , num_retries = 3 , on_failure = HttpResponse (status = 500 ), delay_ = 0.5 , backoff_ = 1.5 ):
1719 @wraps (view )
1820 def retry (* args , ** kwargs ):
@@ -32,10 +34,12 @@ def retry(*args, **kwargs):
3234 return on_failure
3335 return retry
3436
37+
3538class PingView (View ):
3639 def get (self , request , * args , ** kwargs ):
3740 return HttpResponse ("python/django" , status = 200 )
3841
42+
3943@method_decorator (csrf_exempt , name = 'dispatch' )
4044class CustomersView (View ):
4145 def get (self , request , id = None , * args , ** kwargs ):
@@ -61,10 +65,11 @@ def delete(self, request, id=None, *args, **kwargs):
6165 return HttpResponse (status = 404 )
6266 Customers .objects .filter (id = id ).delete ()
6367 return HttpResponse (status = 200 )
64-
68+
6569 # The PUT method is shadowed by the POST method, so there doesn't seem
6670 # to be a reason to include it.
6771
72+
6873@method_decorator (csrf_exempt , name = 'dispatch' )
6974class ProductView (View ):
7075 def get (self , request , id = None , * args , ** kwargs ):
@@ -86,6 +91,7 @@ def post(self, request, *args, **kwargs):
8691 # The REST API outlined in the github does not say that /product/ needs
8792 # a PUT and DELETE method
8893
94+
8995@method_decorator (csrf_exempt , name = 'dispatch' )
9096class OrdersView (View ):
9197 def get (self , request , id = None , * args , ** kwargs ):
@@ -94,7 +100,7 @@ def get(self, request, id=None, *args, **kwargs):
94100 else :
95101 orders = list (Orders .objects .filter (id = id ).values ())
96102 return JsonResponse (orders , safe = False )
97-
103+
98104 @retry_on_exception
99105 @atomic
100106 def post (self , request , * args , ** kwargs ):
0 commit comments