1
\$\begingroup\$

I need to inject same variables into settings.py for multiple django apps.hence i wrote a module which takes in output of local() and modifies. This works but is it the right way to do things?

def enable_theme(theme_name, container):
"""
Enable the settings for a custom theme, whose files should be stored
in ENV_ROOT/themes/THEME_NAME (e.g., edx_all/themes/stanford).
The THEME_NAME setting should be configured separately since it can't
be set here (this function closes too early). An idiom for doing this
is:
 THEME_NAME = "stanford"
 enable_theme(THEME_NAME)
"""
 container["THEME_NAME"] = theme_name
 container['MITX_FEATURES']['USE_CUSTOM_THEME'] = True
 # Calculate the location of the theme's files
 theme_root = container['THEME_ROOT'] / "themes" / theme_name
 # Include the theme's templates in the template search paths
 container['TEMPLATE_DIRS'].append(theme_root / 'templates')
 container['THEME_SASS_DIRECTORY'] = theme_root / 'static/saas'
 container['MAKO_TEMPLATES']['main'].append(theme_root / 'templates')
 # Namespace the theme's static files to 'themes/<theme_name>' to
 # avoid collisions with default edX static files
 container['STATICFILES_DIRS'].append((u'themes/%s' % theme_name,
 theme_root / 'static'))
 container['FAVICON_PATH'] = 'themes/%s/images/favicon.ico' % theme_name
#Test case
from theming_utils.template_customizer import enable_theme
THEME_NAME = "sokratik"
PIPELINE = False
MITX_FEATURES['USE_DJANGO_PIPELINE'] = False
DEBUG = True
TEMPLATE_DEBUG = True
enable_theme(THEME_NAME, locals())
asked Sep 6, 2013 at 13:00
\$\endgroup\$
1
  • \$\begingroup\$ The code you posted doesn't use local(). Also, you need to format your code so that it shows up correctly. \$\endgroup\$ Commented Sep 6, 2013 at 13:15

1 Answer 1

1
\$\begingroup\$

You're not trying to modify a local environment, you're trying to modify the module's dictionary, which you can access by calling globals().

Note: the dictionary returned by locals() isn't meant to be modified.

answered Sep 6, 2013 at 15:33
\$\endgroup\$
2
  • \$\begingroup\$ that explains a bit of stuff, in case I am actually using globals, is it fine to modify globals in this way?? \$\endgroup\$ Commented Sep 6, 2013 at 19:29
  • \$\begingroup\$ It's okay to modify a module's dictionary, I don't know whether or not it's the right way to handle themes in Django. \$\endgroup\$ Commented Sep 6, 2013 at 20:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.