Skip to content
Snippets Groups Projects
Commit c537ae6f authored by Rachel TORCHET's avatar Rachel TORCHET
Browse files

Update views.py

Former-commit-id: f4067dda556067ae1ac78af600b05263ce9f9030
parent bf6e8f72
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,46 @@ class IppiWizard(NamedUrlSessionWizardView): ...@@ -89,7 +89,46 @@ class IppiWizard(NamedUrlSessionWizardView):
initial['pdb_id'] = self.storage.get_step_data('PDBForm').get('PDBForm-pdb_id') initial['pdb_id'] = self.storage.get_step_data('PDBForm').get('PDBForm-pdb_id')
return self.initial_dict.get(step, initial) return self.initial_dict.get(step, initial)
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 == 'Bibliography':
form.instance.autofill()
if self.steps.current == '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)
except Protein.DoesNotExist:
p = Protein()
p.uniprot_id = uniprot_ids[0]
p.autofill()
p.save()
protein_ids.append(p.id)
data['pks'] = protein_ids
return data
def get_form_instance(self, step):
if self.steps.current == 'PDBForm':
pk = self.storage.get_step_data('BibliographyForm').get('pk')
return Bibliography.objects.get(pk=pk)
if self.steps.current == 'ProteinForm':
pks = self.storage.get_step_data('PDBForm').get('pks')
print(Protein.objects.filter(id__in=pks))
return Protein.objects.filter(id__in=pks)
def get_template_names(self): def get_template_names(self):
return [TEMPLATES[self.steps.current]] return [TEMPLATES[self.steps.current]]
......
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