Skip to content

Commit

Permalink
Improved slugification of titles
Browse files Browse the repository at this point in the history
When a title contains an 'ø' or an 'æ', they seem to be left out when the title is slugified. I now fixed this by replacing 'ø' with 'o' and 'æ' with 'ae' before slugifying the title
  • Loading branch information
Gunvor4 committed Nov 2, 2023
1 parent 1dd7eb4 commit 972bf22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/internal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ def __str__(self):
return _("{title}").format(title=self.title)

Check warning on line 339 in src/internal/models.py

View check run for this annotation

Codecov / codecov/patch

src/internal/models.py#L339

Added line #L339 was not covered by tests

def save(self, *args, **kwargs):
self.slug = slugify(self.title)
title = self.title
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
self.slug = slugify(title)
super().save(*args, **kwargs)

Check warning on line 346 in src/internal/models.py

View check run for this annotation

Codecov / codecov/patch

src/internal/models.py#L342-L346

Added lines #L342 - L346 were not covered by tests

class Meta:
verbose_name_plural = 'Lore articles'

21 changes: 16 additions & 5 deletions src/internal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,23 @@ class LoreCreateView(PermissionRequiredMixin, LoreFormMixin, CreateView):

def form_valid(self, form):
title = form.cleaned_data['title']
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
slug = slugify(title)
if Lore.objects.filter(slug=slug).exists():
form.add_error('title', _("An article with this title already exists. Please merge your text with the existing one!"))
return self.form_invalid(form)
elif slugify(title) == '':
elif slug == '':
form.add_error('title', _("Make a title consisting of actual letters, idiot! Thank you :-)"))
return self.form_invalid(form)

Check warning on line 385 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L376-L385

Added lines #L376 - L385 were not covered by tests
else:
return super().form_valid(form)

Check warning on line 387 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L387

Added line #L387 was not covered by tests

def get_success_url(self):
slug = slugify(self.object)
title = str(self.object)
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
slug = slugify(title)
return reverse_lazy('lore_article', args=[slug])

Check warning on line 394 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L390-L394

Added lines #L390 - L394 were not covered by tests


Expand All @@ -395,12 +400,16 @@ class LoreUpdateView(PermissionRequiredMixin, LoreFormMixin, UpdateView):
permission_required = ('internal.change_lore',)

def get_back_button_link(self):
title = self.get_form_kwargs()['instance']
title = str(self.get_form_kwargs()['instance'])
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
slug = slugify(title)
return reverse_lazy('lore_article', args=[slug])

Check warning on line 407 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L403-L407

Added lines #L403 - L407 were not covered by tests

def form_valid(self, form):
title = form.cleaned_data['title']
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
slug = slugify(title)
article = super().get_object()
if (article.slug != slug) and (Lore.objects.filter(slug=slug).exists()):
Expand All @@ -410,12 +419,14 @@ def form_valid(self, form):
return super().form_valid(form)

Check warning on line 419 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L419

Added line #L419 was not covered by tests

def get_success_url(self):
slug = slugify(self.object)
title = str(self.object)
title = title.replace('ø', 'o')
title = title.replace('æ', 'ae')
slug = slugify(title)
return reverse_lazy('lore_article', args=[slug])

Check warning on line 426 in src/internal/views.py

View check run for this annotation

Codecov / codecov/patch

src/internal/views.py#L422-L426

Added lines #L422 - L426 were not covered by tests


class LoreDeleteView(PermissionRequiredMixin, PreventGetRequestsMixin, DeleteView):
model = Lore
success_url = reverse_lazy('lore_list')
permission_required = ('internal.delete_lore',)

0 comments on commit 972bf22

Please sign in to comment.