Skip to content

Commit

Permalink
Da/discussion updates (#1675)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
davidpofo authored Aug 5, 2021
1 parent 7ffbca1 commit 4476d03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions discussion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<Deleted Discussion>" else False

def can_comment(self, user):
return user is not None and self.is_participant(user)

Expand Down Expand Up @@ -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.")
Expand Down
3 changes: 2 additions & 1 deletion discussion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions guidedmodules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4476d03

Please sign in to comment.