Commits

Luke Plant  committed b43d4c5

Pulled out authentication checking in Autocomplete into separate method.

This allows it to be overridden by a subclass easily.

  • Participants
  • Parent commits 5d3df39

Comments (0)

Files changed (1)

File autocomplete/views.py

     def __init__(self):
         self.settings = dict()
 
+    def allowed(self, request, ac_name, auth):
+        if auth and not request.user.is_authenticated():
+            return False
+        else:
+            return True
+
     def __call__(self, request, ac_name, query_param='q'):
         if not ac_name in self.settings:
             return self.not_found(request, ac_name)
 
         qs, fields, limit, key, label, auth = self.settings[ac_name]
-        if auth and not request.user.is_authenticated():
+        if not self.allowed(request, ac_name, auth):
             return self.forbidden(request, ac_name)
         query = request.GET.get(query_param, '')