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

experiment in trying to save Model objects as json for the wizard

Former-commit-id: b2181d605c00bb890226f2c4213d22f2498aa534
parent 24f2716d
No related branches found
No related tags found
No related merge requests found
067f156ca37c93920f1a15dac26337a9956fccbb
\ No newline at end of file
ea2455328a1ef5effe52858804d0c303950ec7cf
\ No newline at end of file
......@@ -2,10 +2,11 @@ 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
from .models import Protein, Bibliography, Taxonomy
from .ws import get_pdb_uniprot_mapping
def index(request):
......@@ -46,6 +47,19 @@ 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
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)
def process_step(self, form):
"""
This method overrides the one used to postprocess the form data.
......@@ -54,8 +68,8 @@ class IppiWizard(NamedUrlSessionWizardView):
"""
if self.steps.current=='IdForm':
form.instance.autofill()
self.instance_dict['BibliographyForm'] = form.instance
elif self.steps.current=='PDBForm':
return model_to_dict(form.instance)
if self.steps.current=='PDBForm':
uniprot_ids = get_pdb_uniprot_mapping(form.cleaned_data['pdb_id'])
proteins = []
for uniprot_id in uniprot_ids:
......@@ -66,7 +80,7 @@ class IppiWizard(NamedUrlSessionWizardView):
p.uniprot_id = uniprot_ids[0]
p.autofill()
proteins.append(p)
self.instance_dict['ProteinForm'] = Ol(proteins)
return {'set': [model_to_dict(p, exclude=['molecular_functions']) for p in proteins]}
return self.get_form_step_data(form)
def done(self, form_list, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment