New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New i18n settings #2
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,16 @@ | |
from django.utils.translation import ugettext_lazy as _ | ||
from sekizai.helpers import validate_template | ||
|
||
def pre_patch(): | ||
"""Patch settings for dynamic defaults""" | ||
if not getattr(settings, 'CMS_LANGUAGES', False): | ||
settings.CMS_LANGUAGES = {settings.SITE_ID:[]} | ||
for code, name in settings.LANGUAGES: | ||
lang = {'code':code, 'name':_(name)} | ||
settings.CMS_LANGUAGES[settings.SITE_ID].append(lang) | ||
|
||
def post_patch(): | ||
"""Patch settings after global are adde | ||
"""Patch settings after global are added | ||
""" | ||
if settings.CMS_TEMPLATE_INHERITANCE: | ||
# Append the magic inheritance template | ||
|
@@ -46,3 +53,33 @@ def post_patch_check(): | |
"I can't find the namespaces in %r." | ||
% template[0] | ||
) | ||
VALID_LANG_PROPS = ['code', 'name', 'fallbacks', 'hide_untranslated', 'redirect_on_fallback', 'public'] | ||
try: | ||
for site in settings.CMS_LANGUAGES.keys(): | ||
try: | ||
int(site) | ||
except ValueError: | ||
if not site =="default": | ||
raise ImproperlyConfigured("CMS_LANGUAGES can only be filled with integers (site ids) and 'default' for\n" | ||
" default values. %s is not a valid key." % site) | ||
for lang in settings.CMS_LANGUAGES[site]: | ||
if site == "default": | ||
if lang not in VALID_LANG_PROPS: | ||
raise ImproperlyConfigured("CMS_LANGUAGES has an invalid property on the site %(site)s and language %(language)s: %(property)s" % {'site':site, 'language':lang['code'], 'property':key}) | ||
continue | ||
if not "code" in lang.keys(): | ||
raise ImproperlyConfigured("CMS_LANGUAGES has language without a 'code' property") | ||
if not 'name' in lang.keys(): | ||
raise ImproperlyConfigured("CMS_LANGUAGES has a language without a 'name' property") | ||
for key in lang.keys(): | ||
if key not in VALID_LANG_PROPS: | ||
raise ImproperlyConfigured("CMS_LANGUAGES has an invalid property on the site %(site)s and language %(language)s: %(property)s" % {'site':site, 'language':lang['code'], 'property':key}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8? this is a little over 80 characters.... |
||
except: | ||
raise ImproperlyConfigured("CMS_LANGUAGES has changed. Please refer to the docs.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should really be backwards compatible for at least one release with warnings instead of exceptions. |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's up with the empty lines here? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -530,6 +530,8 @@ def get_languages(self): | |
self.all_languages = Title.objects.filter(page=self).values_list("language", flat=True).distinct() | ||
self.all_languages = list(self.all_languages) | ||
self.all_languages.sort() | ||
for x in xrange(len(self.all_languages)): | ||
self.all_languages[x] = str(self.all_languages[x]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wat? |
||
return self.all_languages | ||
|
||
def get_cached_ancestors(self, ascending=True): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ def render(self, context, instance, placeholder): | |
page = instance.from_page | ||
else: | ||
page = instance.page | ||
if not instance.page.publisher_is_draft and page.publisher_is_draft: | ||
if settings.CMS_MODERATOR and not instance.page.publisher_is_draft and page.publisher_is_draft: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't look i18n related |
||
page = page.publisher_public | ||
|
||
plugins = get_cmsplugin_queryset(request).filter( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from cms.utils.i18n import get_language_tuple | ||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
from cms.models import CMSPlugin, Page | ||
from django.conf import settings | ||
|
||
class InheritPagePlaceholder(CMSPlugin): | ||
""" | ||
Provides the ability to inherit plugins for a certain placeholder from an associated "parent" page instance | ||
""" | ||
from_page = models.ForeignKey(Page, null=True, blank=True, help_text=_("Choose a page to include its plugins into this placeholder, empty will choose current page")) | ||
from_language = models.CharField(_("language"), max_length=5, choices=settings.CMS_LANGUAGES, blank=True, null=True, help_text=_("Optional: the language of the plugins you want")) | ||
from_language = models.CharField(_("language"), max_length=5, choices=get_language_tuple(), blank=True, null=True, help_text=_("Optional: the language of the plugins you want")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.keys()
is useless here.