]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
Adding ability to convert comments to answers.
[osqa.git] / forum / models / user.py
index 7772bc9fc630e695f7209406f9f2b1b1e0b4c672..e3c97fa90d6bf4f61cd30d41bdc432a95d2652fc 100644 (file)
@@ -85,6 +85,9 @@ class AnonymousUser(DjangoAnonymousUser):
     def can_upload_files(self):
         return False
 
+    def is_a_super_user_or_staff(self):
+        return False
+
 def true_if_is_super_or_staff(fn):
     def decorated(self, *args, **kwargs):
         return self.is_superuser or self.is_staff or fn(self, *args, **kwargs)
@@ -153,12 +156,15 @@ class User(BaseModel, DjangoUser):
 
     @property
     def last_activity(self):
-        return self.actions.order_by('-action_date')[0].action_date
+        try:
+            return self.actions.order_by('-action_date')[0].action_date
+        except:
+            return self.last_seen
 
     @property
     def gravatar(self):
-        return md5(self.email).hexdigest()
-
+        return md5(self.email.lower()).hexdigest()
+    
     def save(self, *args, **kwargs):
         if self.reputation < 0:
             self.reputation = 0
@@ -270,9 +276,17 @@ class User(BaseModel, DjangoUser):
     def can_delete_comment(self, comment):
         return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS)
 
+    @true_if_is_super_or_staff
+    def can_convert_comment_to_answer(self, comment):
+        return self == comment.author or self.reputation >= int(settings.REP_TO_COMMENTS_TO_ANSWERS)
+
     def can_convert_to_comment(self, answer):
         return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int
                 (settings.REP_TO_CONVERT_TO_COMMENT))
+    
+    def can_convert_to_question(self, answer):
+        return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int
+                (settings.REP_TO_CONVERT_TO_QUESTION))
 
     @true_if_is_super_or_staff
     def can_accept_answer(self, answer):
@@ -307,7 +321,7 @@ class User(BaseModel, DjangoUser):
 
     @true_if_is_super_or_staff
     def can_reopen_question(self, question):
-        return self == question.author and self.reputation >= settings.REP_TO_REOPEN_OWN
+        return self == question.author and self.reputation >= int(settings.REP_TO_REOPEN_OWN)
 
     @true_if_is_super_or_staff
     def can_delete_post(self, post):