Commits

Anonymous committed 3456259

[project @ 385]
Changed the UserSpecific* managers so that they return all objects
if the context is not an HTTP request. This makes scripts that need to
delete all objects, for instance, work much better.

  • Participants
  • Parent commits d3991c7

Comments (0)

Files changed (3)

File cciw/cciwmain/models/forums.py

     def get_query_set(self):
         queryset = super(UserSpecificTopics, self).get_query_set()
         user = threadlocals.get_current_user()
-        if user is None or user.is_anonymous() or \
-            not user.has_perm('cciwmain.edit_topic'):
+        if threadlocals.is_web_request() and \
+           (user is None or user.is_anonymous() or \
+            not user.has_perm('cciwmain.edit_topic')):
             # Non-moderator user
             member = threadlocals.get_current_member()
             if member is not None:
     def get_query_set(self):
         queryset = super(UserSpecificPhotos, self).get_query_set()
         user = threadlocals.get_current_user()
-        if user is None or user.is_anonymous() or \
-            not user.has_perm('cciwmain.edit_topic'):
+        if threadlocals.is_web_request() and \
+            (user is None or user.is_anonymous() or \
+             not user.has_perm('cciwmain.edit_topic')):
             # Non-moderator user
             return queryset.filter(hidden=False)
         else:
         appropriate for the current member/user."""
         queryset = super(UserSpecificPosts, self).get_query_set()
         user = threadlocals.get_current_user()
-        if user is None or user.is_anonymous() or \
-            not user.has_perm('cciwmain.edit_post'):
+        if threadlocals.is_web_request() and \
+           (user is None or user.is_anonymous() or \
+            not user.has_perm('cciwmain.edit_post')):
             # Non-moderator user
             
             member = threadlocals.get_current_member()

File cciw/cciwmain/models/members.py

 class UserSpecificMembers(models.Manager):
     def get_query_set(self):
         user = threadlocals.get_current_user()
-        if user is None or user.is_anonymous() or not user.is_staff or not\
-            user.has_perm('cciwmain.change_member'):
+        if threadlocals.is_web_request() and \
+           (user is None or user.is_anonymous() or not user.is_staff or \
+            not user.has_perm('cciwmain.change_member')):
             return super(UserSpecificMembers, self).get_query_set().filter(hidden=False)
         else:
             return super(UserSpecificMembers, self).get_query_set()

File cciw/middleware/threadlocals.py

 
 _thread_locals = threading.local()
 
+
+import os
+def is_web_request():
+    return os.environ.get('SERVER_PROTOCOL') is not None
+
 def get_current_user():
     return getattr(_thread_locals, 'user', None)