From 181926a082856b299f64919c40126473c31ff67f Mon Sep 17 00:00:00 2001 From: Parbhat Puri <parbhatpuri17@gmail.com> Date: Fri, 19 Apr 2019 11:36:29 +0000 Subject: [PATCH] GH-1147: Dashboard view for partners --- .../dashboard/partner_dashboard.html | 98 +++++++++++-------- opentech/apply/dashboard/views.py | 63 ++++++++---- opentech/apply/funds/models/submissions.py | 3 + opentech/apply/funds/tables.py | 5 + 4 files changed, 110 insertions(+), 59 deletions(-) diff --git a/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html b/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html index 122386a8b..7bbd5c514 100644 --- a/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html @@ -1,57 +1,71 @@ {% extends "base-apply.html" %} {% load render_table from django_tables2 %} -{% load static wagtailcore_tags workflow_tags statusbar_tags %} +{% load static statusbar_tags workflow_tags %} -{% block title %}Submission Dashboard{% endblock %} +{% block title %}OTF partner Dashboard{% endblock %} {% block content %} <div class="admin-bar"> - <div class="admin-bar__inner wrapper--applicant-dashboard"> - <div> - <h3 class="heading heading--no-margin">Dashboard</h3> - <h5>An overview of active and past submissions</h5> - </div> - <div class="wrapper wrapper--cta-box"> - <h4 class="heading heading--no-margin">Submit a new application</h4> - <h5 class="heading heading--normal">Apply now for our open rounds</h5> - <a class="button button--primary" href="{% pageurl APPLY_SITE.root_page %}" class="button">Apply</a> - </div> + <div class="admin-bar__inner"> + {% block page_header %} + <h1 class="gamma heading heading--no-margin heading--bold">Dashboard</h1> + {% endblock %} </div> </div> + <div class="wrapper wrapper--large wrapper--inner-space-medium"> - <h3>Your active submissions</h3> - {% for submission in my_active_submissions %} - <div class="wrapper wrapper--status-bar-outer"> - <div class="wrapper wrapper--status-bar-inner"> - <div> - <h5 class="heading heading--no-margin"><a class="link link--underlined" href="{% url 'funds:submissions:detail' submission.id %}">{{ submission.title }}</a></h5> - <h6 class="heading heading--no-margin heading--submission-meta"><span>Submitted:</span> {{ submission.submit_time.date }} by {{ submission.user.get_full_name }}</h6> + + <div class="wrapper wrapper--bottom-space"> + <h4 class="heading heading--normal"> + Your partner submissions <span class="heading heading--submission-count">{{ partner_submissions_count }}</span> + </h4> + + {% if partner_submissions.data %} + {% render_table partner_submissions %} + {% else %} + No submissions + {% endif %} + </div> + + {% if my_reviewed.data %} + <div class="wrapper wrapper--bottom-space"> + <h4 class="heading heading--normal">Your previous reviews</h4> + {% render_table my_reviewed %} + </div> + {% endif %} + + <div class="wrapper wrapper--bottom-space"> + <h4 class="heading heading--normal">Your active submissions</h4> + {% for submission in my_submissions %} + <div class="wrapper wrapper--status-bar-outer"> + <div class="wrapper wrapper--status-bar-inner"> + <div> + <h5 class="heading heading--no-margin"><a class="link link--underlined" href="{% url 'funds:submissions:detail' submission.id %}">{{ submission.title }}</a></h5> + <h6 class="heading heading--no-margin heading--submission-meta"><span>Submitted:</span> {{ submission.submit_time.date }} by {{ submission.user.get_full_name }}</h6> + </div> + {% status_bar submission.workflow submission.phase request.user css_class="status-bar--small" %} </div> - {% status_bar submission.workflow submission.phase request.user css_class="status-bar--small" %} + {% if request.user|has_edit_perm:submission %} + <a class="button button--primary" href="{% url 'funds:submissions:edit' submission.id %}"> + {% if submission.status == 'draft_proposal' %} + Start your {{ submission.stage }} application + {% else %} + Edit + {% endif %} + </a> + {% endif %} </div> - {% if request.user|has_edit_perm:submission %} - <a class="button button--primary" href="{% url 'funds:submissions:edit' submission.id %}"> - {% if submission.status == 'draft_proposal' %} - Start your {{ submission.stage }} application - {% else %} - Edit - {% endif %} - </a> - {% endif %} + {% empty %} + No active submissions + {% endfor %} </div> - {% empty %} - No active submissions - {% endfor %} -</div> -{% if table.data %} - <div class="wrapper wrapper--large wrapper--inner-space-medium"> - <h3>Submission history</h3> - {% render_table table %} - </div> -{% endif %} -{% endblock %} + {% if my_inactive_submissions_table.data %} + <div class="wrapper wrapper--bottom-space"> + <h4 class="heading heading--normal">Submission history</h4> + {% render_table my_inactive_submissions_table %} + </div> + {% endif %} +</div> -{% block extra_js %} - <script src="{% static 'js/apply/submission-tooltips.js' %}"></script> {% endblock %} diff --git a/opentech/apply/dashboard/views.py b/opentech/apply/dashboard/views.py index 47b7c0969..84ac2ce23 100644 --- a/opentech/apply/dashboard/views.py +++ b/opentech/apply/dashboard/views.py @@ -13,6 +13,7 @@ from opentech.apply.funds.tables import ( SummarySubmissionsTable, SummarySubmissionsTableWithRole, review_filter_for_user, + PartnerSubmissionsTable ) from opentech.apply.utils.views import ViewDispatcher @@ -153,10 +154,10 @@ class ReviewerDashboardView(TemplateView): my_submissions = qs.filter( user=request.user ).active().current().select_related('draft_revision') - my_submissions = [ submission.from_draft() for submission in my_submissions ] + my_inactive_submissions_qs = qs.filter(user=self.request.user).inactive().current() my_inactive_submissions_table = ReviewerSubmissionsTable( my_inactive_submissions_qs, prefix='my-submissions-' @@ -173,29 +174,57 @@ class ReviewerDashboardView(TemplateView): return super().get_context_data(**kwargs) -class PartnerDashboardView(SingleTableView): +class PartnerDashboardView(TemplateView): template_name = 'dashboard/partner_dashboard.html' - model = ApplicationSubmission - table_class = SubmissionsTable - def get_queryset(self): - return self.model.objects.filter( - user=self.request.user - ).inactive().current().for_table(self.request.user) + def get_partner_submissions(self, user, qs): + partner_submissions_qs = qs.partner_for(user).order_by('-submit_time') + partner_submissions_table = PartnerSubmissionsTable(partner_submissions_qs, prefix='my-partnered-') - def get_context_data(self, **kwargs): - my_active_submissions = self.model.objects.filter( - user=self.request.user - ).active().current().select_related('draft_revision') + return partner_submissions_qs, partner_submissions_table - my_active_submissions = [ - submission.from_draft() for submission in my_active_submissions + def get_my_reviewed(self, request, qs): + my_reviewed_qs = qs.reviewed_by(request.user).order_by('-submit_time') + my_reviewed_table = PartnerSubmissionsTable(my_reviewed_qs, prefix='my-reviewed-') + + return my_reviewed_qs, my_reviewed_table + + def get_my_submissions(self, request, qs): + my_submissions = qs.filter( + user=request.user + ).active().current().select_related('draft_revision') + my_submissions = [ + submission.from_draft() for submission in my_submissions ] - return super().get_context_data( - my_active_submissions=my_active_submissions, - **kwargs, + my_inactive_submissions_qs = qs.filter(user=self.request.user).inactive().current() + my_inactive_submissions_table = PartnerSubmissionsTable( + my_inactive_submissions_qs, prefix='my-submissions-' ) + return my_submissions, my_inactive_submissions_table + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + qs = ApplicationSubmission.objects.all().for_table(self.request.user) + + # Submissions in which user added as partner + partner_submissions_qs, partner_submissions = self.get_partner_submissions(self.request.user, qs) + + # Partner's reviewed submissions + my_reviewed_qs, my_reviewed = self.get_my_reviewed(self.request, qs) + + # Applications by partner + my_submissions, my_inactive_submissions_table = self.get_my_submissions(self.request, qs) + + context.update({ + 'partner_submissions': partner_submissions, + 'partner_submissions_count': partner_submissions_qs.count(), + 'my_reviewed': my_reviewed, + 'my_submissions': my_submissions, + 'my_inactive_submissions_table': my_inactive_submissions_table, + }) + + return context class CommunityDashboardView(SingleTableView): diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index 0151cb79e..cd0505443 100644 --- a/opentech/apply/funds/models/submissions.py +++ b/opentech/apply/funds/models/submissions.py @@ -96,6 +96,9 @@ class ApplicationSubmissionQueryset(JSONOrderable): def reviewed_by(self, user): return self.filter(reviews__author=user) + def partner_for(self, user): + return self.filter(partners=user) + def awaiting_determination_for(self, user): return self.filter(status__in=DETERMINATION_RESPONSE_PHASES).filter(lead=user) diff --git a/opentech/apply/funds/tables.py b/opentech/apply/funds/tables.py index a08dc0512..23c3ba801 100644 --- a/opentech/apply/funds/tables.py +++ b/opentech/apply/funds/tables.py @@ -93,6 +93,11 @@ class ReviewerSubmissionsTable(SubmissionsTable): orderable = False +class PartnerSubmissionsTable(SubmissionsTable): + class Meta(SubmissionsTable.Meta): + orderable = False + + class LabeledCheckboxColumn(tables.CheckBoxColumn): def wrap_with_label(self, checkbox, for_value): return format_html( -- GitLab