]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
Prevents questions on which the slug comes out empty to enter a redirect loop.
[osqa.git] / forum / models / user.py
index 7f1df5f65598ed958d762d6356eaf259b9c05f2c..2e71868d8d1333f19a1a27bfd929d515606aeecc 100644 (file)
@@ -151,6 +151,10 @@ class User(BaseModel, DjangoUser):
 
         return self.username
 
+    @property
+    def last_activity(self):
+        return self.actions.order_by('-action_date')[0].action_date
+
     @property
     def gravatar(self):
         return md5(self.email).hexdigest()
@@ -360,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()
@@ -369,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
@@ -404,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)