]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
Accepting incoming merge of the jambazov feature branch. Mostly includes new bug...
[osqa.git] / forum / models / user.py
index b18047e9295ccb208b18293cad1c188ef12e7bc6..9d6324875f9273c6d9ab5da77290f7bb5c4645e9 100644 (file)
@@ -22,6 +22,8 @@ QUESTIONS_PER_PAGE_CHOICES = (
 )
 
 class AnonymousUser(DjangoAnonymousUser):
 )
 
 class AnonymousUser(DjangoAnonymousUser):
+    reputation = 0
+    
     def get_visible_answers(self, question):
         return question.answers.filter_state(deleted=False)
 
     def get_visible_answers(self, question):
         return question.answers.filter_state(deleted=False)
 
@@ -33,6 +35,9 @@ class AnonymousUser(DjangoAnonymousUser):
 
     def can_vote_down(self):
         return False
 
     def can_vote_down(self):
         return False
+    
+    def can_vote_count_today(self):
+        return 0
 
     def can_flag_offensive(self, post=None):
         return False
 
     def can_flag_offensive(self, post=None):
         return False
@@ -54,6 +59,12 @@ class AnonymousUser(DjangoAnonymousUser):
 
     def can_convert_to_comment(self, answer):
         return False
 
     def can_convert_to_comment(self, answer):
         return False
+    
+    def can_convert_to_question(self, answer):
+        return False
+    
+    def can_convert_comment_to_answer(self, comment):
+        return False
 
     def can_accept_answer(self, answer):
         return False
 
     def can_accept_answer(self, answer):
         return False
@@ -159,12 +170,12 @@ class User(BaseModel, DjangoUser):
         try:
             return self.actions.order_by('-action_date')[0].action_date
         except:
         try:
             return self.actions.order_by('-action_date')[0].action_date
         except:
-            return None
+            return self.last_seen
 
     @property
     def gravatar(self):
 
     @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
     def save(self, *args, **kwargs):
         if self.reputation < 0:
             self.reputation = 0
@@ -232,7 +243,15 @@ class User(BaseModel, DjangoUser):
         today = datetime.date.today()
         return self.actions.filter(canceled=False, action_type="flag",
                                    action_date__gte=(today - datetime.timedelta(days=1))).count()
         today = datetime.date.today()
         return self.actions.filter(canceled=False, action_type="flag",
                                    action_date__gte=(today - datetime.timedelta(days=1))).count()
-
+    
+    def can_vote_count_today(self):
+        votes_today = settings.MAX_VOTES_PER_DAY
+        
+        if settings.USER_REPUTATION_TO_MAX_VOTES:
+            votes_today = votes_today + int(self.reputation)
+        
+        return votes_today
+    
     @true_if_is_super_or_staff
     def can_view_deleted_post(self, post):
         return post.author == self
     @true_if_is_super_or_staff
     def can_view_deleted_post(self, post):
         return post.author == self
@@ -276,9 +295,17 @@ class User(BaseModel, DjangoUser):
     def can_delete_comment(self, comment):
         return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS)
 
     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_CONVERT_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_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):
 
     @true_if_is_super_or_staff
     def can_accept_answer(self, answer):