diff --git a/ippisite/ippidb/forms.py b/ippisite/ippidb/forms.py index 5f8a1955891cd8aaadf3d5cfc09fd21454af9468..8c4bfb5b50b354b2e7ae5775248d7bb00268c0c3 100644 --- a/ippisite/ippidb/forms.py +++ b/ippisite/ippidb/forms.py @@ -10,7 +10,7 @@ from .models import * from .ws import pdb_entry_exists """ Step 1 : IdForm """ -class IdForm(ModelForm): +class IdFormOld(ModelForm): class Meta: model = Bibliography fields = ['source','id_source'] @@ -22,6 +22,38 @@ class IdForm(ModelForm): 'id_source': forms.TextInput(), } + +class IdForm(forms.Form): + source = forms.ChoiceField( + label='Bibliographic type', + choices=Bibliography.SOURCES, + initial='PM', + widget=forms.RadioSelect, + ) + id_source = forms.CharField( + label='Bibliographic ID', + max_length=25, + ) + + def clean(self): + ret = super().clean() + Bibliography.validate_source_id(ret["id_source"], ret["source"]) + return ret + + def get_or_create(self): + kwargs = dict(source=self.cleaned_data["source"], + id_source=self.cleaned_data["id_source"], + ) + try: + b = Bibliography.objects.get(**kwargs) + return b, False + except Bibliography.DoesNotExist: + pass + b = Bibliography(**kwargs) + b.save(autofill=True) + return b, True + + """ Step 2 : BibliographyForm """ class BibliographyForm(ModelForm): class Meta: diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index a9f2af14649167c46e83d1cfbebfaf9f6faf5f76..cc9ff3bb641faedc560520c753b17ed6be675e4c 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -85,13 +85,25 @@ class Bibliography(AutoFillableModel): def clean(self): super().clean() - id_source_validator = self.id_source_validators[self.source] - if not id_source_validator.match(self.id_source): + Bibliography.validate_source_id(self.id_source, self.source) + + def has_external_url(self): + return self.source == 'PM' + + def get_external_url(self): + if self.source == 'PM': + return "https://www.ncbi.nlm.nih.gov/pubmed/" + str(self.id_source) + + @staticmethod + def validate_source_id(id_source, source): + id_source_validator = Bibliography.id_source_validators[source] + if not id_source_validator.match(id_source): raise ValidationError( dict( id_source=_("Must match pattern %s for this selected source" % id_source_validator.pattern) ) ) + return True class Meta: verbose_name_plural = "bibliographies" diff --git a/ippisite/ippidb/templates/BibliographyForm.html b/ippisite/ippidb/templates/BibliographyForm.html index 1077635623fa7796a4aef2d7a74480c58f54749e..5bab7e289b159b03c8463b84b88e266f354df914 100644 --- a/ippisite/ippidb/templates/BibliographyForm.html +++ b/ippisite/ippidb/templates/BibliographyForm.html @@ -1,72 +1,53 @@ {% extends "add.html" %} {% load i18n %} +{% load customtags %} {% block form %} <div id="Form"> - <div class="step_desc"> - <h1 class="step_title">Bibliography informations</h1> - <p class="step_step">Step {{ wizard.steps.step1 }} on {{ wizard.steps.count }}</p> - <p class="step_step_desc"> According to the ID you gave, here are the informations that we collect. Could you complete informations contained in it. </p> - </div> - <div class="form_div"> - <form action="" method="post"> - {% csrf_token %} - <table> - {{ wizard.management_form }} - {{ wizard.form.errors}} - {{ wizard.form.non_field_errors}} - {% block custom_form %}{% endblock %} - - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {{ form }} - {% endfor %} - {% else %} - <div class="publi_title"> - {% if source == "PM" %} - Publication on PubMed - PMID {{ wizard.form.id_source.value }}<br/> - <a target="_blank" href="https://www.ncbi.nlm.nih.gov/pubmed/{{ wizard.form.id_source.value }}"><b>{{ wizard.form.title.value }}</b><br/> - <i>{{ wizard.form.authors_list.value }}</i><br/> - {{ wizard.form.journal_name.value }}<br/></a> - {% endif %} - </div> - <div class="hidden"> - {{ wizard.form.source }} - {{ wizard.form.id_source }} - {{ wizard.form.title }} - {{ wizard.form.authors_list }} - {{ wizard.form.journal_name }} - </div> - <p> This publication contains :<br/></p> - <div > - <label> - <input type="checkbox"><span>{{ wizard.form.cytotox.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.in_silico.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.in_vitro.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.in_vivo.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.in_cellulo.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.pharmacokinetic.label }}</span> - </label> - <label> - <input type="checkbox"><span>{{ wizard.form.xray.label }}</span> - </label> - </div> - </div> - {% endif %} - </table> - <input class="submit_button" type="submit" value="{% trans "Next step" %}"/> - </form> - </div> + <div class="step_desc"> + <h1 class="step_title">Bibliography informations</h1> + <p class="step_step">Step {{ wizard.steps.step1 }} on {{ wizard.steps.count }}</p> + <p class="step_step_desc"> According to the ID you gave, here are the informations that we collect. Could you + complete informations contained in it. </p> + </div> + <div class="form_div"> + <form action="" method="post"> + {% csrf_token %} + {{ wizard.management_form }} + {{ wizard.form.errors}} + {{ wizard.form.non_field_errors}} + {% block custom_form %}{% endblock %} + <div class="publi_title"> + {{wizard.form.instance.get_source_display}} {{wizard.form.instance.id_source}}<br/> + <a target="_blank" + {% if wizard.form.instance.has_external_url %} + href="{{ wizard.form.instance.get_external_url }}" + {% endif %}><b> + {{wizard.form.title.value }}</b><br/> + <i>{{ wizard.form.authors_list.value }}</i><br/> + {{ wizard.form.journal_name.value }}<br/> + </a> + </div> + <div class="hidden"> + {{ wizard.form.source }} + {{ wizard.form.id_source }} + {{ wizard.form.title }} + {{ wizard.form.authors_list }} + {{ wizard.form.journal_name }} + </div> + <p> This publication contains :<br/></p> + <div> + {{ wizard.form.cytotox|bootstrap }} + {{ wizard.form.in_silico|bootstrap }} + {{ wizard.form.in_vitro|bootstrap }} + {{ wizard.form.in_vivo|bootstrap }} + {{ wizard.form.in_cellulo|bootstrap }} + {{ wizard.form.pharmacokinetic|bootstrap }} + {{ wizard.form.xray|bootstrap }} + </div> + </div> + <input class="submit_button" type="submit" value="{% trans " Next step" %}"/> + </form> +</div> </div> {% endblock %} \ No newline at end of file diff --git a/ippisite/ippidb/views/contribute.py b/ippisite/ippidb/views/contribute.py index 25fc44b1f5045dc47348fcfdfc28fb2e0956a58e..2a67a2896037ddf074c9e91be8923c85ccdd9344 100644 --- a/ippisite/ippidb/views/contribute.py +++ b/ippisite/ippidb/views/contribute.py @@ -75,10 +75,11 @@ class IppiWizard(LoginRequiredMixin, NamedUrlSessionWizardView): """ data = super(IppiWizard, self).process_step(form).copy() if self.steps.current == 'IdForm': - form.instance.autofill() - if self.steps.current in ['IdForm', 'Bibliography']: - form.instance.save() - data['pk'] = form.instance.id + b, created = form.get_or_create() + data['IdForm-id'] = b.id + # if self.steps.current in ['IdForm', 'Bibliography']: + # form.get_or_create() + # data['pk'] = b.id if self.steps.current == 'PDBForm': pdb_id = form.cleaned_data['pdb_id'] uniprot_ids = [] @@ -99,8 +100,8 @@ class IppiWizard(LoginRequiredMixin, NamedUrlSessionWizardView): def get_form_instance(self, step): # Works only for Modelform if self.steps.current == 'BibliographyForm': - pk = self.storage.get_step_data('IdForm').get('pk') - return Bibliography.objects.get(pk=pk) + pk = self.storage.get_step_data('IdForm').get('IdForm-id') + return models.Bibliography.objects.get(pk=pk) if self.steps.current == 'ProteinDomainComplexTypeForm': print("blablabla", self.storage.get_step_data('PDBForm').get('pks')) pks = self.storage.get_step_data('PDBForm').get('pks')