Skip to content
Snippets Groups Projects
Commit 6947eae1 authored by Rachel TORCHET's avatar Rachel TORCHET
Browse files
Former-commit-id: ad324ebb221b815351ada88c5563a625791ec9c3
parents ddc1d460 3b5eb558
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,5 @@
/ippidb_backend/PrepareFingerPrints/nbproject/private/
/ippidb_backend/PrepareFingerPrints/build/
/ippidb_backend/PrepareFingerPrints/dist/
.DS_Store
\ No newline at end of file
.DS_Store
ippisite/db.sqlite3
\ No newline at end of file
067f156ca37c93920f1a15dac26337a9956fccbb
\ No newline at end of file
cbc5368d062b8764f1b0d652691f17cd132d699f
\ No newline at end of file
......@@ -39,8 +39,7 @@ class ProteinForm(ModelForm):
'entry_name' : forms.TextInput(attrs={'placeholder':'e.g KMT2A_HUMAN'}),
}
ProteinFormSet = modelformset_factory(Protein, exclude=('recommended_name_long', 'short_name'))
formset=ProteinFormSet()
ProteinFormSet = modelformset_factory(Protein, exclude=('recommended_name_long', 'short_name'), extra=0)
ARCHI_TYPE = (
......
......@@ -25,11 +25,13 @@
{% block custom_form %}{% endblock %}
{% if wizard.form.forms %}
{{ wizard.form.management_form }}
{{ formset.management_form }}
{% for form in wizard.form.forms %}
{{ form }}
{% endfor %}
{% else %}
{{ wizard.form.management_form }}
{{ formset.management_form }}
{% for form in formset %}
{% for field in form %}
......@@ -41,4 +43,4 @@
<input type="submit" value="{% trans "Next step" %}"/>
</form>
</div>
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect
from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView
from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet, PDBFormSet
from .models import Protein
from .models import Protein, Bibliography
from .ws import get_pdb_uniprot_mapping
def index(request):
......@@ -39,25 +39,36 @@ TEMPLATES = {"IdForm": "IdForm.html",
"ProteinDomainComplexForm": "ProteinDomainComplexForm.html",
"PpiForm": "PpiForm.html"}
class Ol(list):
ordered = True
class IppiWizard(NamedUrlSessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def get_form_instance(self, step):
if self.steps.current=='BibliographyForm':
pk = self.storage.get_step_data('IdForm').get('pk')
return Bibliography.objects.get(pk=pk)
if self.steps.current=='ProteinForm':
pks = self.storage.get_step_data('PDBForm').get('pks')
return Protein.objects.filter(id__in=pks)
def process_step(self, form):
"""
This method overrides the one used to postprocess the form data.
The added code just sets the form model for use in later forms
when appropriate
"""
data = super(IppiWizard, self).process_step(form).copy()
if self.steps.current=='IdForm':
form.instance.autofill()
self.instance_dict['BibliographyForm'] = form.instance
elif self.steps.current=='PDBForm':
uniprot_ids = get_pdb_uniprot_mapping(form.cleaned_data['pdb_id'])
proteins = []
if self.steps.current in ['IdForm', 'Bibliography']:
form.instance.save()
data['pk'] = form.instance.id
if self.steps.current=='PDBForm':
pdb_ids = [form['pdb_id'] for form in form.cleaned_data]
uniprot_ids = []
protein_ids = []
for pdb_id in pdb_ids:
uniprot_ids += get_pdb_uniprot_mapping(pdb_id)
for uniprot_id in uniprot_ids:
try:
p = Protein.objects.get(uniprot_id=uniprot_id)
......@@ -65,9 +76,10 @@ class IppiWizard(NamedUrlSessionWizardView):
p = Protein()
p.uniprot_id = uniprot_ids[0]
p.autofill()
proteins.append(p)
self.instance_dict['ProteinForm'] = Ol(proteins)
return self.get_form_step_data(form)
p.save()
protein_ids.append(p.id)
data['pks'] = protein_ids
return data
def done(self, form_list, **kwargs):
return render(self.request, '/admin-session/add.html', {
......
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