]> git.openstreetmap.org Git - osqa.git/blob - forum/context.py
adding an example test for the user module. the fixture portion of this maybe not...
[osqa.git] / forum / context.py
1 from forum import settings
2 from django.conf import settings as djsettings
3
4 def application_settings(context):
5     my_settings = {
6         'APP_TITLE' : settings.APP_TITLE,
7         'APP_SHORT_NAME' : settings.APP_SHORT_NAME,
8         'SHOW_WELCOME_BOX' : settings.SHOW_WELCOME_BOX,
9         'APP_URL'   : settings.APP_URL,
10         'APP_KEYWORDS' : settings.APP_KEYWORDS,
11         'APP_DESCRIPTION' : settings.APP_DESCRIPTION,
12         'APP_INTRO' : settings.APP_INTRO,
13         'APP_LOGO' : settings.APP_LOGO,
14         'EMAIL_VALIDATION': 'off',
15                 'SUPPORT_URL': settings.SUPPORT_URL,
16                 'CONTACT_URL': settings.CONTACT_URL,
17         'FORUM_SCRIPT_ALIAS': djsettings.FORUM_SCRIPT_ALIAS,
18         'LANGUAGE_CODE': djsettings.LANGUAGE_CODE,
19         'GOOGLE_SITEMAP_CODE':settings.GOOGLE_SITEMAP_CODE,
20         'GOOGLE_ANALYTICS_KEY':settings.GOOGLE_ANALYTICS_KEY,
21         'WIKI_ON':settings.WIKI_ON,
22         'OSQA_SKIN':djsettings.OSQA_DEFAULT_SKIN,
23         'APP_FAVICON':settings.APP_FAVICON,
24         'OSQA_VERSION': settings.OSQA_VERSION,
25         'ADMIN_MEDIA_PREFIX': djsettings.ADMIN_MEDIA_PREFIX,
26         'SVN_REVISION': settings.SVN_REVISION,
27         }
28     return {'settings':my_settings}
29
30 def auth_processor(request):
31     """
32     Returns context variables required by apps that use Django's authentication
33     system.
34
35     If there is no 'user' attribute in the request, uses AnonymousUser (from
36     django.contrib.auth).
37     """
38     if hasattr(request, 'user'):
39         user = request.user
40         if user.is_authenticated():
41             messages = user.message_set.all()
42         else:
43             messages = None
44     else:
45         from django.contrib.auth.models import AnonymousUser
46         user = AnonymousUser()
47         messages = None
48
49     from django.core.context_processors import PermWrapper
50     return {
51         'user': user,
52         'messages': messages,
53         'perms': PermWrapper(user),
54     }