def validate_unique_slug(self, cleaned_data): """ Test whether the slug is unique within a given time period. """ kwargs = {} error_msg = _("The slug is not unique") # The /year/month/slug/ URL determines when a slug can be unique. pubdate = cleaned_data['publication_date'] or now() if '{year}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: kwargs['year'] = pubdate.year error_msg = _("The slug is not unique within it's publication year.") if '{month}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: kwargs['month'] = pubdate.month error_msg = _("The slug is not unique within it's publication month.") if '{day}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: kwargs['day'] = pubdate.day error_msg = _("The slug is not unique within it's publication day.") date_range = get_date_range(**kwargs) if date_range: dup_qs = EntryModel.objects.filter(slug=cleaned_data['slug'], publication_date__range=date_range) else: dup_qs = EntryModel.objects.filter(slug=cleaned_data['slug']) if self.instance and self.instance.pk: dup_qs = dup_qs.exclude(pk=self.instance.pk) # Test whether the slug is unique in the current month # Note: doesn't take changes to FLUENT_BLOGS_ENTRY_LINK_STYLE into account. if dup_qs.exists(): raise ValidationError(error_msg)
def validate_unique_slug(self, cleaned_data): """ Test whether the slug is unique within a given time period. """ date_kwargs = {} error_msg = _("The slug is not unique") # The /year/month/slug/ URL determines when a slug can be unique. pubdate = cleaned_data['publication_date'] or now() if '{year}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: date_kwargs['year'] = pubdate.year error_msg = _("The slug is not unique within it's publication year.") if '{month}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: date_kwargs['month'] = pubdate.month error_msg = _("The slug is not unique within it's publication month.") if '{day}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE: date_kwargs['day'] = pubdate.day error_msg = _("The slug is not unique within it's publication day.") date_range = get_date_range(**date_kwargs) # Base filters are configurable for translation support. dup_filters = self.get_unique_slug_filters(cleaned_data) if date_range: dup_filters['publication_date__range'] = date_range dup_qs = EntryModel.objects.filter(**dup_filters) if self.instance and self.instance.pk: dup_qs = dup_qs.exclude(pk=self.instance.pk) # Test whether the slug is unique in the current month # Note: doesn't take changes to FLUENT_BLOGS_ENTRY_LINK_STYLE into account. if dup_qs.exists(): raise ValidationError(error_msg)
def get_queryset(self): qs = super(BaseDetailMixin, self).get_queryset() # Allow same slug in different dates # The available arguments depend on the FLUENT_BLOGS_ENTRY_LINK_STYLE setting. year = int(self.kwargs['year']) if 'year' in self.kwargs else None month = int(self.kwargs['month']) if 'month' in self.kwargs else None day = int(self.kwargs['day']) if 'day' in self.kwargs else None range = get_date_range(year, month, day) if range: qs = qs.filter(publication_date__range=range) return qs
def get_queryset(self): # The DetailView redefines get_queryset() to show detail pages for staff members. # All other overviews won't show the draft pages yet. qs = get_entry_model().objects.published(for_user=self.request.user) if self.prefetch_translations: qs = qs.prefetch_related('translations') # Allow same slug in different dates # The available arguments depend on the FLUENT_BLOGS_ENTRY_LINK_STYLE setting. year = int(self.kwargs['year']) if 'year' in self.kwargs else None month = int(self.kwargs['month']) if 'month' in self.kwargs else None day = int(self.kwargs['day']) if 'day' in self.kwargs else None range = get_date_range(year, month, day) if range: qs = qs.filter(publication_date__range=range) return qs
def get_queryset(self): # The DetailView redefines get_queryset() to show detail pages for staff members. # All other overviews won't show the draft pages yet. qs = get_entry_model().objects.published(for_user=self.request.user) if self.prefetch_translations: qs = qs.prefetch_related("translations") # Allow same slug in different dates # The available arguments depend on the FLUENT_BLOGS_ENTRY_LINK_STYLE setting. year = int(self.kwargs["year"]) if "year" in self.kwargs else None month = int(self.kwargs["month"]) if "month" in self.kwargs else None day = int(self.kwargs["day"]) if "day" in self.kwargs else None range = get_date_range(year, month, day) if range: qs = qs.filter(publication_date__range=range) return qs