diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index 668943c08f314eac660abcc7c4828ef9520ef766..b4d4983be675b8f375239747575f3eb5416eebaa 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -89,7 +89,46 @@ class IppiWizard(NamedUrlSessionWizardView): initial['pdb_id'] = self.storage.get_step_data('PDBForm').get('PDBForm-pdb_id') 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): return [TEMPLATES[self.steps.current]]