Commit 53b9503d authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Using ViewOnSiteModelAdmin, adding get_absolute_url in Biblio, Ppi, and Compound

parent 4a882e36
......@@ -4,12 +4,36 @@ iPPI-DB django admin module
from django.apps import apps
from django.contrib import admin
from django.contrib.admin.options import get_content_type_for_model
from django.utils.html import format_html
from django.utils.translation import ugettext
from .models import *
class ViewOnSiteModelAdmin(admin.ModelAdmin):
class Media:
css = {
'all': ('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',)
}
def __init__(self, model, admin_site):
if callable(getattr(model, "get_absolute_url", None)) and callable(self.view_on_site_in_list):
self.list_display += ('view_on_site_in_list',)
super().__init__(model, admin_site)
def view_on_site_in_list(self, obj):
return format_html(
'<center><a href="' + reverse('admin:view_on_site', kwargs={
'content_type_id': get_content_type_for_model(obj).pk,
'object_id': obj.pk
}) + '"><i class="fa fa-external-link"></i></a><center>')
view_on_site_in_list.short_description = format_html('<center>' + ugettext('View on site') + '<center>')
@admin.register(Bibliography)
class BibliographyAdmin(admin.ModelAdmin):
class BibliographyAdmin(ViewOnSiteModelAdmin):
list_display = ('authors_list', 'title',
'journal_name', 'biblio_year', 'id_source')
......@@ -39,14 +63,14 @@ class DomainAdmin(admin.ModelAdmin):
@admin.register(ProteinDomainBoundComplex)
class ProteinDomainBoundComplexAdmin(admin.ModelAdmin):
class ProteinDomainBoundComplexAdmin(ViewOnSiteModelAdmin):
list_display = ('protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p')
list_display_links = (
'protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p')
@admin.register(ProteinDomainPartnerComplex)
class ProteinDomainPartnerComplexAdmin(admin.ModelAdmin):
class ProteinDomainPartnerComplexAdmin(ViewOnSiteModelAdmin):
list_display = ('protein', 'domain', 'ppc_copy_nb')
list_display_links = ('protein', 'domain', 'ppc_copy_nb')
......@@ -57,18 +81,18 @@ class Symmetry(admin.ModelAdmin):
@admin.register(Compound)
class Compound(admin.ModelAdmin):
class Compound(ViewOnSiteModelAdmin):
list_display = ('id', 'iupac_name', 'common_name', 'canonical_smile')
search_fields = ('id', 'iupac_name', 'common_name', 'canonical_smile')
@admin.register(TestActivityDescription)
class TextActivityDescription(admin.ModelAdmin):
class TextActivityDescription(ViewOnSiteModelAdmin):
list_display = ('test_name', 'test_type', 'test_modulation_type')
@admin.register(Ppi)
class PpiModelAdmin(admin.ModelAdmin):
class PpiModelAdmin(ViewOnSiteModelAdmin):
filter_horizontal = ('diseases',)
list_display = ('pdb_id', 'name', 'symmetry', 'family')
list_filter = ('diseases',)
......@@ -76,7 +100,7 @@ class PpiModelAdmin(admin.ModelAdmin):
@admin.register(ProteinDomainComplex)
class ProteinDomainComplexAdmin(admin.ModelAdmin):
class ProteinDomainComplexAdmin(ViewOnSiteModelAdmin):
search_fields = ('id', 'protein__id', 'domain__id', 'protein__uniprot_id', 'domain__pfam_acc',)
list_display = ('id', '__str__', 'protein_uniprot_id', 'domain_pfam_acc',)
......@@ -95,7 +119,7 @@ class ProteinDomainComplexAdmin(admin.ModelAdmin):
for model in apps.get_app_config('ippidb').models.values():
try:
admin.site.register(model)
admin.site.register(model, ViewOnSiteModelAdmin)
except admin.sites.AlreadyRegistered as are:
continue
......
......@@ -145,6 +145,9 @@ class Bibliography(AutoFillableModel):
def __str__(self):
return '{}, {}'.format(self.source, self.id_source)
def get_absolute_url(self):
return reverse('biblio-view', kwargs={'biblio_pk': self.pk})
class Taxonomy(AutoFillableModel):
"""
......@@ -380,6 +383,9 @@ class Ppi(AutoFillableModel):
def __str__(self):
return 'PPI #{} on {}'.format(self.id, self.name)
def get_absolute_url(self):
return reverse('ppi-view', kwargs={'ppi_pk': self.pk})
def is_autofill_done(self):
return self.name != ""
......@@ -913,6 +919,9 @@ class Compound(AutoFillableModel):
def __str__(self):
return 'Compound #{}'.format(self.id)
def get_absolute_url(self):
return reverse('compound_card', kwargs={'pk': self.pk})
class CompoundTanimoto(models.Model):
canonical_smiles = models.TextField(
......
......@@ -22,12 +22,12 @@ urlpatterns = [
url(r'^contribute$', views.adminSession, name='admin-session'),
url(r'^contribute/add/(?P<step>.+)/$', ippidb_wizard, name='ippidb_step'),
url(r'^contribute/add/$', ippidb_wizard, name='admin-session-add'),
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}),
url(r'^contribute/view/(?P<biblio_pk>\d+)-(?P<ppi_pk>\d+)/$', views.admin_session_view, name='admin-session-view'),
url(r'^contribute/view/(?P<biblio_pk>\d+)-/$', views.admin_session_view, {'ppi_pk': None}, name='biblio-view'),
url(r'^contribute/view/-(?P<ppi_pk>\d+)/$', views.admin_session_view, {'biblio_pk': None}, name='ppi-view'),
url(r'^contribute/view/(?P<contribution_pk>\d+)/$',
views.admin_session_view,
{'ppi_pk': None, 'bibli_pk': None},
{'ppi_pk': None, 'biblio_pk': None},
name='contribution-detail',
),
url(r'^contribute/update/$', views.update, name='admin-session-update'),
......
......@@ -320,10 +320,10 @@ class IppiWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
# update its date of modification
contribution.save()
# super().done(form_list=form_list, **kwargs)
return admin_session_view(self.request, bibli_pk=None, ppi_pk=None, contribution_pk=contribution.pk)
return admin_session_view(self.request, biblio_pk=None, ppi_pk=None, contribution_pk=contribution.pk)
def admin_session_view(request, bibli_pk, ppi_pk, contribution_pk=None):
def admin_session_view(request, biblio_pk, ppi_pk, contribution_pk=None):
context = {}
if contribution_pk:
contribution = get_object_or_404(models.Contribution, pk=contribution_pk)
......@@ -334,8 +334,8 @@ def admin_session_view(request, bibli_pk, ppi_pk, contribution_pk=None):
bibliography = None
ppi = None
if bibli_pk:
bibliography = get_object_or_404(models.Bibliography, pk=bibli_pk)
if biblio_pk:
bibliography = get_object_or_404(models.Bibliography, pk=biblio_pk)
if bibliography:
context["bibliography"] = bibliography
context["testactivitydescription"] = bibliography.testactivitydescription_set.all()
......
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