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

improving two first step of the wizard (re-using object, loading its value)

parent a4bbe512
......@@ -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:
......
......@@ -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"
......
{% 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
......@@ -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')
......
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