Ask Your Question
0

Access settings attribute from template

asked 2013-06-04 13:27:57 -0600

SocialQA gravatar image

For example, in user_navigation.html template we have following code:

if settings.KARMA_MODE != 'hidden' and settings.BADGES_MODE != 'hidden'

I want to understand how this is been done, lets say I want to introduce a boolean value in the settings.py, how do I access that from my template similar to above technique.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-06-04 13:38:29 -0600

Evgeny gravatar image

If you would like to introduce those values via settings.py, then use the convention of the overrides by the livesettings app. Those settings are not the same as uppercased local variables inside the settings.py file.

LIVESETTINGS_OPTIONS = {
    1: {
        'DB': True,
        'SETTINGS': {
            'KARMA_AND_BADGE_VISIBILITY': {
                'KARMA_MODE': 'private',
                'BADGES_MODE': 'hidden'
            },
         }
    }
}

Where number 1 is site id. Key 'KARMA_AND_BADGE_VISIBILITY' is a section of livesettings - you can see that in the various askbot/conf/*.py files.

In general, I would say this is for the users who do not mind to get their hands on the code. Otherwise it is possible to change them via the /settings/ url.

We might in the future move away from the livesettings app as it has some limitations, and in that case the custom settings specified via the overrides will need to be migrated to the new, hopefully simpler format.

edit flag offensive delete link more

Comments

When I search for KARMA_AND_BADGE_VISIBILITY I found karma_adn_badges_visibility.py by that doesn't look like what you have put in the answer.

SocialQA gravatar imageSocialQA ( 2013-06-04 13:57:39 -0600 )edit
1

Yes - open that file and may be it will help you - there inside section with that name is defined. Like I said this is part of the livesettings app which has own conventions of dealing with the settings.

Evgeny gravatar imageEvgeny ( 2013-06-04 14:07:07 -0600 )edit

You have an index with an integer and curly braces where as in this file it has name KARMA_AND_BADGE_VISIBILITY then settings.register with ( ) braces.

SocialQA gravatar imageSocialQA ( 2013-06-04 14:12:56 -0600 )edit
1

That's just Python code. The settings are defined via the function calls and the LIVESETTINGS_OPTIONS is just nested dictionary representing the static overridden values. Once you override them in the settings.py you can't change them via the /settings/ url. The 1: { 'DB': True... part - consider that a preamble to the actual settings. The value of 'SETTINGS' is actually what you want to be editing. We have not made effort to make this part user friendly yet, sorry.

Evgeny gravatar imageEvgeny ( 2013-06-04 14:19:16 -0600 )edit

If I understood correctly what you put in your answer is something that goes into settings.py... if thats the case similarly karama_and_badge should have a attribute in settings.py.. I think i am super confused... wonder if you can show a simple end to end example. Thanks. May be then I can take an approach to clean it up and do an upstream.

SocialQA gravatar imageSocialQA ( 2013-06-04 14:30:33 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-04 13:27:57 -0600

Seen: 113 times

Last updated: Jun 04 '13