Skip to content
Snippets Groups Projects
Commit fa14d5d8 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

save objects in Wizard steps to escape storage hell.

Former-commit-id: 7f39a04b19e82c358a9cf5d3bb7a1f3aeacf22b3
parent 9d86faa8
No related branches found
No related tags found
No related merge requests found
ea2455328a1ef5effe52858804d0c303950ec7cf
\ No newline at end of file
cbc5368d062b8764f1b0d652691f17cd132d699f
\ No newline at end of file
......@@ -2,11 +2,10 @@ import ippidb
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.forms.models import model_to_dict
from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView
from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet
from .models import Protein, Bibliography, Taxonomy
from .models import Protein, Bibliography
from .ws import get_pdb_uniprot_mapping
def index(request):
......@@ -40,25 +39,17 @@ 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':
data = self.storage.get_step_data('IdForm')
obj = Bibliography(**data)
return obj
pk = self.storage.get_step_data('IdForm').get('pk')
return Bibliography.objects.get(pk=pk)
if self.steps.current=='ProteinForm':
data = self.storage.get_step_data('PDBForm').getlist('set')
proteins = []
for data_item in data:
data_item['organism'] = Taxonomy.objects.get(pk=data_item['organism'])
proteins.append(Protein(**data_item))
return Ol(proteins)
pks = self.storage.get_step_data('PDBForm').get('pks')
return Protein.objects.filter(id__in=pks)
def process_step(self, form):
"""
......@@ -66,22 +57,25 @@ class IppiWizard(NamedUrlSessionWizardView):
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()
return model_to_dict(form.instance)
if self.steps.current in ['IdForm', 'Bibliography']:
form.instance.save()
data['pk'] = form.instance.id
if self.steps.current=='PDBForm':
uniprot_ids = get_pdb_uniprot_mapping(form.cleaned_data['pdb_id'])
proteins = []
protein_ids = []
for uniprot_id in uniprot_ids:
try:
p = Protein.objects.get(uniprot_id=uniprot_id)
except Protein.DoesNotExist:
p = Protein()
p.uniprot_id = uniprot_ids[0]
p.autofill()
proteins.append(p)
return {'set': [model_to_dict(p, exclude=['molecular_functions']) for p in 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