Commit d52fc83c authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Adding a model Contribution to have a pointer on a contribution and know its...

Adding a model Contribution to have a pointer on a contribution and know its origin. Adding link to its related DetailView
parent fcc8d024
......@@ -8,11 +8,13 @@ import operator
import re
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.db import models, transaction
from django.db.models import FloatField, IntegerField, BooleanField
from django.db.models import Max, Count, F, Q, Case, When
from django.db.models.functions import Cast
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from .utils import FingerPrinter, smi2inchi, smi2inchikey
......@@ -1246,3 +1248,25 @@ class DrugbankCompoundTanimoto(models.Model):
drugbank_compound = models.ForeignKey(DrugBankCompound, models.CASCADE)
tanimoto = models.DecimalField(
'Tanimoto value', max_digits=5, decimal_places=4)
class Contribution(models.Model):
contributor = models.ForeignKey(
ppi = models.ForeignKey(
bibliography = models.ForeignKey(
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def get_absolute_url(self):
return reverse('contribution-detail', kwargs={'contribution_pk':})
......@@ -18,9 +18,22 @@
<div id="main">
<div id="content" class="main-content">
<div class="section row">
{% include "ippidb/bibliography_card.html" with object=bibliography css_class="col-xs-12 col-md-6"%}
{% include "ippidb/ppi_card.html" with object=ppi css_class="col-xs-12 col-md-6" %}
<div class="col-12">
{%if contribution %}
<div class="col-xs-12 col-md-4 col-lg-2 mb-4">
<div class="card">
<div class="card-body">
Contribution of <b>{{contribution.contributor.username}}</b> on {{contribution.created_at}}
{% if contribution.updated_at == contribution.created_at %}
Last updated on {{contribution.updated_at}}
{% endif %}
{%endif %}
{% include "ippidb/bibliography_card.html" with object=bibliography css_class="col-xs-12 col-md-8 col-lg-4 mb-4"%}
{% include "ippidb/ppi_card.html" with object=ppi css_class="col-xs-12 col-lg-6 mb-4" %}
<div class="col-12 mb-4">
<div class="card">
<h5 class="card-header">{{complexes|verbose_name}}</h5>
<div class="card-body">
......@@ -30,7 +43,7 @@
<div class="col-12">
<div class="col-12 mb-4">
<div class="card">
<h5 class="card-header">Tests</h5>
<div class="card-body">
......@@ -46,7 +59,7 @@
<div class="col-12">
<div class="col-12 mb-4">
<div class="card">
<h5 class="card-header">{{refcompoundbiblio|verbose_name}}</h5>
<div class="card-body">
......@@ -3,9 +3,9 @@ iPPI-DB URLs routing module
from django.conf.urls import include, url
from . import views
from ippidb.forms import *
from ippidb.views import IppiWizard, FORMS
from . import views
ippidb_wizard = IppiWizard.as_view(FORMS,
......@@ -25,6 +25,11 @@ urlpatterns = [
url(r'^contribute/view/(?P<bibli_pk>\d+)-(?P<ppi_pk>\d+)/$', views.admin_session_view, name='admin-session-view'),
url(r'^contribute/view/(?P<bibli_pk>\d+)-/$', views.admin_session_view, {'ppi_pk': None}),
url(r'^contribute/view/-(?P<ppi_pk>\d+)/$', views.admin_session_view, {'bibli_pk': None}),
{'ppi_pk': None, 'bibli_pk': None},
url(r'^contribute/update/$', views.update, name='admin-session-update'),
url(r'^utils/mol2smi$', views.convert_mol2smi, name='mol2smi'),
url(r'^utils/smi2mol$', views.convert_smi2mol, name='smi2mol'),
......@@ -309,14 +309,34 @@ class IppiWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
# re-save the ppi to update its name
super().done(form_list=form_list, **kwargs)
return admin_session_view(self.request,,
# get/build the contribution object
contribution, created = models.Contribution.objects.get_or_create(
if not created:
# update its date of modification
# super().done(form_list=form_list, **kwargs)
return admin_session_view(self.request, bibli_pk=None, ppi_pk=None,
def admin_session_view(request, bibli_pk, ppi_pk):
def admin_session_view(request, bibli_pk, ppi_pk, contribution_pk=None):
context = {}
if contribution_pk:
contribution = get_object_or_404(models.Contribution, pk=contribution_pk)
bibliography = contribution.bibliography
ppi = contribution.ppi
context["contribution"] = contribution
bibliography = None
ppi = None
if bibli_pk:
bibliography = get_object_or_404(models.Bibliography, pk=bibli_pk)
if bibliography:
context["bibliography"] = bibliography
context["testactivitydescription"] = bibliography.testactivitydescription_set.all()
context["testcytotoxdescription"] = bibliography.testcytotoxdescription_set.all()
......@@ -325,7 +345,8 @@ def admin_session_view(request, bibli_pk, ppi_pk):
if ppi_pk:
ppi = get_object_or_404(models.Ppi, pk=ppi_pk)
if ppi:
context["ppi"] = ppi
context["complexes"] = ppi.ppicomplex_set.all()
return render(request, 'contribute-view.html', context=context)
return render(request, 'contribute-detail.html', context=context)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment