]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
OSQA-583, prevent the caching of the JavaScript files. Appending a random number...
[osqa.git] / forum / models / user.py
index f8c91d65f10a11fddbfc61f917d1c60ddb2b1650..e7365388eb2efce62bfba607f9b8be18f06839e5 100644 (file)
@@ -4,10 +4,8 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser
 from django.db.models import Q
-try:
-    from hashlib import md5
-except:
-    from md5 import new as md5
+
+from forum.settings import TRUNCATE_LONG_USERNAMES, TRUNCATE_USERNAMES_LONGER_THAN
 
 import string
 from random import Random
@@ -150,12 +148,17 @@ class User(BaseModel, DjangoUser):
 
     @property
     def decorated_name(self):
+        username = self.username
+
+        if len(username) > TRUNCATE_USERNAMES_LONGER_THAN and TRUNCATE_LONG_USERNAMES:
+            username = '%s...' % username[:TRUNCATE_USERNAMES_LONGER_THAN-3]
+
         if settings.SHOW_STATUS_DIAMONDS:
             if self.is_superuser:
-                return u"%s \u2666\u2666" % self.username
+                return u"%s \u2666\u2666" % username
 
             if self.is_staff:
-                return u"%s \u2666" % self.username
+                return u"%s \u2666" % username
 
         return self.username
 
@@ -286,9 +289,9 @@ 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_CONVERT_COMMENTS_TO_ANSWERS)
+        return (comment.parent.node_type in ('question', 'answer')) and (self.is_superuser or self.is_staff or (
+            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