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

Merge branch 'master' of gitlab.pasteur.fr:ippidb/ippidb-web

parents ff473682 084b140d
No related branches found
No related tags found
No related merge requests found
Pipeline #13828 passed
......@@ -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
......
......@@ -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(){
......
......@@ -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}}">
......
......@@ -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"
......
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