Skip to content

Commit

Permalink
A candidate can have non utf8 names
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Álvarez committed Feb 24, 2014
1 parent 50f55da commit 619cc66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.template.defaultfilters import slugify
from django.db.models.signals import post_save
from django.dispatch.dispatcher import receiver
from unidecode import unidecode


facebook_regexp = re.compile(r"^https?://[^/]*(facebook\.com|fb\.com|fb\.me)(/.*|/?)")
Expand Down Expand Up @@ -86,7 +87,7 @@ class Candidate(models.Model):

def save(self, *args, **kwargs):
if self.pk is None:
self.slug = slug = slugify(self.name)
self.slug = slug = slugify(unidecode(unicode(self.name)))
counter = 1
while True:
try:
Expand Down
11 changes: 11 additions & 0 deletions elections/tests/candidate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import os
from django.conf import settings
from django.test import TestCase
Expand Down Expand Up @@ -63,6 +64,16 @@ def test_create_candidate(self):
self.assertTrue(candidate.has_answered)
self.assertEqual(candidate.election, self.election)


def test_create_candidate_with_a_non_utf8_name(self):
candidate = Candidate.objects.create(name=u'مرشح واحد',
election=self.election)
self.assertTrue(candidate)
self.assertEqual(candidate.name, u'مرشح واحد')
self.assertTrue(candidate.slug)



def test_update_candidate(self):
candidate, created = Candidate.objects.get_or_create(name='Juan Candidato',
election=self.election)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ pillow==2.0.0
django-tastypie==0.9.15
django-markdown-deux==1.0.4
pyaml==13.07.1
unidecode==0.04.14

0 comments on commit 619cc66

Please sign in to comment.