def save(self, *args, **kwargs): if not self.slug: self.slug = utils.slugify(self.title) if self.slug.startswith('special:'): self.is_published = True self.is_nsfw = False self.is_spoiler = False self.validate_unique() if self.is_published and not self.published: self.published = timezone.now() return super().save(*args, **kwargs)
def find_linked_article(self, namespace, page): from wiki.models import Article classes = ['.wikilink'] slug = utils.slugify(page) namespace = utils.slugify_namespace(namespace) try: article = Article.objects.get(is_published=True, slug=slug, namespace=namespace) href = article.get_absolute_url() title = article.title except Article.DoesNotExist: classes.append('.new') href = reverse('wiki', args=[namespace, slug]) title = '{page} (page does not exist)'.format(page=page) return href, title.replace('"', '"'), ' '.join(classes)
def get_initial(self): slug = self.kwargs['slug'] title = slug.replace('_', ' ').strip().title() if not self.kwargs['slug'].startswith('_'): slug = utils.slugify(title) initial = { 'title': title, 'slug': slug, 'namespace': self.kwargs['namespace'], 'is_published': True, } template = self._get_template() if template: initial['markdown'] = template return initial
def get_redirect(self, qs=None): m = self.REDIRECT_RE.match(self.markdown.strip()) if m is None: return None url = m.group('redirect') # Prepend current namespace if redirect URL is not absolute url = utils.join_path(self.namespace, url) # Get and slugify namespace and slug from URL namespace, slug = utils.split_path(url) slug = utils.slugify(slug) namespace = utils.slugify_namespace(namespace) if qs is None: qs = Article.objects.filter(is_published=True) return qs.get(namespace=namespace, slug=slug)
def save(self, *args, **kwargs): if not self.slug: self.slug = utils.slugify(self.name) return super().save(*args, **kwargs)
def anchor(self): return utils.slugify(self.term)
def clean(self): super().clean() if not self.slug: self.slug = utils.slugify(self.title)