From 08b22b2ade17b2add64756fd73b13012c62f4875 Mon Sep 17 00:00:00 2001 From: sandeepsajan0 <sandeepsajan0@gmail.com> Date: Thu, 16 Jun 2022 12:22:23 +0530 Subject: [PATCH] Add support for different type of users, and update template and template tags --- .../templates/activity/notifications.html | 5 +++-- .../activity/templatetags/activity_tags.py | 2 +- hypha/apply/activity/views.py | 21 +++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hypha/apply/activity/templates/activity/notifications.html b/hypha/apply/activity/templates/activity/notifications.html index 4e36a728c..0f20cb70c 100644 --- a/hypha/apply/activity/templates/activity/notifications.html +++ b/hypha/apply/activity/templates/activity/notifications.html @@ -4,6 +4,7 @@ {% block content %} <div class="admin-bar"> <div class="admin-bar__inner"> + <h1 class="gamma heading heading--no-margin heading--bold">{% trans "Notifications" %}</h1> <div class="tabs js-tabs"> <div class="tabs__container"> <a class="tab__item" href="#comments" data-tab="tab-1"> @@ -24,7 +25,7 @@ {% for comment in object_list %} {% if comment.type == 'comment' %} - <p><a href="{{ comment.source.get_absolute_url }}">{{ comment.source_content_type.name|source_type }}({{ comment.source.title|truncatechars:15 }})</a> + <p><a href="{{ comment.source.get_absolute_url }}">{{ comment.source_content_type.name|source_type }} ({{ comment.source.title|truncatechars:15 }})</a> : {{ comment.user }} made a comment</p> {% endif %} {% endfor %} @@ -33,7 +34,7 @@ <div class="tabs__content" id="tab-2"> <div class="feed"> {% for action in actions %} - <p><a href="{{ action.source.get_absolute_url }}">{{ action.source_content_type.name|source_type }}({{ action.source.title|truncatechars:15 }})</a> + <p><a href="{{ action.source.get_absolute_url }}">{{ action.source_content_type.name|source_type }} ({{ action.source.title|truncatechars:15 }})</a> : {{ action.message }} <a href="{{ action.related_object.get_absolute_url }}">{{ action.related_object.title }}</a> </p> {% endfor %} diff --git a/hypha/apply/activity/templatetags/activity_tags.py b/hypha/apply/activity/templatetags/activity_tags.py index 406010ede..5b0dc4b11 100644 --- a/hypha/apply/activity/templatetags/activity_tags.py +++ b/hypha/apply/activity/templatetags/activity_tags.py @@ -61,4 +61,4 @@ def visibility_options(activity, user): def source_type(value): if value and "submission" in value: return "Submission" - return value.capitalize() + return str(value).capitalize() diff --git a/hypha/apply/activity/views.py b/hypha/apply/activity/views.py index 3d6315ca6..197e042f5 100644 --- a/hypha/apply/activity/views.py +++ b/hypha/apply/activity/views.py @@ -2,7 +2,8 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import CreateView, ListView -from hypha.apply.users.decorators import staff_required +from hypha.apply.funds.models.submissions import ApplicationSubmission +from hypha.apply.users.decorators import login_required from hypha.apply.utils.views import DelegatedViewMixin from .forms import CommentForm @@ -61,13 +62,25 @@ class CommentFormView(DelegatedViewMixin, CreateView): return kwargs -@method_decorator(staff_required, name='dispatch') +@method_decorator(login_required, name='dispatch') class NotificationsView(ListView): model = Activity template_name = 'activity/notifications.html' def get_context_data(self, *, object_list=None, **kwargs): context = super(NotificationsView, self).get_context_data() - context['comments'] = Activity.comments.all().order_by('-timestamp') - context['actions'] = Activity.actions.all().order_by('-timestamp') + user = self.request.user + if user.is_applicant or user.is_partner: + context['comments'] = Activity.comments.filter(source__user=user).order_by('-timestamp') + context['actions'] = Activity.actions.filter(source__user=user).order_by('-timestamp') + elif user.is_reviewer: + reviewer_submissions = ApplicationSubmission.objects.filter(reviewers=user).values_list("id", flat=True) + context['comments'] = Activity.comments.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') + context['actions'] = Activity.actions.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') + elif user.is_apply_staff or user.is_apply_staff_admin: + context['comments'] = Activity.comments.all().order_by('-timestamp') + context['actions'] = Activity.actions.all().order_by('-timestamp') + else: + context['comments'] = Activity.comments.filter(user=user).order_by('-timestamp') + context['actions'] = Activity.actions.filter(user=user).order_by('-timestamp') return context -- GitLab