Skip to content
Snippets Groups Projects
Commit 3d2695de authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add list of contributors in the about page

TODO: contributor detail page
parent 465ca1d8
No related branches found
No related tags found
2 merge requests!43K8S deployments of release branche, and other updates,!35migrate iPPI-DB to Django 4.0
{% extends "about.html" %}
{% block title %}inhibitors of Protein-Protein Interaction Database{% endblock %}
{% block pagetitle %}Contributors{% endblock%}
{% block view_content %}
<div class="row">
<table class="table table-striped">
<thead>
<tr>
<th scope="col" title="Contributor Name">Name</th>
<th scope="col" title="Contributor ORCID Link">ORCID</th>
</tr>
</thead>
<tbody>
{% for contributor in object_list %}
<tr>
<td>{{ contributor.get_contributor_firstname | capfirst }} {{ contributor.get_contributor_lastname | capfirst }}</td>
<td><a href="{{ contributor.get_orcid_url }}" target="_blank">{{ contributor.get_orcid }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
\ No newline at end of file
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
<li> <li>
<a href="/about-pca">Chemical space</a> <a href="/about-pca">Chemical space</a>
</li> </li>
<li>
<a href="/contributors">Contributors</a>
</li>
</ul> </ul>
</div> </div>
</nav> </nav>
......
...@@ -44,7 +44,7 @@ class IppiDbStaticSitemap(Sitemap): ...@@ -44,7 +44,7 @@ class IppiDbStaticSitemap(Sitemap):
sitemaps = { sitemaps = {
"static": IppiDbStaticSitemap, "static": IppiDbStaticSitemap,
"compounds": views.site.IppiDbCompoundSitemap, "compounds": views.IppiDbCompoundSitemap,
} }
urlpatterns = [ urlpatterns = [
...@@ -61,6 +61,7 @@ urlpatterns = [ ...@@ -61,6 +61,7 @@ urlpatterns = [
name="physicochemistry", name="physicochemistry",
), ),
re_path(r"^about-pca/$", views.about_pca, name="pca"), re_path(r"^about-pca/$", views.about_pca, name="pca"),
re_path(r"^about-contributors/$", views.ContributorsListView.as_view(), name="contributors"),
re_path(r"^targetcentric/$", views.PDBView.as_view(), name="cavities"), re_path(r"^targetcentric/$", views.PDBView.as_view(), name="cavities"),
re_path(r"^targetcentric/networks$", views.NetworkView.as_view(), name="networks"), re_path(r"^targetcentric/networks$", views.NetworkView.as_view(), name="networks"),
re_path(r"^api/", include(ROUTER.urls)), re_path(r"^api/", include(ROUTER.urls)),
......
...@@ -32,6 +32,7 @@ from .about import ( ...@@ -32,6 +32,7 @@ from .about import (
about_pca, about_pca,
about_pharmacology, about_pharmacology,
about_physicochemistry, about_physicochemistry,
ContributorsListView,
) )
from django.conf import settings from django.conf import settings
...@@ -102,6 +103,7 @@ __all__ = [ ...@@ -102,6 +103,7 @@ __all__ = [
about_pca, about_pca,
about_pharmacology, about_pharmacology,
about_physicochemistry, about_physicochemistry,
ContributorsListView,
PdbViewSet, PdbViewSet,
DistanceViewSet, DistanceViewSet,
PDBView, PDBView,
......
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
iPPI-DB global statistics views iPPI-DB global statistics views
""" """
from django.db.models import F, Count, FloatField import re
from django.contrib.auth import get_user_model
from django.db.models import F, Count, FloatField, QuerySet
from django.db.models.functions import Cast, Floor from django.db.models.functions import Cast, Floor
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import ListView
import json import json
...@@ -19,6 +22,8 @@ from ippidb.models import ( ...@@ -19,6 +22,8 @@ from ippidb.models import (
Protein, Protein,
) )
from ippidb.ws import get_orcid_user_details
def about_general(request): def about_general(request):
compounds_count = Compound.objects.count() compounds_count = Compound.objects.count()
...@@ -278,3 +283,79 @@ def about_pca(request): ...@@ -278,3 +283,79 @@ def about_pca(request):
except PcaBiplotData.DoesNotExist: except PcaBiplotData.DoesNotExist:
context = {} context = {}
return render(request, "about-pca.html", context=context) return render(request, "about-pca.html", context=context)
User = get_user_model()
def cached_orcid_json(getter_function):
def new_function(self):
if self.__orcid_json is None:
self.__orcid_json = get_orcid_user_details(self.get_orcid())
ret = getter_function(self)
return ret
return new_function
def get_orcid(self):
"""
Get contributor ORCID from their allauth social account
"""
if self.socialaccount_set.count() > 0:
return self.socialaccount_set.all()[0].uid
return None
def get_orcid_url(self):
"""
Get contributor ORCID fURL from their allauth profile
"""
if self.socialaccount_set.count() > 0:
return self.socialaccount_set.all()[0].get_profile_url()
return None
@cached_orcid_json
def get_contributor_firstname(self):
"""
Get contributor full name from their ORCID profile
"""
orcid = self.get_orcid()
if orcid is not None:
data = self.__orcid_json
return data['first_name']
@cached_orcid_json
def get_contributor_lastname(self):
"""
Get contributor full name from their ORCID profile
"""
orcid = self.get_orcid()
if orcid is not None:
data = self.__orcid_json
return data['last_name']
User.add_to_class("get_orcid", get_orcid)
User.add_to_class("get_orcid_url", get_orcid_url)
User.add_to_class("__orcid_json", None)
User.add_to_class("get_contributor_firstname", get_contributor_firstname)
User.add_to_class("get_contributor_lastname", get_contributor_lastname)
class ContributorsListView(ListView):
"""
Contributors list view
"""
model = User
template_name = "about-contributors.html"
def get_queryset(self) -> QuerySet[User]:
qs = super().get_queryset()
qs = qs.annotate(contributions_count=Count("contribution")).filter(
socialaccount__isnull=False, contributions_count__gt=0
)
return qs
...@@ -598,6 +598,6 @@ def get_orcid_user_details(orcid: str) -> str: ...@@ -598,6 +598,6 @@ def get_orcid_user_details(orcid: str) -> str:
) )
data = resp.json() data = resp.json()
return { return {
"first": data["name"]["given-names"]["value"], "first_name": data["name"]["given-names"]["value"],
"last": data["name"]["family-name"]["value"], "last_name": data["name"]["family-name"]["value"],
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment