From a5fbd3e90a7dc706ec2b508383ac178c0fb31696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 27 Feb 2012 11:11:37 +0100 Subject: [PATCH] Absolute urls and view definitions --- trans/models.py | 12 ++++++++++++ urls.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/trans/models.py b/trans/models.py index 8a99dcd2b..410f54dcf 100644 --- a/trans/models.py +++ b/trans/models.py @@ -10,6 +10,10 @@ class Project(models.Model): mail = models.EmailField() instructions = models.URLField() + @models.permalink + def get_absolute_url(self): + return ('trans.views.project', (), {'project': self.slug}) + class SubProject(models.Model): name = models.CharField(max_length = 100) slug = models.SlugField(db_index = True) @@ -17,6 +21,10 @@ class SubProject(models.Model): repo = models.CharField(max_length = 200) branch = models.CharField(max_length = 50) + @models.permalink + def get_absolute_url(self): + return ('trans.views.subproject', (), {'project': self.project.slug, 'subproject': self.slug}) + class Translation(models.Model): subproject = models.ForeignKey(SubProject) language = models.ForeignKey(Language) @@ -25,6 +33,10 @@ class Translation(models.Model): revision = models.CharField(max_length = 40) filename = models.CharField(max_length = 200) + @models.permalink + def get_absolute_url(self): + return ('trans.views.translation', (), {'project': self.subproject.slug, 'subproject': self.subproject.slug, 'lang': self.language.code}) + class Unit(models.Model): translation = models.ForeignKey(Translation) location = models.TextField() diff --git a/urls.py b/urls.py index aa6b85b7e..d2f8090ca 100644 --- a/urls.py +++ b/urls.py @@ -6,6 +6,9 @@ urlpatterns = patterns('', # Examples: # url(r'^$', 'weblate.views.home', name='home'), # url(r'^weblate/', include('weblate.foo.urls')), + url(r'^(?P[^/]*)/$', 'trans.views.project'), + url(r'^(?P[^/]*)/(?P[^/]*)/$', 'trans.views.subproject'), + url(r'^(?P[^/]*)/(?P[^/]*)/(?P[^/]*)/$', 'trans.views.translation'), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)),