Skip to content

Commit

Permalink
use getattr
Browse files Browse the repository at this point in the history
  • Loading branch information
agitator committed May 9, 2022
1 parent 3e57847 commit e0cd920
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions plone/app/dexterity/behaviors/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,24 @@ def default_language(context):
language = None

# 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
while not language and context is not None and not IPloneSiteRoot.providedBy(context):
language = getattr(context.aq_base, 'language', None)

if not 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.
context = context.__parent__

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

if not language:
language = default_language

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

return language
Expand Down

0 comments on commit e0cd920

Please sign in to comment.