Skip to content

Commit

Permalink
Simplified source filter logic, updated activity tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wes-otf committed Feb 3, 2025
1 parent 911de36 commit ba80f5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
25 changes: 5 additions & 20 deletions hypha/apply/activity/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from django.db.models.functions import JSONObject
from django.utils import timezone

from hypha.apply.funds.models.submissions import ApplicationSubmission
from hypha.apply.projects.models.project import Project
from hypha.apply.todo.models import Task

from .models import Activity
Expand Down Expand Up @@ -50,25 +48,12 @@ def get_related_activities_for_user(obj, user):
Returns:
[`Activity`][hypha.apply.activity.models.Activity] queryset
"""
proj_content_type = ContentType.objects.get_for_model(Project)
app_content_type = ContentType.objects.get_for_model(ApplicationSubmission)

# Determine if the provided object is an ApplicationSubmission or Project, then pull
# the related it's related Project/ApplicationSubmission activites if attribute it exists
if isinstance(obj, ApplicationSubmission):
source_filter = Q(source_object_id=obj.id, source_content_type=app_content_type)
if hasattr(obj, "project") and obj.project:
source_filter = source_filter | Q(
source_object_id=obj.project.id, source_content_type=proj_content_type
)
if hasattr(obj, "project") and obj.project:
source_filter = Q(submission=obj) | Q(project=obj.project)
if hasattr(obj, "submission") and obj.submission:
source_filter = Q(submission=obj.submission) | Q(project=obj)
else:
source_filter = Q(
source_object_id=obj.id, source_content_type=proj_content_type
)
if hasattr(obj, "submission") and obj.submission:
source_filter = source_filter | Q(
source_object_id=obj.submission.id, source_content_type=app_content_type
)
source_filter = Q(submission=obj)

queryset = (
Activity.objects.filter(source_filter)
Expand Down
6 changes: 5 additions & 1 deletion hypha/apply/activity/templatetags/activity_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def visibility_options(activity, user) -> str:
Returns:
A JSON string of visibility options
"""
submission_partner_list = activity.source.partners.all()
if hasattr(activity.source, "partners"):
submission_partner_list = activity.source.partners.all()
else:
submission_partner_list = activity.source.submission.partners.all()

choices = activity.visibility_choices_for(user, submission_partner_list)
return json.dumps(choices)

Expand Down

0 comments on commit ba80f5f

Please sign in to comment.