Skip to content
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

Don't acquire .language from portal root. #259

Open
wants to merge 2 commits into
base: 2.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ New features:

Bug fixes:

- Don't acquire lanuage from portal root default_language for ICategorization.language.
Fixes https://github.com/plone/plone.app.dexterity/issues/258
[jaroel]

- Make sure robot autologin test fixture is not accidentally torn down
when the Dexterity fixture's ZODB sandbox is reverted.
[davisagli]
Expand Down
27 changes: 16 additions & 11 deletions plone/app/dexterity/behaviors/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ def default_language(context):
# this new content is being added
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