Put the 'languages' dict in utils.py outside of any function def, set it to None by default, then a method to return it, populating it if it's not already there, then call that method from the context processor:
loco_directory/common/utils.py
languages = None
def get_languages():
"""
Return a language list.
"""
if languages is None:
languages = {}
Languages = Language.objects.order_by('name')
for language in Languages:
if check_for_language(language.code): languages[language.code] = language.name
languages = sorted([(value,key) for (key,value) in languages.items()])
return languages
Put the 'languages' dict in utils.py outside of any function def, set it to None by default, then a method to return it, populating it if it's not already there, then call that method from the context processor:
loco_directory/ common/ utils.py
languages = None objects. order_by( 'name') language( language. code):
languages[ language. code] = language.name
def get_languages():
"""
Return a language list.
"""
if languages is None:
languages = {}
Languages = Language.
for language in Languages:
if check_for_
languages = sorted([(value,key) for (key,value) in languages.items()])
return languages
loco_directory/ common/ context_ processors. py
import common.utils menu(request) : utils.get_ languages( )}
def language_
return {'languages': common.