From 879b8cf508eb603cc4c362ddc5081d748bb8dc3b Mon Sep 17 00:00:00 2001 From: sandeepsajan0 <sandeepsajan0@gmail.com> Date: Wed, 15 Jun 2022 17:32:06 +0530 Subject: [PATCH] [Draft]Add notifications page and list activities in tabs --- .../templates/activity/notifications.html | 48 +++++++++++++++++++ .../activity/templatetags/activity_tags.py | 7 +++ hypha/apply/activity/urls.py | 3 ++ hypha/apply/activity/views.py | 16 ++++++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 hypha/apply/activity/templates/activity/notifications.html diff --git a/hypha/apply/activity/templates/activity/notifications.html b/hypha/apply/activity/templates/activity/notifications.html new file mode 100644 index 000000000..4e36a728c --- /dev/null +++ b/hypha/apply/activity/templates/activity/notifications.html @@ -0,0 +1,48 @@ +{% extends "base-apply.html" %} +{% load i18n static activity_tags %} + +{% block content %} +<div class="admin-bar"> + <div class="admin-bar__inner"> + <div class="tabs js-tabs"> + <div class="tabs__container"> + <a class="tab__item" href="#comments" data-tab="tab-1"> + {% trans "Comments" %} + </a> + + <a class="tab__item" href="#actions" data-tab="tab-2"> + {% trans "Actions" %} + </a> + </div> + </div> + </div> +</div> + +<div class="wrapper wrapper--large wrapper--tabs js-tabs-content"> + {# Tab 1 #} + <div class="tabs__content" id="tab-1"> + {% 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> + : {{ comment.user }} made a comment</p> + {% endif %} + {% endfor %} + </div> + {# Tab 2 #} + <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> + : {{ action.message }} <a href="{{ action.related_object.get_absolute_url }}">{{ action.related_object.title }}</a> + </p> + {% endfor %} + </div> + </div> +</div> + +{% endblock %} + +{% block extra_js %} + <script src="{% static 'js/apply/tabs.js' %}"></script> +{% endblock %} diff --git a/hypha/apply/activity/templatetags/activity_tags.py b/hypha/apply/activity/templatetags/activity_tags.py index 2df2a15d1..406010ede 100644 --- a/hypha/apply/activity/templatetags/activity_tags.py +++ b/hypha/apply/activity/templatetags/activity_tags.py @@ -55,3 +55,10 @@ def display_for(activity, user): def visibility_options(activity, user): choices = activity.visibility_choices_for(user) return json.dumps(choices) + + +@register.filter +def source_type(value): + if value and "submission" in value: + return "Submission" + return value.capitalize() diff --git a/hypha/apply/activity/urls.py b/hypha/apply/activity/urls.py index 19c085527..4ba4a55f8 100644 --- a/hypha/apply/activity/urls.py +++ b/hypha/apply/activity/urls.py @@ -1,8 +1,11 @@ from django.urls import include, path +from .views import NotificationsView + app_name = 'activity' urlpatterns = [ path('anymail/', include('anymail.urls')), + path('notifications/', NotificationsView.as_view(), name='notifications') ] diff --git a/hypha/apply/activity/views.py b/hypha/apply/activity/views.py index 7b75221f0..3d6315ca6 100644 --- a/hypha/apply/activity/views.py +++ b/hypha/apply/activity/views.py @@ -1,6 +1,8 @@ from django.utils import timezone -from django.views.generic import CreateView +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.utils.views import DelegatedViewMixin from .forms import CommentForm @@ -57,3 +59,15 @@ class CommentFormView(DelegatedViewMixin, CreateView): kwargs = super().get_form_kwargs() kwargs.pop('instance') return kwargs + + +@method_decorator(staff_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') + return context -- GitLab