]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
python 2.4 compatibility fixes and fix on score counter
[osqa.git] / forum / models / user.py
index 655e17e864a51377f62fda4c6a64369b24e45760..82cfe3aec3523d6bb177514d2a7a60e8f9e8cf10 100644 (file)
@@ -3,7 +3,10 @@ from forum import const
 from django.contrib.contenttypes.models import ContentType\r
 from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser\r
 from django.db.models import Q\r
-from hashlib import md5\r
+try:\r
+    from hashlib import md5\r
+except:\r
+    import md5\r
 import string\r
 from random import Random\r
 \r
@@ -97,7 +100,7 @@ class User(BaseModel, DjangoUser):
 \r
     @property\r
     def gravatar(self):\r
-        return hashlib.md5(self.email).hexdigest()\r
+        return md5(self.email).hexdigest()\r
 \r
     def save(self, *args, **kwargs):\r
         if self.reputation < 0:\r
@@ -216,7 +219,7 @@ class User(BaseModel, DjangoUser):
     class Meta:\r
         app_label = 'forum'\r
 \r
-class Activity(MetaContent):\r
+class Activity(GenericContent):\r
     """\r
     We keep some history data for user activities\r
     """\r
@@ -238,20 +241,15 @@ class Activity(MetaContent):
             activity_record.send(sender=self.activity_type, instance=self)\r
 \r
     @property\r
-    def question(self):\r
-        if self.activity_type == const.TYPE_ACTIVITY_ASK_QUESTION:\r
-            return self.content_object\r
-        elif self.activity_type in (const.TYPE_ACTIVITY_ANSWER,\r
-                const.TYPE_ACTIVITY_MARK_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION):\r
-            return self.content_object.question\r
-        elif self.activity_type == const.TYPE_ACTIVITY_COMMENT_QUESTION:\r
-            return self.content_object.content_object\r
-        elif self.activity_type == const.TYPE_ACTIVITY_COMMENT_ANSWER:\r
-            return self.content_object.content_object.question\r
-        elif self.activity_type == const.TYPE_ACTIVITY_UPDATE_ANSWER:\r
-            return self.content_object.content_object.answer.question\r
-        else:\r
-            raise NotImplementedError()\r
+    def node(self):\r
+        if self.activity_type in (const.TYPE_ACTIVITY_ANSWER, const.TYPE_ACTIVITY_ASK_QUESTION,\r
+                const.TYPE_ACTIVITY_MARK_ANSWER, const.TYPE_ACTIVITY_COMMENT_QUESTION, const.TYPE_ACTIVITY_COMMENT_ANSWER):\r
+            return self.content_object.leaf\r
+\r
+        if self.activity_type in (const.TYPE_ACTIVITY_UPDATE_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION):\r
+            return self.content_object.node.leaf            \r
+            \r
+        raise NotImplementedError()\r
 \r
     @property\r
     def type_as_string(self):\r
@@ -262,13 +260,15 @@ class Activity(MetaContent):
         elif self.activity_type  == const.TYPE_ACTIVITY_MARK_ANSWER:\r
             return _("marked an answer")\r
         elif self.activity_type  == const.TYPE_ACTIVITY_UPDATE_QUESTION:\r
-            return _("edited")\r
+            return _("edited a question")\r
         elif self.activity_type == const.TYPE_ACTIVITY_COMMENT_QUESTION:\r
-            return _("commented")\r
+            return _("commented a question")\r
         elif self.activity_type == const.TYPE_ACTIVITY_COMMENT_ANSWER:\r
             return _("commented an answer")\r
         elif self.activity_type == const.TYPE_ACTIVITY_UPDATE_ANSWER:\r
             return _("edited an answer")\r
+        elif self.activity_type == const.TYPE_ACTIVITY_PRIZE:\r
+            return _("received badge")\r
         else:\r
             raise NotImplementedError()\r
 \r