English language fields

This commit is contained in:
Oleg Lavrovsky 2018-05-25 15:17:53 +02:00
parent e02256acc3
commit 0c681b615d
4 changed files with 19 additions and 1 deletions

View file

@ -219,16 +219,20 @@ class ArticleRelatedLink(Orderable):
class HomePage(Page):
intro_de = RichTextField(default='')
intro_fr = RichTextField(default='')
intro_en = RichTextField(default='')
trans_intro = TranslatedField(
'intro_de',
'intro_fr',
'intro_en',
)
body_de = RichTextField(default='', blank=True)
body_fr = RichTextField(default='', blank=True)
body_en = RichTextField(default='', blank=True)
trans_body = TranslatedField(
'body_de',
'body_fr',
'body_en',
)
infos_de = StreamField([
@ -237,9 +241,13 @@ class HomePage(Page):
infos_fr = StreamField([
('info', InfoBlock())
], null=True, blank=True)
infos_en = StreamField([
('info', InfoBlock())
], null=True, blank=True)
trans_infos = TranslatedField(
'infos_de',
'infos_fr',
'infos_en',
)
content_panels = Page.content_panels + [
@ -253,6 +261,11 @@ class HomePage(Page):
FieldPanel('body_fr', classname="full"),
StreamFieldPanel('infos_fr'),
], heading="Français"),
MultiFieldPanel([
FieldPanel('intro_en', classname="full"),
FieldPanel('body_en', classname="full"),
StreamFieldPanel('infos_en'),
], heading="English"),
]
@property

View file

@ -52,9 +52,11 @@ class Contact(models.Model):
"""
title = models.CharField(max_length=255, default="")
title_fr = models.CharField(max_length=255, default="")
title_en = models.CharField(max_length=255, default="")
trans_title = TranslatedField(
'title',
'title_fr',
'title_en',
)
address = models.TextField(default="", blank=True)
phone = models.CharField(max_length=40, default="")
@ -75,6 +77,7 @@ class Contact(models.Model):
panels = Page.content_panels + [
FieldPanel('title_fr'),
FieldPanel('title_en'),
FieldPanel('address'),
FieldPanel('phone'),
FieldPanel('email'),

View file

@ -13,6 +13,8 @@ def language_switcher(context):
if len(url) > 2 and len(url[1]) >= 2:
url[1] = '$lang$'
url = '/'.join(url)
else:
url = context['page'].url
return {
'languages': [
{ 'code': 'de', 'title': 'De', 'url': url.replace('$lang$','de') },

View file

@ -1,7 +1,7 @@
from django.utils import translation
class TranslatedField(object):
def __init__(self, de_field, fr_field, en_field=None):
def __init__(self, de_field, fr_field, en_field):
self.de_field = de_field
self.fr_field = fr_field
self.en_field = en_field