musician website directives clear

This commit is contained in:
Jorge Pastor 2024-05-23 21:46:45 +02:00
parent 475df0a2e5
commit 0dc4352432
3 changed files with 19 additions and 21 deletions

View File

@ -93,26 +93,24 @@ class WesiteDirectiveCreateForm(forms.ModelForm):
# def clean(self): def clean(self):
# TODO: comprovar que la ruta no exista # Recoge todos los paths de directive y contents
# locations = set() locations = set()
# for form in self.content_formset.forms: for content in Content.objects.filter(website=self.website):
# location = form.cleaned_data.get('path') location = content.path
# delete = form.cleaned_data.get('DELETE') if location is not None:
# if not delete and location is not None: locations.add(location)
# locations.add(normurlpath(location)) for directive_obj in WebsiteDirective.objects.filter(website=self.website):
location = directive_obj.value
# values = defaultdict(list) if location is not None:
# for form in self.forms: locations.add(normurlpath(location.split()[0]))
# wdirective = form.instance # Comprueva que no se repitan
# directive = form.cleaned_data directive = self.cleaned_data
# if directive.get('name') is not None: value = normurlpath(directive.get('value'))
# try: if value:
# wdirective.directive_instance.validate_uniqueness(directive, values, locations) value = value.split()[0]
# except ValidationError as err: if value in locations:
# for k,v in err.error_dict.items(): self.add_error('value', f"Location '{value}' already in use by other content/directive.")
# form.add_error(k, v)
def save(self, commit=True): def save(self, commit=True):
instance = super().save(commit=False) instance = super().save(commit=False)

View File

@ -133,7 +133,6 @@ class WebsiteAddDirectiveView(CustomContextMixin, UserTokenRequiredMixin, Create
kwargs = super().get_form_kwargs() kwargs = super().get_form_kwargs()
website = get_object_or_404(Website, account=self.request.user, pk=self.kwargs["pk"]) website = get_object_or_404(Website, account=self.request.user, pk=self.kwargs["pk"])
kwargs['website'] = website kwargs['website'] = website
# kwargs["user"] = self.request.user
return kwargs return kwargs
def get_success_url(self): def get_success_url(self):

View File

@ -4,6 +4,7 @@ from functools import lru_cache
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.encoding import force_str
from orchestra import plugins from orchestra import plugins
from orchestra.utils.python import import_class from orchestra.utils.python import import_class