diff --git a/ippisite/ippidb/forms.py b/ippisite/ippidb/forms.py index f5e944e3ace8399c7e9fc038e9c80810fdc3c3aa..dba54e33fcce800c27b8f1acedbdcad0c3498507 100644 --- a/ippisite/ippidb/forms.py +++ b/ippisite/ippidb/forms.py @@ -269,7 +269,10 @@ class ComplexCompositionForm(forms.Form): ppp_copy_nb_per_p = forms.IntegerField( label=_('ppp_copy_nb_per_p'), required=False, - widget=forms.NumberInput(attrs={'class': 'bound-complex-only'}), + widget=forms.NumberInput(attrs={ + 'class': 'bound-complex-only', + 'data-required': True, + }), validators=[ MinValueValidator(1), ], @@ -451,6 +454,8 @@ class CompoundBaseFormSet(forms.BaseFormSet): return compound_names = set() common_names = set() + smiles_set = set() + iupac_set = set() for form in self.forms: if form.cleaned_data.get("DELETE", False): continue @@ -469,6 +474,24 @@ class CompoundBaseFormSet(forms.BaseFormSet): ) common_names.add(common_name) + smiles = form.cleaned_data['molecule_smiles'] + if len(smiles)>0 : + if smiles in smiles_set: + raise forms.ValidationError( + _("Compound must have distinct smiles. Incriminated value:'%s'") % + smiles + ) + smiles_set.add(smiles) + + iupac = form.cleaned_data['molecule_iupac'] + if len(iupac)>0 : + if iupac in iupac_set: + raise forms.ValidationError( + _("Compound must have distinct iupac. Incriminated value:'%s'") % + iupac + ) + iupac_set.add(iupac) + def __init__(self, show_is_a_ligand=False, *args, **kwargs): super().__init__(*args, **kwargs) self.show_is_a_ligand = show_is_a_ligand @@ -613,6 +636,12 @@ class CompoundActivityResultBaseInlineNestedFormSet(BaseInlineNestedFormSet): super().add_fields(form, index) form.fields["compound_name"].choices = self.__compound_names + def set_modulation_type(self, modulation_type): + for form in self.forms: + form.fields["modulation_type"].choices = [ + (key, msg) for key, msg in form.fields["modulation_type"].choices if key == modulation_type + ] + def set_compound_names(self, compound_names): """ Set the choices of the field compound_name to the compound_names provided @@ -690,6 +719,7 @@ class TestActivityDescriptionForm(forms.ModelForm): queryset=Protein.objects.none(), label=_("protein_domain_bound_complex_label"), help_text=_("protein_domain_bound_complex_help_text"), + required=True, ) class Meta: @@ -747,6 +777,10 @@ class TestActivityDescriptionBaseModelFormSet(BaseInlineNestedFormSet): __compound_names = None __protein_subset_ids = None + def __init__(self, modulation_type=None, *args, **kwargs): + super().__init__(*args, **kwargs) + self.__modulation_type = modulation_type + def add_fields(self, form, index): super().add_fields(form, index) form.nested = CompoundActivityResultInlineFormset( @@ -760,7 +794,10 @@ class TestActivityDescriptionBaseModelFormSet(BaseInlineNestedFormSet): queryset=CompoundActivityResult.objects.none() ) form.nested.set_compound_names(self.__compound_names) + form.nested.set_modulation_type(self.__modulation_type) form.fields["protein_complex"].queryset = Protein.objects.filter(id__in=self.__protein_subset_ids) + if Protein.objects.filter(id__in=self.__protein_subset_ids).count() == 1: + form.fields["protein_complex"].initial = Protein.objects.filter(id__in=self.__protein_subset_ids).first() def set_compound_names(self, compound_names): """ @@ -936,6 +973,10 @@ class TestCytotoxDescriptionForm(forms.ModelForm): 'biblio', ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["compound_concentration"].required = True + def has_changed(self): """ Test if the form has changed, we consider that it has not changed if it is not linked to an actual instance and @@ -1138,6 +1179,11 @@ class TestPKDescriptionForm(forms.ModelForm): 'biblio', ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + for f in ['administration_mode', 'concentration', 'dose', 'dose_interval', ]: + self.fields[f].required = True + def has_changed(self): """ Test if the form has changed, we consider that it has not changed if it is not linked to an actual instance and diff --git a/ippisite/ippidb/templates/ProteinDomainComplexForm.html b/ippisite/ippidb/templates/ProteinDomainComplexForm.html index 65ff55eeb1e0e416c21f60cc63f3b5bb8ad740f0..7dd078682124d2f0e582a05576ddc531486f9780 100644 --- a/ippisite/ippidb/templates/ProteinDomainComplexForm.html +++ b/ippisite/ippidb/templates/ProteinDomainComplexForm.html @@ -10,14 +10,15 @@ function update_partner_bound_fields_visibility(){ console.log($(source).val()); let partner = $(source).val() == "Partner"; if(partner){ - console.log(partner); $(source).closest(".formset-item").find(".partner-complex-only").parent().show(); + $(source).closest(".formset-item").find(".partner-complex-only[data-required]").prop("required",true); $(source).closest(".formset-item").find(".bound-complex-only").parent().hide(); - console.log("test:",$(source).closest(".formset-item").parent().find(".complex-type").val()); + $(source).closest(".formset-item").find(".bound-complex-only[data-required]").prop("required",false); }else{ $(source).closest(".formset-item").find(".partner-complex-only").parent().hide(); + $(source).closest(".formset-item").find(".partner-complex-only[data-required]").prop("required",false); $(source).closest(".formset-item").find(".bound-complex-only").parent().show(); - console.log("test2:",$(source).closest(".formset-item").parent().find(".complex-type").val()); + $(source).closest(".formset-item").find(".bound-complex-only[data-required]").prop("required",true); } } $(document).ready(function(){ diff --git a/ippisite/ippidb/templates/compound_form_content.html b/ippisite/ippidb/templates/compound_form_content.html index 5195a590b365b4ed8b59863995b2d4f1d9f510e8..93f302864d3fe3c47b14c7ba1e30bdd0f01c7f2e 100644 --- a/ippisite/ippidb/templates/compound_form_content.html +++ b/ippisite/ippidb/templates/compound_form_content.html @@ -14,7 +14,7 @@ <div class="input-group mb-3"> <input type="text" name="{{form.common_name.html_name}}" - value="{{form.common_name.value}}" + {%if form.common_name.value %}value="{{form.common_name.value}}"{%endif%} maxlength="{{form.fields.common_name.max_length}}" class=" form-control" id="{{form.common_name.id_for_label}}"> diff --git a/ippisite/ippidb/views/contribute.py b/ippisite/ippidb/views/contribute.py index bf966cfc77cd7c18e3770aa4b29c59fde7823513..2d5555a3496f37380c5717dc100f7a4e26fb2e65 100644 --- a/ippisite/ippidb/views/contribute.py +++ b/ippisite/ippidb/views/contribute.py @@ -154,6 +154,12 @@ class IppiWizard(LoginRequiredMixin, NamedUrlSessionWizardView): kwargs['form_kwargs'] = {'protein_ids': protein_ids} elif step == 'ActivityDescriptionFormSet': kwargs['queryset'] = models.TestActivityDescription.objects.none() + if self.storage.get_step_data('ProteinDomainComplexTypeForm') \ + .get('ProteinDomainComplexTypeForm-complexChoice', "") == "inhibited": + kwargs['modulation_type'] = "I" + elif self.storage.get_step_data('ProteinDomainComplexTypeForm') \ + .get('ProteinDomainComplexTypeForm-complexChoice', "") == "stabilized": + kwargs['modulation_type'] = "S" elif step == 'CompoundForm': kwargs['show_is_a_ligand'] = self.storage.get_step_data('BibliographyForm') \ .get('BibliographyForm-xray', "") == "on"