From 710cb1a0ad8580914f11aa9f8f8a0a80e1b19f50 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 10 Apr 2017 14:30:24 +0300 Subject: [PATCH 1/2] Add utf-8 support in slugs with autoslug Slugs end up empty if list name consists only of non-ascii characters and that results in an error. Autoslug converts non-ascii characters to appropriate ascii ones and auto-updates the slug when list name changes. Add unidecode dependency and fix PEP8 errors models.py: add one blank line for PEP8 --- setup.py | 1 + todo/models.py | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index c32daa5..a708efe 100755 --- a/setup.py +++ b/setup.py @@ -99,6 +99,7 @@ setup( include_package_data=True, zip_safe=False, tests_require=['tox'], + install_requires=['django-autoslug', 'unidecode', ], cmdclass={ 'clean': Clean, 'test': Tox, diff --git a/todo/models.py b/todo/models.py index 0c5dc53..b7b67db 100644 --- a/todo/models.py +++ b/todo/models.py @@ -3,24 +3,18 @@ import datetime from django.db import models from django.contrib.auth.models import Group -from django.template.defaultfilters import slugify from django.core.urlresolvers import reverse from django.utils.encoding import python_2_unicode_compatible from django.conf import settings +from autoslug import AutoSlugField @python_2_unicode_compatible class List(models.Model): name = models.CharField(max_length=60) - slug = models.SlugField(max_length=60, editable=False) + slug = AutoSlugField(populate_from='name', editable=False, always_update=True) group = models.ForeignKey(Group) - def save(self, *args, **kwargs): - if not self.id: - self.slug = slugify(self.name) - - super(List, self).save(*args, **kwargs) - def __str__(self): return self.name From fc9f5d1bb4a77ecd7861a5f6da3f4838e5add9f8 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 10 Apr 2017 14:31:15 +0300 Subject: [PATCH 2/2] views.py: Fix variable artifact in del_list() del_list has no name attribute. We want the name of the deleted list. --- todo/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo/views.py b/todo/views.py index d10d4e3..c408ad8 100644 --- a/todo/views.py +++ b/todo/views.py @@ -71,7 +71,7 @@ def del_list(request, list_id, list_slug): if request.method == 'POST': List.objects.get(id=list.id).delete() - messages.success(request, "{list_name} is gone.".format(list_name=del_list.name)) + messages.success(request, "{list_name} is gone.".format(list_name=list.name)) return HttpResponseRedirect(reverse('todo-lists')) else: item_count_done = Item.objects.filter(list=list.id, completed=1).count()