diff --git a/vcweb/core/forms.py b/vcweb/core/forms.py index 48ccfdf2..e387fc80 100644 --- a/vcweb/core/forms.py +++ b/vcweb/core/forms.py @@ -239,22 +239,38 @@ class Meta: class ExperimentParameterValueForm(forms.ModelForm): required_css_class = 'required' - def __init__(self, *args, **kwargs): - super(ExperimentParameterValueForm, self).__init__(*args, **kwargs) - self.fields['parameter'].queryset = self.fields[ - 'parameter'].queryset.filter(scope='experiment') + def __init__(self, post_dict=None, instance=None, pk=None, **kwargs): + if instance is None and pk is not None and pk != '-1': + instance = ExperimentParameterValue.objects.get(pk=pk) + super(ExperimentParameterValueForm, self).__init__(post_dict, instance=instance, **kwargs) + + self.fields['parameter'].queryset = self.fields['parameter'].queryset.filter(scope='experiment') for name, field in self.fields.items(): - if field.widget.__class__ == CheckboxInput: + if isinstance(field.widget, CheckboxInput): field.widget.attrs['data-bind'] = 'checked: %s' % name else: field.widget.attrs['data-bind'] = 'value: %s' % name + if post_dict: + self.request_type = post_dict.get('request_type') + + def save(self, commit=True): + epv = super(ExperimentParameterValueForm, self).save(commit=False) + if self.request_type == 'delete': + logger.warn("Deleting round parameter value %s", epv) + epv.delete() + elif commit: + epv.save() + return epv + + class Meta: model = ExperimentParameterValue - exclude = ('experiment_configuration', 'last_modified', 'date_created') + exclude = ('last_modified', 'date_created') widgets = { 'string_value': forms.Textarea(attrs={'cols': 40, 'rows': 3}), + 'experiment_configuration': forms.HiddenInput } diff --git a/vcweb/core/templates/experimenter/edit-configuration.html b/vcweb/core/templates/experimenter/edit-configuration.html index e5b76445..c2e3e78d 100644 --- a/vcweb/core/templates/experimenter/edit-configuration.html +++ b/vcweb/core/templates/experimenter/edit-configuration.html @@ -203,7 +203,7 @@