def can_upload_files(self):
return False
+ def is_a_super_user_or_staff(self):
+ return False
+
def true_if_is_super_or_staff(fn):
def decorated(self, *args, **kwargs):
return self.is_superuser or self.is_staff or fn(self, *args, **kwargs)
return self.username
+ @property
+ def last_activity(self):
+ try:
+ return self.actions.order_by('-action_date')[0].action_date
+ except:
+ return self.last_seen
+
@property
def gravatar(self):
return md5(self.email).hexdigest()
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
(settings.REP_TO_CONVERT_TO_COMMENT))
+
+ def can_convert_to_question(self, answer):
+ return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int
+ (settings.REP_TO_CONVERT_TO_QUESTION))
@true_if_is_super_or_staff
def can_accept_answer(self, answer):
- return self == answer.question.author
+ return self == answer.question.author and (settings.USERS_CAN_ACCEPT_OWN or answer.author != answer.question.author)
@true_if_is_super_or_staff
def can_create_tags(self):
@true_if_is_super_or_staff
def can_reopen_question(self, question):
- return self == question.author and self.reputation >= settings.REP_TO_REOPEN_OWN
+ return self == question.author and self.reputation >= int(settings.REP_TO_REOPEN_OWN)
@true_if_is_super_or_staff
def can_delete_post(self, post):
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):
return self.reputation >= int(settings.REP_TO_UPLOAD)
+ @true_if_is_super_or_staff
+ def is_a_super_user_or_staff(self):
+ return False
+
def email_valid_and_can_ask(self):
return 'ask' not in settings.REQUIRE_EMAIL_VALIDATION_TO or self.email_isvalid
def suspension(self):
if self.__dict__.get('_suspension_dencache_', False) != None:
try:
- self.__dict__['_suspension_dencache_'] = self.actions.get(action_type="suspend", canceled=False)
+ self.__dict__['_suspension_dencache_'] = self.reputes.get(action__action_type="suspend", action__canceled=False).action
except ObjectDoesNotExist:
self.__dict__['_suspension_dencache_'] = None
except MultipleObjectsReturned:
logging.error("Multiple suspension actions found for user %s (%s)" % (self.username, self.id))
- self.__dict__['_suspension_dencache_'] = self.actions.filter(action_type="suspend", canceled=False
- ).order_by('-action_date')[0]
+ self.__dict__['_suspension_dencache_'] = self.reputes.filter(action__action_type="suspend", action__canceled=False
+ ).order_by('-action__action_date')[0]
return self.__dict__['_suspension_dencache_']
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()
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
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)
class SubscriptionSettings(models.Model):
- user = models.OneToOneField(User, related_name='subscription_settings')
+ user = models.OneToOneField(User, related_name='subscription_settings', editable=False)
enable_notifications = models.BooleanField(default=True)
#notify if
member_joins = models.CharField(max_length=1, default='n')
- new_question = models.CharField(max_length=1, default='d')
+ new_question = models.CharField(max_length=1, default='n')
new_question_watched_tags = models.CharField(max_length=1, default='i')
subscribed_questions = models.CharField(max_length=1, default='i')