X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/95d8d68511babfe9ef9a11f59a29b17f65921bff..f667e349c7709930fa4b73d922ec63b6bd3bdf16:/forum/actions/meta.py diff --git a/forum/actions/meta.py b/forum/actions/meta.py index b16f4f9..a964ef1 100644 --- a/forum/actions/meta.py +++ b/forum/actions/meta.py @@ -27,6 +27,14 @@ class VoteAction(ActionProxy): except: return None + @classmethod + def get_action_for(cls, user, node): + try: + vote = Vote.objects.get(user=user, node=node) + return vote.action + except: + return None + def describe_vote(self, vote_desc, viewer=None): return _("%(user)s %(vote_desc)s %(post_desc)s") % { 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), @@ -89,12 +97,12 @@ class FlagAction(ActionProxy): flag.save() self.node.reset_flag_count_cache() - if self.node.flag_count == int(settings.FLAG_COUNT_TO_HIDE_POST): + if self.node.flag_count >= int(settings.FLAG_COUNT_TO_HIDE_POST): self.repute(self.node.author, -int(settings.REP_LOST_BY_FLAGGED_3_TIMES)) - if self.node.flag_count == int(settings.FLAG_COUNT_TO_DELETE_POST): + if self.node.flag_count >= int(settings.FLAG_COUNT_TO_DELETE_POST): self.repute(self.node.author, -int(settings.REP_LOST_BY_FLAGGED_5_TIMES)) - if not self.node.deleted: + if not self.node.nis.deleted: DeleteAction(node=self.node, user=self.user, extra="BYFLAGGED").save() def cancel_action(self): @@ -125,18 +133,16 @@ class AcceptAnswerAction(ActionProxy): self.repute(self.node.author, int(settings.REP_GAIN_BY_ACCEPTED)) def process_action(self): - self.node.parent.extra_ref = self.node - self.node.parent.save() self.node.marked = True - self.node.extra_action = self + self.node.nstate.accepted = self self.node.save() + self.node.question.reset_accepted_count_cache() def cancel_action(self): - self.node.parent.extra_ref = None - self.node.parent.save() self.node.marked = False - self.node.extra_action = None + self.node.nstate.accepted = None self.node.save() + self.node.question.reset_accepted_count_cache() def describe(self, viewer=None): answer = self.node @@ -149,7 +155,7 @@ class AcceptAnswerAction(ActionProxy): return _("%(user)s accepted %(answerer)s answer on %(asker)s question %(question)s") % { 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), - 'answerer': self.hyperlink(answer.author.get_profile_url(), self.friendly_username(viewer, answer.author)), + 'answerer': self.hyperlink(answer.author.get_profile_url(), self.friendly_ownername(viewer, answer.author)), 'asker': asker, 'question': self.hyperlink(question.get_absolute_url(), question.title) } @@ -171,23 +177,21 @@ class FavoriteAction(ActionProxy): class DeleteAction(ActionProxy): def process_action(self): - self.node.deleted = self - self.node.save() + self.node.mark_deleted(self) if self.node.node_type == "answer": self.node.question.reset_answer_count_cache() def cancel_action(self): - self.node.deleted = None - self.node.save() + self.node.mark_deleted(None) if self.node.node_type == "answer": self.node.question.reset_answer_count_cache() def describe(self, viewer=None): - return _("%(user)s deleted %(post_desc)s: %(reason)s") % { + return _("%(user)s deleted %(post_desc)s") % { 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), - 'post_desc': self.describe_node(viewer, self.node), 'reason': self.reason(), + 'post_desc': self.describe_node(viewer, self.node) } def reason(self):