Permalink
Browse files

resolved some inputs from fellow devs

  • Loading branch information...
1 parent 1d121c4 commit 5507637d1c466850da2b2248ff9f7a6a7bf0c3d0 @digi604 digi604 committed Oct 3, 2012
View
@@ -57,7 +57,7 @@ class AppRegexURLResolver(RegexURLResolver):
@property
def url_patterns(self):
language = get_language()
- if language in self.url_patterns_dict.keys():
+ if language in self.url_patterns_dict:
return self.url_patterns_dict[language]
else:
return []
View
@@ -9,19 +9,20 @@
def pre_patch():
"""Patch settings for dynamic defaults"""
if not getattr(settings, 'CMS_LANGUAGES', False):
- settings.CMS_LANGUAGES = {settings.SITE_ID:[]}
+ settings.CMS_LANGUAGES = {settings.SITE_ID: []}
for code, name in settings.LANGUAGES:
- lang = {'code':code, 'name':_(name)}
+ lang = {'code': code, 'name': _(name)}
settings.CMS_LANGUAGES[settings.SITE_ID].append(lang)
+
def post_patch():
"""Patch settings after global are added
"""
if settings.CMS_TEMPLATE_INHERITANCE:
# Append the magic inheritance template
settings.CMS_TEMPLATES = tuple(settings.CMS_TEMPLATES) + (
(settings.CMS_TEMPLATE_INHERITANCE_MAGIC, _('Inherit the template of the nearest ancestor')),
- )
+ )
def post_patch_check():
@@ -34,12 +35,12 @@ def post_patch_check():
if (cms_templates_length < 1 or
(cms_templates_length == 1 and settings.CMS_TEMPLATES[0][0] == settings.CMS_TEMPLATE_INHERITANCE_MAGIC)):
raise ImproperlyConfigured('Please make sure you specified a CMS_TEMPLATES setting.')
-
+
# check if is user middleware installed
if settings.CMS_PERMISSION and not 'cms.middleware.user.CurrentUserMiddleware' in settings.MIDDLEWARE_CLASSES:
raise ImproperlyConfigured('CMS Permission system requires cms.middleware.user.CurrentUserMiddleware.\n'
- 'Please put it into your MIDDLEWARE_CLASSES in settings file')
-
+ 'Please put it into your MIDDLEWARE_CLASSES in settings file')
+
# check sekizai namespaces
try:
from django.template.loaders.app_directories import Loader
@@ -56,19 +57,49 @@ def post_patch_check():
% template[0]
)
VALID_LANG_PROPS = ['code', 'name', 'fallbacks', 'hide_untranslated', 'redirect_on_fallback', 'public']
- try:
+
+ if isinstance(settings.CMS_LANGUAGES, tuple):
+ new_languages = {}
+ lang_template = {'code': '', 'name': '', 'fallbacks': [], 'public': True, 'redirect_on_fallback': True,
+ 'hide_untranslated': getattr(settings, 'CMS_HIDE_UNTRANSLATED', False)}
+ if hasattr(settings, 'CMS_SITE_LANGUAGES'):
+ for site in settings.CMS_SITE_LANGUAGES:
+ new_languages[site] = []
+ else:
+ new_languages[1] = []
+
+ if hasattr(settings, 'CMS_SITE_LANGUAGES'):
+ for site in settings.CMS_SITE_LANGUAGES:
+ for site_code in settings.CMS_SITE_LANGUAGES[site]:
+ for code, name in settings.CMS_LANGUAGES:
+ if code == site_code:
+ new_languages[site].append(get_old_language_conf(code, name, lang_template))
+ else:
+ for code, name in settings.CMS_LANGUAGES:
+ new_languages[1].append(get_old_language_conf(code, name, lang_template))
+ settings.CMS_LANGUAGES = new_languages
+ import pprint
+
+ pp = pprint.PrettyPrinter(indent=4)
+ warnings.warn(
+ "CMS_LANGUAGES has changed in django-cms 2.4\nYou may replace CMS_LANGUAGES with the following:\n%s" %
+ pp.pformat(settings.CMS_LANGUAGES), CMSDeprecationWarning)
+
+ else:
for site in settings.CMS_LANGUAGES:
try:
int(site)
except ValueError:
- if not site =="default":
- raise ImproperlyConfigured("CMS_LANGUAGES can only be filled with integers (site ids) and 'default'"
- " for default values. %s is not a valid key." % site)
+ if not site == "default":
+ raise ImproperlyConfigured(
+ "CMS_LANGUAGES can only be filled with integers (site ids) and 'default'"
+ " for default values. %s is not a valid key." % site)
for language in settings.CMS_LANGUAGES[site]:
if site == "default":
if language not in VALID_LANG_PROPS:
- raise ImproperlyConfigured("CMS_LANGUAGES has an invalid property in the default properties: %(property)s" %
- {'property':language})
+ raise ImproperlyConfigured(
+ "CMS_LANGUAGES has an invalid property in the default properties: %(property)s" %
+ {'property': language})
continue
if not "code" in language.keys():
raise ImproperlyConfigured("CMS_LANGUAGES has a language without a 'code' property")
@@ -78,8 +109,8 @@ def post_patch_check():
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':language['code'], 'property':key})
- # Fill up the defaults
+ {'site': site, 'language': language['code'], 'property': key})
+ # Fill up the defaults
if not language.has_key('fallbacks'):
fallbacks = []
for tmp_language in settings.CMS_LANGUAGES[site]:
@@ -104,44 +135,17 @@ def post_patch_check():
language['public'] = True
if not language.has_key('redirect_on_fallback'):
if settings.CMS_LANGUAGES.has_key('default'):
- language['redirect_on_fallback'] = settings.CMS_LANGUAGES['default'].get('redirect_on_fallback', True)
+ language['redirect_on_fallback'] = settings.CMS_LANGUAGES['default'].get(
+ 'redirect_on_fallback',
+ True)
else:
language['redirect_on_fallback'] = True
if not language.has_key('hide_untranslated'):
if settings.CMS_LANGUAGES.has_key('default'):
- language['hide_untranslated'] = settings.CMS_LANGUAGES['default'].get('hide_untranslated', True)
+ language['hide_untranslated'] = settings.CMS_LANGUAGES['default'].get('hide_untranslated',
+ True)
else:
language['hide_untranslated'] = True
- except TypeError:
- if type(settings.CMS_LANGUAGES) == tuple:
- new_languages = {}
- lang_template = {'code':'', 'name':'', 'fallbacks':[],'public':True, 'redirect_on_fallback':True, 'hide_untranslated':False}
- if hasattr(settings,'CMS_HIDE_UNTRANSLATED'):
- lang_template['hide_untranslated'] = settings.CMS_HIDE_UNTRANSLATED
- if hasattr(settings, 'CMS_SITE_LANGUAGES'):
- for site in settings.CMS_SITE_LANGUAGES:
- new_languages[site] = []
- else:
- new_languages[1]=[]
-
- if hasattr(settings, 'CMS_SITE_LANGUAGES'):
- for site in settings.CMS_SITE_LANGUAGES:
- for site_code in settings.CMS_SITE_LANGUAGES[site]:
- for code, name in settings.CMS_LANGUAGES:
- if code == site_code:
- new_languages[site].append(get_old_language_conf(code, name, lang_template))
- else:
- for code, name in settings.CMS_LANGUAGES:
- new_languages[1].append(get_old_language_conf(code, name, lang_template))
- settings.CMS_LANGUAGES = new_languages
- import pprint
- pp = pprint.PrettyPrinter(indent=4)
- warnings.warn(
- "CMS_LANGUAGES has changed in django-cms 2.4\nYou may replace CMS_LANGUAGES with the following:\n%s" % pp.pformat(settings.CMS_LANGUAGES),
- CMSDeprecationWarning)
-
- else:
- raise ImproperlyConfigured("CMS_LANGUAGES has changed and has some errors. Please refer to the docs.")
def get_old_language_conf(code, name, template):
View
@@ -2,9 +2,11 @@
class PluginAlreadyRegistered(Exception):
pass
+
class PluginNotRegistered(Exception):
pass
+
class AppAlreadyRegistered(Exception):
pass
@@ -13,12 +15,15 @@ class AppAlreadyRegistered(Exception):
class NotImplemented(Exception):
pass
+
class SubClassNeededError(Exception):
pass
+
class MissingFormError(Exception):
pass
+
class NoHomeFound(Exception):
pass
@@ -27,14 +32,22 @@ class PermissionsException(Exception):
"""Base permission exception
"""
+
class NoPermissionsException(PermissionsException):
"""Can be fired when some violate action is performed on permission system.
"""
-
+
+
class Deprecated(Exception): pass
-
+
+
class DuplicatePlaceholderWarning(Warning): pass
+
class DontUsePageAttributeWarning(Warning): pass
-class CMSDeprecationWarning(Warning):pass
+
+class CMSDeprecationWarning(Warning): pass
+
+
+class LanguageError(Exception): pass
@@ -29,7 +29,7 @@ class Meta:
app_label = 'cms'
def __unicode__(self):
- return "%s (%s, %s)" % (self.title, self.slug, self.language)
+ return u"%s (%s, %s)" % (self.title, self.slug, self.language)
def save(self, *args, **kwargs):
# Update the path attribute before saving
View
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from contextlib import contextmanager
+from cms.exceptions import LanguageError
from django.conf import settings
from django.utils import translation
@contextmanager
def force_language(new_lang):
old_lang = translation.get_language()
- translation.activate(new_lang)
+ if old_lang != new_lang:
+ translation.activate(new_lang)
yield
translation.activate(old_lang)
@@ -142,7 +144,3 @@ def get_site(site):
return int(site)
except TypeError:
return site.pk
-
-
-class LanguageError(Exception):
- pass
View
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.db.models import Q
-from django.core.exceptions import ValidationError
import re
APPEND_TO_SLUG = "-copy"
@@ -32,17 +31,18 @@ def is_valid_page_slug(page, parent, lang, slug, site, path=None):
qs = qs.filter(page__parent__isnull=True)
if page.pk:
- qs = qs.exclude(Q(language=lang)&Q(page=page))
+ qs = qs.exclude(Q(language=lang) & Q(page=page))
if settings.CMS_MODERATOR:
qs = qs.exclude(page__publisher_public=page)
- ## Check for slugs
+ ## Check for slugs
if qs.filter(slug=slug).count():
return False
- ## Check for path
+ ## Check for path
if path and qs.filter(path=path).count():
return False
return True
+
def get_available_slug(title, new_slug=None):
"""Smart function generates slug for title if current title slug cannot be
used. Appends APPEND_TO_SLUG to slug and checks it again.
@@ -59,7 +59,7 @@ def get_available_slug(title, new_slug=None):
path = title.path
# This checks for conflicting slugs/overwrite_url, for both published and unpublished pages
# This is a simpler check than in page_resolver.is_valid_url which
- # takes into account actualy page URL
+ # takes into account actually page URL
if not is_valid_page_slug(title.page, title.page.parent, title.language, slug, title.page.site, path):
# add nice copy attribute, first is -copy, then -copy-2, -copy-3, ....
match = COPY_SLUG_REGEX.match(slug)
@@ -68,10 +68,10 @@ def get_available_slug(title, new_slug=None):
next = int(match.groups()[0]) + 1
slug = "-".join(slug.split('-')[:-1]) + "-%d" % next
except TypeError:
- slug = slug + "-2"
+ slug += "-2"
else:
- slug = slug + APPEND_TO_SLUG
+ slug += APPEND_TO_SLUG
return get_available_slug(title, slug)
else:
return slug
View
@@ -7,9 +7,9 @@ Internationalization
Multilingual URLs
*****************
-If you use more than one language, django-CMS urls need
-to be referenced via a `i18n_patterns`_. For more information about this see the
-official django documentation.
+If you use more than one language, django CMS urls need
+to be referenced via :func:`~django.conf.urls.i18n.i18n_patterns`. For more information about this see the
+official django `documentation`_.
Main `urls.py` example:
@@ -35,7 +35,7 @@ Main `urls.py` example:
)
-.. _i18n_patterns: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#internationalization-in-url-patterns
+.. _documentation: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#internationalization-in-url-patterns
****************
Language Chooser
View
@@ -17,7 +17,7 @@ For django 1.4 more infos can be found here:
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#internationalization-in-url-patterns
-If you are still running django 1.3 you are able to archive the same functionality with django-i18nurl. It is a backport
+If you are still running django 1.3 you are able to archieve the same functionality with django-i18nurl. It is a backport
of the new functionality in django 1.4 and can be found here:
https://github.com/brocaar/django-i18nurls
@@ -7,6 +7,4 @@ South>=0.7.2
html5lib
django-mptt==0.5.1
django-sekizai>=0.6.1
-argparse
-
-
+argparse

0 comments on commit 5507637

Please sign in to comment.