Browse Source

ajax_only decorator for API's

Rafał Pitoń 11 years ago
parent
commit
b0bd96f5c2
1 changed files with 11 additions and 0 deletions
  1. 11 0
      misago/core/decorators.py

+ 11 - 0
misago/core/decorators.py

@@ -1,6 +1,17 @@
 from django.shortcuts import render
 
 
+def ajax_only(f):
+    def decorator(request, *args, **kwargs):
+        if not request.is_ajax():
+            response = render(request, 'misago/errorpages/wrong_way.html')
+            response.status_code = 405
+            return response
+        else:
+            return f(request, *args, **kwargs)
+    return decorator
+
+
 def require_POST(f):
     def decorator(request, *args, **kwargs):
         if not request.method == 'POST':