fixes for Page model translation into admin, fix for Dj1.6 compatibility

EmailTemplateFixes
matteo.cafarotti 2014-10-04 11:22:47 +02:00
parent 7ef7ad3eff
commit e8347d3815
4 changed files with 18 additions and 19 deletions

View File

@ -1,4 +1,4 @@
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
@ -8,9 +8,9 @@ urlpatterns = patterns('',
url(r'q/', include('questionnaire.urls')),
url(r'^take/(?P<questionnaire_id>[0-9]+)/$', 'questionnaire.views.generate_run'),
url(r'^$', 'questionnaire.page.views.page', {'page' : 'index'}),
url(r'^(?P<page>.*)\.html$', 'questionnaire.page.views.page'),
url(r'^(?P<lang>..)/(?P<page>.*)\.html$', 'questionnaire.page.views.langpage'),
url(r'^$', 'questionnaire.page.views.page', {'page_to_render' : 'index'}),
url(r'^(?P<lang>..)/(?P<page_to_trans>.*)\.html$', 'questionnaire.page.views.langpage'),
url(r'^(?P<page_to_render>.*)\.html$', 'questionnaire.page.views.page'),
url(r'^setlang/$', 'questionnaire.views.set_language'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

View File

@ -356,11 +356,11 @@ class Question(models.Model):
def questioninclude(self):
return "questionnaire/" + self.get_type() + ".html"
def __cmp__(a, b):
anum, astr = split_numal(a.number)
bnum, bstr = split_numal(b.number)
cmpnum = cmp(anum, bnum)
return cmpnum or cmp(astr, bstr)
# def __cmp__(a, b):
# anum, astr = split_numal(a.number)
# bnum, bstr = split_numal(b.number)
# cmpnum = cmp(anum, bnum)
# return cmpnum or cmp(astr, bstr)
class Meta:
translate = ('text', 'extra', 'footer')

View File

@ -6,17 +6,16 @@ class Page(models.Model):
__metaclass__ = TransMeta
slug = models.SlugField(unique=True, primary_key=True)
title = models.CharField(max_length=256)
body = models.TextField()
title = models.CharField(u"Title", max_length=256)
body = models.TextField(u"Body")
public = models.BooleanField(default=True)
def __unicode__(self):
return u"Page[%s]" % self.slug
def get_absolute_url(self):
return reverse('page.views.page', kwargs={'page':self.slug})
return reverse('questionnaire.page.views.page', kwargs={'page_to_render':self.slug})
class Meta:
pass
translate = ('title','body',)

View File

@ -6,20 +6,20 @@ from django import http
from django.utils import translation
from models import Page
def page(request, page):
def page(request, page_to_render):
try:
p = Page.objects.get(slug=page, public=True)
p = Page.objects.get(slug=page_to_render, public=True)
except Page.DoesNotExist:
raise http.Http404('%s page requested but not found' % page)
raise http.Http404('%s page requested but not found' % page_to_render)
return render_to_response("page.html",
{ "request" : request, "page" : p, },
context_instance = RequestContext(request)
)
def langpage(request, lang, page):
translation.activate_language(lang)
return page(request, page)
def langpage(request, lang, page_to_trans):
translation.activate(lang)
return page(request, page_to_trans)
def set_language(request):
next = request.REQUEST.get('next', None)