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
...@@ -5,3 +5,4 @@ ...@@ -5,3 +5,4 @@
/ippidb_backend/PrepareFingerPrints/build/ /ippidb_backend/PrepareFingerPrints/build/
/ippidb_backend/PrepareFingerPrints/dist/ /ippidb_backend/PrepareFingerPrints/dist/
.DS_Store .DS_Store
ippisite/db.sqlite3
\ No newline at end of file
067f156ca37c93920f1a15dac26337a9956fccbb cbc5368d062b8764f1b0d652691f17cd132d699f
\ No newline at end of file \ No newline at end of file
...@@ -39,8 +39,7 @@ class ProteinForm(ModelForm): ...@@ -39,8 +39,7 @@ class ProteinForm(ModelForm):
'entry_name' : forms.TextInput(attrs={'placeholder':'e.g KMT2A_HUMAN'}), 'entry_name' : forms.TextInput(attrs={'placeholder':'e.g KMT2A_HUMAN'}),
} }
ProteinFormSet = modelformset_factory(Protein, exclude=('recommended_name_long', 'short_name')) ProteinFormSet = modelformset_factory(Protein, exclude=('recommended_name_long', 'short_name'), extra=0)
formset=ProteinFormSet()
ARCHI_TYPE = ( ARCHI_TYPE = (
......
...@@ -25,11 +25,13 @@ ...@@ -25,11 +25,13 @@
{% block custom_form %}{% endblock %} {% block custom_form %}{% endblock %}
{% if wizard.form.forms %} {% if wizard.form.forms %}
{{ wizard.form.management_form }}
{{ formset.management_form }} {{ formset.management_form }}
{% for form in wizard.form.forms %} {% for form in wizard.form.forms %}
{{ form }} {{ form }}
{% endfor %} {% endfor %}
{% else %} {% else %}
{{ wizard.form.management_form }}
{{ formset.management_form }} {{ formset.management_form }}
{% for form in formset %} {% for form in formset %}
{% for field in form %} {% for field in form %}
......
...@@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect ...@@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect
from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView
from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet, PDBFormSet 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 from .ws import get_pdb_uniprot_mapping
def index(request): def index(request):
...@@ -39,25 +39,36 @@ TEMPLATES = {"IdForm": "IdForm.html", ...@@ -39,25 +39,36 @@ TEMPLATES = {"IdForm": "IdForm.html",
"ProteinDomainComplexForm": "ProteinDomainComplexForm.html", "ProteinDomainComplexForm": "ProteinDomainComplexForm.html",
"PpiForm": "PpiForm.html"} "PpiForm": "PpiForm.html"}
class Ol(list):
ordered = True
class IppiWizard(NamedUrlSessionWizardView): class IppiWizard(NamedUrlSessionWizardView):
def get_template_names(self): def get_template_names(self):
return [TEMPLATES[self.steps.current]] 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): def process_step(self, form):
""" """
This method overrides the one used to postprocess the form data. This method overrides the one used to postprocess the form data.
The added code just sets the form model for use in later forms The added code just sets the form model for use in later forms
when appropriate when appropriate
""" """
data = super(IppiWizard, self).process_step(form).copy()
if self.steps.current=='IdForm': if self.steps.current=='IdForm':
form.instance.autofill() form.instance.autofill()
self.instance_dict['BibliographyForm'] = form.instance if self.steps.current in ['IdForm', 'Bibliography']:
elif self.steps.current=='PDBForm': form.instance.save()
uniprot_ids = get_pdb_uniprot_mapping(form.cleaned_data['pdb_id']) data['pk'] = form.instance.id
proteins = [] 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: for uniprot_id in uniprot_ids:
try: try:
p = Protein.objects.get(uniprot_id=uniprot_id) p = Protein.objects.get(uniprot_id=uniprot_id)
...@@ -65,9 +76,10 @@ class IppiWizard(NamedUrlSessionWizardView): ...@@ -65,9 +76,10 @@ class IppiWizard(NamedUrlSessionWizardView):
p = Protein() p = Protein()
p.uniprot_id = uniprot_ids[0] p.uniprot_id = uniprot_ids[0]
p.autofill() p.autofill()
proteins.append(p) p.save()
self.instance_dict['ProteinForm'] = Ol(proteins) protein_ids.append(p.id)
return self.get_form_step_data(form) data['pks'] = protein_ids
return data
def done(self, form_list, **kwargs): def done(self, form_list, **kwargs):
return render(self.request, '/admin-session/add.html', { return render(self.request, '/admin-session/add.html', {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment