Esempio n. 1
0
    def form_valid(self, form):
        """
        Store new flatpage from form data. Checks wether a site
        is specified for the flatpage or sets the current site by
        default. Additionally, if URL is left blank, a slugified
        version of the title will be used as URL after checking
        if it is valid.
        """
        # if no URL is specified, generate from title
        page = form.save(commit=False)

        if not page.url:
            page.url = '/%s/' % slugify(page.title)

        try:
            URLDoesNotExistValidator()(page.url)
        except ValidationError:
            pass
        else:
            # use current site as default for new page
            page.save()
            page.sites.add(Site.objects.get_current())

            return HttpResponseRedirect(self.get_success_url(page))

        ctx = self.get_context_data()
        ctx['form'] = form
        return self.render_to_response(ctx)
Esempio n. 2
0
    def save(self, update_slugs=True, *args, **kwargs):
        if update_slugs:
            parent = self.get_parent()
            slug = slugify(self.name)
            # If category has a parent, includes the parents slug in this one
            if parent:
                self.slug = '%s%s%s' % (
                    parent.slug, self._slug_separator, slug)
                self.full_name = '%s%s%s' % (
                    parent.full_name, self._full_name_separator, self.name)
            else:
                self.slug = slug
                self.full_name = self.name

        # Enforce slug uniqueness here as MySQL can't handle a unique index on
        # the slug field
        try:
            match = self.__class__.objects.get(slug=self.slug)
        except self.__class__.DoesNotExist:
            pass
        else:
            if match.id != self.id:
                raise ValidationError(
                    _("A category with slug '%(slug)s' already exists") % {
                        'slug': self.slug})

        super(AbstractCategory, self).save(*args, **kwargs)
Esempio n. 3
0
    def save(self, *args, **kwargs):
        if self.is_top_level and not self.title:
            raise ValidationError(_("Canonical products must have a title"))
        if not self.slug:
            self.slug = slugify(self.get_title())

        # Validate attributes if necessary
        self.attr.validate_attributes()

        # Save product
        super(AbstractProduct, self).save(*args, **kwargs)

        # Finally, save attributes
        self.attr.save()
Esempio n. 4
0
    def is_slug_conflicting(self, name, ref_node_pk, position):
        # determine parent
        if ref_node_pk:
            ref_category = Category.objects.get(pk=ref_node_pk)
            if position == "first-child":
                parent = ref_category
            else:
                parent = ref_category.get_parent()
        else:
            parent = None

        # build full slug
        slug_prefix = (parent.slug + Category._slug_separator) if parent else ""
        slug = "%s%s" % (slug_prefix, slugify(name))

        # check if slug is conflicting
        try:
            category = Category.objects.get(slug=slug)
        except Category.DoesNotExist:
            pass
        else:
            if category.pk != self.instance.pk:
                return True
        return False
Esempio n. 5
0
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(AbstractOption, self).save(*args, **kwargs)
Esempio n. 6
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     super(AbstractAttributeEntityType, self).save(*args, **kwargs)
Esempio n. 7
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     return super(AbstractProductClass, self).save(*args, **kwargs)
Esempio n. 8
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     super(AbstractContributor, self).save(*args, **kwargs)
Esempio n. 9
0
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(ShippingMethod, self).save(*args, **kwargs)