]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
Avoids a strange error probably coming from either django or python.
[osqa.git] / forum / models / user.py
index 34c6b36f39d79db7af39dc55e6e1d2a206fec3ba..fb13c27f7c5524c27b2aaa544d207f76ac978a97 100644 (file)
@@ -315,7 +315,7 @@ class User(BaseModel, DjangoUser):
             return self.can_delete_comment(post)
 
         return (self == post.author and (post.__class__.__name__ == "Answer" or
-        not post.answers.exclude(author=self).count()))
+        not post.answers.exclude(author__id=self.id).count()))
 
     @true_if_is_super_or_staff
     def can_upload_files(self):
@@ -364,7 +364,7 @@ class User(BaseModel, DjangoUser):
     class Meta:
         app_label = 'forum'
 
-class UserProperty(models.Model):
+class UserProperty(BaseModel):
     user = models.ForeignKey(User, related_name='properties')
     key = models.CharField(max_length=16)
     value = PickledObjectField()
@@ -373,6 +373,16 @@ class UserProperty(models.Model):
         app_label = 'forum'
         unique_together = ('user', 'key')
 
+    def cache_key(self):
+        return self._generate_cache_key("%s:%s" % (self.user.id, self.key))
+
+    @classmethod
+    def infer_cache_key(cls, querydict):
+        if 'user' in querydict and 'key' in querydict:
+            return cls._generate_cache_key("%s:%s" % (querydict['user'].id, querydict['key']))
+
+        return None
+
 class UserPropertyDict(object):
     def __init__(self, user):
         self.__dict__['_user'] = user
@@ -408,7 +418,7 @@ class UserPropertyDict(object):
             if current:
                 current.value = value
                 self.__dict__[name] = value
-                current.save()
+                current.save(full_save=True)
             else:
                 user = self.__dict__['_user']
                 prop = UserProperty(user=user, value=value, key=name)