Skip to content

Commit

Permalink
Don't acquire .language from portal root.
Browse files Browse the repository at this point in the history
Fixes #258
  • Loading branch information
jaroel authored Oct 6, 2017
1 parent 1e9db4e commit 04decd8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions plone/app/dexterity/behaviors/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@
def default_language(context):
# If we are adding a new object, context will be the folderish object where
# this new content is being added
# import pdb; pdb.set_trace()
language = None

if context is not None and not IPloneSiteRoot.providedBy(context):
language = context.Language()
if not language:
# Try to get the language from context or parent(s)
while context is not None and not IPloneSiteRoot.providedBy(context):
try:
# Use aq_base so the .language attribute isn't acquired from root
language = context.aq_base.Language()
except AttributeError: # Accesses .language
# If we are here, it means we were editing an object that didn't
# have its language set or that the container where we were adding
# the new content didn't have a language set. So we check its
# parent, unless we are at site's root, in which case we get site's
# default language
if not IPloneSiteRoot.providedBy(context.aq_parent):
language = context.aq_parent.Language()
# parent.
context = context.__parent__

pl = getToolByName(getSite(), 'portal_languages')
default_language = pl.getDefaultLanguage()

if not language:
# Finally, if we still don't have a language, then just use site's
# default
pl = getToolByName(getSite(), 'portal_languages')
language = pl.getDefaultLanguage()
language = default_language

# Is the language supported/enabled at all?
if language not in pl.getAvailableLanguages():
language = default_language

return language

Expand Down

0 comments on commit 04decd8

Please sign in to comment.