musician webapps filter create duplicate options
This commit is contained in:
parent
b896dd2262
commit
b911e0e89f
|
@ -231,6 +231,11 @@ class WebappOptionForm(forms.ModelForm):
|
||||||
target = 'this.id.replace("name", "value")'
|
target = 'this.id.replace("name", "value")'
|
||||||
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
|
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
|
||||||
|
|
||||||
|
|
||||||
|
class WebappOptionCreateForm(WebappOptionForm):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
plugin = AppType.get(self.webapp.type)
|
plugin = AppType.get(self.webapp.type)
|
||||||
choices = list(plugin.get_group_options_choices())
|
choices = list(plugin.get_group_options_choices())
|
||||||
for grupo, opciones in enumerate(choices):
|
for grupo, opciones in enumerate(choices):
|
||||||
|
@ -239,9 +244,6 @@ class WebappOptionForm(forms.ModelForm):
|
||||||
choices[grupo] = (opciones[0], nueva_lista)
|
choices[grupo] = (opciones[0], nueva_lista)
|
||||||
self.fields['name'].widget.choices = choices
|
self.fields['name'].widget.choices = choices
|
||||||
|
|
||||||
|
|
||||||
class WebappOptionCreateForm(WebappOptionForm):
|
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
instance = super().save(commit=False)
|
instance = super().save(commit=False)
|
||||||
instance.webapp = self.webapp
|
instance.webapp = self.webapp
|
||||||
|
@ -249,7 +251,20 @@ class WebappOptionCreateForm(WebappOptionForm):
|
||||||
super().save(commit=True)
|
super().save(commit=True)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
name = self.cleaned_data.get("name")
|
||||||
|
if WebAppOption.objects.filter(webapp=self.webapp, name=name).exists():
|
||||||
|
raise ValidationError(_("This option already exist."))
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
class WebappOptionUpdateForm(WebappOptionForm):
|
class WebappOptionUpdateForm(WebappOptionForm):
|
||||||
pass
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['name'].widget.choices = [(self.initial['name'], self.initial['name'])]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue