Skip to content

Commit

Permalink
HK suggestion for #298: log in link
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Nov 10, 2023
1 parent e2aa49b commit 61ce543
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/eke.knowledge/src/eke/knowledge/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.db.models.functions import Lower
from django.http import HttpRequest
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.text import slugify
from django_plotly_dash import DjangoDash
from modelcluster.fields import ParentalManyToManyField
Expand Down Expand Up @@ -147,6 +148,12 @@ class RDFMeta:
str(rdflib.DCTERMS.description): _ComplexDescriptionRDFAttribute('description', scalar=True),
esu('protocolType'): RDFAttribute('kind', scalar=True)
}
def _authentication(self, request: HttpRequest) -> dict:
'''Given a request, determine if the user is authenticated and what the login link would be if not.'''
params = {'authenticated': request.user.is_authenticated}
if not params['authenticated']:
params['login'] = reverse('wagtailcore_login') + '?next=' + request.path
return params
def get_context(self, request: HttpRequest, *args, **kwargs) -> dict:
'''Get the context for the page template.'''
context = super().get_context(request, args, kwargs)
Expand All @@ -158,6 +165,8 @@ def get_context(self, request: HttpRequest, *args, **kwargs) -> dict:
total_collections = dcs.count()
dcs = filter_by_user(dcs, request.user)
invisible_collections = total_collections - dcs.count()
if invisible_collections:
context.update(self._authentication(request))
context['data_collections'] = dcs
context['invisible_collections'] = invisible_collections
from eke.biomarkers.biomarker import Biomarker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,22 @@ <h2>Data Collections</h2>
{% endfor %}
</ul>
{% endif %}
{% if invisible_collections == 1 %}
<p class='small'>There is one collection of data that has not yet been made public.</p>
{% elif invisible_collections > 1 %}
<p class='small'>There are {{invisible_collections}} collections of data that have not yet been made public.</p>
{% if invisible_collections %}
<p class='small'>
{% if invisible_collections == 1 %}
There is one collection of data that has not yet been made public.
{% elif invisible_collections > 1 %}
There are {{invisible_collections}} collections of data that have not yet been made public.
{% endif %}
{% if authenticated %}
You are currently logged in, but not with an account that can view the names of the
non-public data collections.
<a href='{{login}}'>Logging in with a different account</a> may give you access.
{% else %}
<a href='{{login}}'>Logging in</a> may you give you access to the names of the
non-public data collections.
{% endif %}
</p>
{% endif %}
{% else %}
<ul>
Expand Down

0 comments on commit 61ce543

Please sign in to comment.