public
Description: StartTheDark is the product of a series of screencasts by Eric Florenzano about the Django web programming framework. The site itself is "A place to see what your friends are doing tonight!"
Homepage: http://startthedark.com/
Clone URL: git://github.com/ericflo/startthedark.git
startthedark / context_processors.py
100644 29 lines (24 sloc) 0.824 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.conf import settings
 
class Counter(object):
    """
A simple counter class which keeps a single integer as private state. Every
time ``get_int`` is called, that integer is returned and then incremented
internally by one.
"""
    i = 1
    
    def get_int(self):
        self.i += 1
        return self.i - 1
 
def production(request):
    """
Serves two purposes:
1. To simply put one instance of ``Counter`` into the context for use
anywhere within the site.
2. To conditionally set a 'MEDIA_SUFFIX' context variable with the value
'-prod'. This is used for media files that differ from development to
production.
"""
    context = {'counter': Counter()}
    if not settings.DEBUG:
        context['MEDIA_SUFFIX'] = '-prod'
    return context