From 2568b983ef7da43472bc196b13bbf4d46b75472e Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Mon, 23 Oct 2023 11:26:45 -0500 Subject: [PATCH] Progress on #289 --- src/eke.knowledge/src/eke/knowledge/sites.py | 24 +++++++++++++++---- .../templates/eke.knowledge/person.html | 20 ++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/eke.knowledge/src/eke/knowledge/sites.py b/src/eke.knowledge/src/eke/knowledge/sites.py index bc169af7..f0a50715 100644 --- a/src/eke.knowledge/src/eke/knowledge/sites.py +++ b/src/eke.knowledge/src/eke/knowledge/sites.py @@ -12,6 +12,7 @@ from django.core.exceptions import ValidationError from django.core.files.images import ImageFile from django.db import models +from django.db.models import Q, Case, When, Value, BooleanField from django.db.models.fields import Field from django.db.models.functions import Lower from django.http import HttpRequest, HttpResponse, HttpResponseRedirect @@ -311,11 +312,24 @@ def get_context(self, request: HttpRequest, *args, **kwargs) -> dict: context['has_interests'] = self.interests.count() > 0 if my_site: from eke.knowledge.protocols import Protocol - opened, closed = [], [] - protocols = Protocol.objects.filter(involvedInvestigatorSites=my_site).order_by(Lower('title')) - for protocol in protocols: - if protocol.finish_date: closed.append(protocol) - else: opened.append(protocol) + + # Whew, this was "fun" + q = Q(coordinatingInvestigatorSite=my_site) + q |= Q(leadInvestigatorSite=my_site) + q |= Q(involvedInvestigatorSites=my_site) + protocols = Protocol.objects.filter(q).distinct().annotate(role=Case( + When(coordinatingInvestigatorSite=my_site, then=Value('Coordinating')), + When(leadInvestigatorSite=my_site, then=Value('Leading')), + When(involvedInvestigatorSites=my_site, then=Value('Involved')), + default=Value('unknown'), + output_field=models.CharField() + )).annotate(finish_blank=Case( + When(finish_date='', then=Value(True)), + default=Value(False), + output_field=BooleanField() + )).order_by(Lower('title')) + + opened, closed = protocols.filter(finish_blank=True), protocols.filter(finish_blank=False) context['opened'], context['closed'] = opened, closed context['publications'] = my_site.publications.order_by(Lower('title')) return context diff --git a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html index 64db1ff1..e936f819 100644 --- a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html +++ b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html @@ -9,11 +9,19 @@

Open Protocols

{% if opened %} - + + + + + + + + {% for protocol in opened %} + @@ -27,11 +35,19 @@

Open Protocols

Closed Protocols

{% if closed %}
Protocol NameBiomarkersDatasets
Protocol NameInvestigatory RoleBiomarkersPublic Data Collections
{{protocol.title}}{{protocol.role}} {% protocol_counts protocol 'biomarkers' %} {% protocol_counts protocol 'data' %}
- + + + + + + + + {% for protocol in closed %} +
Protocol NameBiomarkersDatasets
Protocol NameInvestigatory RoleBiomarkersPublic Data Collections
{{protocol.title}}{{protocol.role}} {% protocol_counts protocol 'biomarkers' %} {% protocol_counts protocol 'data' %}