This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #776 from liqd/mn-2019-07-translatable-wagtail-pages
Mn 2019 07 translatable wagtail pages
- Loading branch information
Showing
8 changed files
with
218 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 11:43 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0006_rename_tables_to_default'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='homepage', | ||
old_name='body', | ||
new_name='body_de', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 11:44 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
import wagtail.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0007_rename_body_to_body_de'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='homepage', | ||
name='body_en', | ||
field=wagtail.core.fields.RichTextField(blank=True), | ||
), | ||
] |
20 changes: 20 additions & 0 deletions
20
apps/cms/pages/migrations/0009_rename_subtitle_to_subtititle_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 12:00 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0008_homepage_body_en'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='homepage', | ||
old_name='subtitle', | ||
new_name='subtitle_de', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 12:01 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0009_rename_subtitle_to_subtititle_de'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='homepage', | ||
name='subtitle_en', | ||
field=models.CharField(blank=True, max_length=500, verbose_name='Subtitle'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 14:46 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0010_homepage_subtitle_en'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='simplepage', | ||
old_name='body', | ||
new_name='body_de', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-07-02 14:47 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
import wagtail.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_pages', '0011_rename_body_to_body_de'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='simplepage', | ||
name='body_en', | ||
field=wagtail.core.fields.RichTextField(blank=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.utils import translation | ||
from wagtail.core.blocks.stream_block import StreamValue | ||
|
||
|
||
class TranslatedField(object): | ||
|
||
def __init__(self, de_field, en_field): | ||
self.de_field = de_field | ||
self.en_field = en_field | ||
|
||
def hasContent(self, field): | ||
if isinstance(field, StreamValue): | ||
value = field.stream_data | ||
if value: | ||
return True | ||
else: | ||
return False | ||
elif isinstance(field, str): | ||
if field: | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
|
||
def __get__(self, instance, owner): | ||
de = getattr(instance, self.de_field) | ||
en = getattr(instance, self.en_field) | ||
|
||
if translation.get_language() == 'en' and self.hasContent(en): | ||
return en | ||
else: | ||
return de |