From 4476d03f6d9de6c6433a87e5e8c0fbbf6fff4111 Mon Sep 17 00:00:00 2001 From: davidpofo Date: Thu, 5 Aug 2021 16:49:30 -0400 Subject: [PATCH] Da/discussion updates (#1675) * get task for the attached object. added some more notes * fixed signature for getting a task for the attached object. * Added get_discussion_autocompletes changes to get the organization from the discussion(should be 1 to 1). If another models wants to implement it they can look at the get_discussion_autocompletes in TaskAnswer * Added get_discussion_autocompletes changes to get the organization from the discussion(should be 1 to 1). If another models wants to implement it they can look at the get_discussion_autocompletes in TaskAnswer --- discussion/models.py | 17 +++++++++++++++++ discussion/views.py | 3 ++- guidedmodules/models.py | 6 +++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/discussion/models.py b/discussion/models.py index e60b2a111..2a022739e 100644 --- a/discussion/models.py +++ b/discussion/models.py @@ -176,6 +176,11 @@ def post_comment(self, user, text, post_method, is_draft=False): def is_public(self): return getattr(self.attached_to_obj, 'is_discussion_public', lambda : False) + def is_discussion_inactive(self): + + if self.attached_to_obj is not None: + return True if self.attached_to_obj.title == "" else False + def can_comment(self, user): return user is not None and self.is_participant(user) @@ -246,6 +251,18 @@ def get_autocompletes(self, user): self._get_autocompletes = self.attached_to_obj.get_discussion_autocompletes(self) return self._get_autocompletes + @property + def get_task(self): + """ + Retrieves the task for the given discussion's attached object. For example Projects have root_task while TaskAnswer discussion would have a task. + """ + if hasattr(self.attached_to_obj, 'root_task'): + return self.attached_to_obj.root_task + elif hasattr(self.attached_to_obj, 'task'): + return self.attached_to_obj.task + else: + return False#TODO: not sure what to do if the model isn't related to a Task + class Comment(models.Model): discussion = models.ForeignKey(Discussion, related_name="comments", on_delete=models.CASCADE, help_text="The Discussion that this comment is attached to.") replies_to = models.ForeignKey('self', blank=True, null=True, related_name="replies", on_delete=models.CASCADE, help_text="If this is a reply to a Comment, the Comment that this is in reply to.") diff --git a/discussion/views.py b/discussion/views.py index 6efd63ab7..23a288d9c 100644 --- a/discussion/views.py +++ b/discussion/views.py @@ -92,7 +92,8 @@ def edit_discussion_comment(request): # save comment.save() - + # TODO: fully implement this add it as an attribute to Discussion model perhaps? Otherwise to find out if the text of the + # Current comment is the same as the previous text you would do something like: comment.extra['history'][-1]['previous-text'] != comment.text # Kick the attached object. if hasattr(comment.discussion.attached_to, 'on_discussion_comment_edited'): comment.discussion.attached_to.on_discussion_comment_edited(comment) diff --git a/guidedmodules/models.py b/guidedmodules/models.py index 5ba7f454f..33953432f 100644 --- a/guidedmodules/models.py +++ b/guidedmodules/models.py @@ -2008,12 +2008,12 @@ def get_notification_watchers(self): # required to attach a Discussion to it def get_discussion_autocompletes(self, discussion): # Get a list of all users who can be @-mentioned. It includes the discussion - # participants (i.e. people working on the same project and disussion guests) + # participants (i.e. people working on the same project and discussion guests) # plus anyone in the same organization. - organization = self.task.project.organization + organization = discussion.organization mentionable_users = set(discussion.get_all_participants()) \ | set( - User.objects.filter(projectmembership__project__organization=self.task.project.organization).distinct()) + User.objects.filter(projectmembership__project__organization=organization).distinct()) User.preload_profiles(mentionable_users) return { # @-mention participants in the discussion and other