X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/f982c8513663a0f9927fb04ba650a5f63bb7f21f..7cdc19bcfed965828015c882bed2cd82a7f442d7:/forum/models/user.py?ds=inline diff --git a/forum/models/user.py b/forum/models/user.py index 7f1df5f..2e71868 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -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)