I start playing around with Django, because I dig python.
I thought it is a matured framework for, for trying to start a multi-
language website with it.
(no just from UI, but that the data can be translate too)
I was using django-multilingual (anyone knows of a better app for this
kind of thing ??)
my models.py looked like that:
class CustomMovieManager(multilingual.Manager):
pass
class Movie(models.Model):
creator = models.ForeignKey(User, verbose_name=_("Created by"),
blank=True, null=True)
created = models.DateTimeField(verbose_name=_("Created at"),
auto_now_add=True)
objects = CustomMovieManager()
class Translation(multilingual.Translation):
title = models.CharField(verbose_name=_("The title"),
blank=True, null=False, max_length=250)
slug = models.SlugField(max_length=50, unique=True, blank=True,
null=True)
summary = models.TextField(verbose_name=_("The summary"),
blank=True, null=False)
A few problem that I was facing, and haven't found a good solutions
for them,
maybe one of you found solutions to those kind of problems.
1.
I wanted to have Hebrew URLs like:
http://localhost/movie/טרמינטור-אחד/ & http://localhost/movie/terminator-one/
django own "django.template.defaultfilters.slugify" wasn't doing a
decent at all:
>>> a = slugify(u'טרמינטור אחד')
>>> print a
''
whats caused me to do this ugly save (which is far form cover all
cases):
def save(self, *args, **kwargs):
for lang_code, lang_name in settings.LANGUAGES:
lang_code = lang_code.replace('-','_')
if getattr(self, 'title_'+lang_code):
slug = slugify(getattr(self, 'title_'+lang_code))
if slug == '': slug = getattr(self,
'title_'+lang_code).replace(' ','-')
setattr(self, 'slug_'+lang_code, slug)
super(Movie, self).save(*args, **kwargs)
2. I really love using doctest, it's the easiest way of doing unit
testing that will last
when I was using ./manage.py test [my app],
I was amaze to discover that django is using it's own _doctest.py, and
not python doctest.
but more weird was that:
>>> p.slug
u'terminator-ver-1'
>>> p.slug_he
u'טרמינטור-אחד'
caused:
Failed example:
p.slug_he
Expected:
u'��¨��� ���¨-���'
Got:
u'\u05d8\u05e8\u05de\u05d9\u05e0\u05d8\u05d5\u05e8-
\u05d0\u05d7\u05d3'
which forced me to change that test to:
>>> p.slug
u'terminator-ver-1'
>>> p.slug_he == u'טרמינטור-אחד'
True
Go figure out what went wrong when this one fails
3.
the last one, which is probably part django-multilingual part django
admin fault.
when I was trying to add items with django admin:
Language: English
The title:
Slug:
The summary:
Language: Hebrew
The title:
Slug:
The summary:
Slug was mandatory, but when ever I've put Hebrew inside it, it went:
"Enter a valid 'slug' consisting of letters, numbers, underscores or
hyphens."
Hmm, who decided Hebrew isn't letters ?? how racial of them :)
I haven't found a way to remove the slug form the admin page (cause of
django-multilingual clever abuse of the admin)
any ideas for solving this one are most then welcome.
Well that's enough noise for one time.
שבוע טוב
Fruch
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"PyWeb-IL" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyweb-il?hl=en
-~----------~----~----~----~------~----~------~--~---
_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il