X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/303b118d8ffc0ed2285166e362a91774f64ad807..5084e9c7ae5281439d6b78f599821e7915844850:/forum/models/user.py diff --git a/forum/models/user.py b/forum/models/user.py index 2e71868..b18047e 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -85,6 +85,9 @@ class AnonymousUser(DjangoAnonymousUser): 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) @@ -153,7 +156,10 @@ class User(BaseModel, DjangoUser): @property def last_activity(self): - return self.actions.order_by('-action_date')[0].action_date + try: + return self.actions.order_by('-action_date')[0].action_date + except: + return None @property def gravatar(self): @@ -276,7 +282,7 @@ class User(BaseModel, DjangoUser): @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): @@ -307,7 +313,7 @@ class User(BaseModel, DjangoUser): @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): @@ -315,12 +321,16 @@ 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): 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