1.3
[auf_recipe_django.git] / auf / recipe / django / boilerplate.py
1 # -*- encoding: utf-8 -*-
2 import zc.buildout.easy_install
3
4
5 env = '''
6 %(relative_paths_setup)s
7 import sys
8 import pkg_resources
9
10 eggs_path = [
11 %(path)s,
12 ]
13
14 sys.path[0:0] = eggs_path
15
16 # correction des namespaces virtuels
17 for egg_path in eggs_path:
18 pkg_resources.fixup_namespace_packages(egg_path)
19 %(initialization)s
20 import %(module_name)s
21 '''
22
23 auf_buildout_file = zc.buildout.easy_install.script_header + env + '''\
24 if __name__ == '__main__':
25 %(module_name)s.%(attrs)s(%(arguments)s)
26 '''
27
28 auf_script_template = {
29 'wsgi': env + """
30 application = %(module_name)s.%(attrs)s(%(arguments)s)
31 """,
32 'fcgi': env + """
33 %(module_name)s.%(attrs)s(%(arguments)s)
34 """,
35 }
36
37
38 ################################################################################
39 # SETTINGS
40 ################################################################################
41
42 conf_file = '''# -*- encoding: utf-8 -*
43
44 DATABASES = {
45 'default': {
46 #'ENGINE': 'django.db.backends.mysql',
47 'ENGINE': 'django.db.backends.sqlite3',
48 'NAME': 'db.sqlite',
49 'USER': '',
50 'PASSWORD': '',
51 'HOST' : '',
52 'PORT' : '',
53 }
54 }
55
56 '''
57
58 dashboard_file ='''# -*- encoding: utf-8 -*
59
60 from django.utils.translation import ugettext_lazy as _
61 from django.core.urlresolvers import reverse
62
63 from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
64 from admin_tools.utils import get_admin_site_name
65
66
67 class CustomIndexDashboard(Dashboard):
68 """
69 Custom index dashboard
70 """
71 def init_with_context(self, context):
72 site_name = get_admin_site_name(context)
73
74 # append an app list module for "Applications"
75 self.children.append(modules.AppList(
76 _('Applications'),
77 exclude=('django.contrib.*',),
78 ))
79
80 # append an app list module for "Administration"
81 self.children.append(modules.AppList(
82 _('Administration'),
83 models=('django.contrib.*',),
84 ))
85
86 # append a recent actions module
87 self.children.append(modules.RecentActions(_('Recent Actions'), 5))
88 '''
89
90
91 auf_urls_template = '''# -*- encoding: utf-8 -*
92 from django.conf.urls.defaults import patterns, include, handler500, handler404, url
93 from django.conf import settings
94 from django.contrib import admin
95
96 admin.autodiscover()
97
98 handler404
99 handler500 # Pyflakes
100
101 urlpatterns = patterns(
102 '',
103 ######## page d'accueil de demo ######
104 (r'^$', 'auf.django.skin.views.demo'),
105 ######################################
106 url(r'^admin_tools/', include('admin_tools.urls')),
107 (r'^admin/', include(admin.site.urls)),
108 (r'^connexion/$', 'django.contrib.auth.views.login'),
109 (r'^deconnexion/$', 'django.contrib.auth.views.logout'),
110
111 )
112
113 if settings.DEBUG:
114 urlpatterns += patterns('',
115 (r'^media/(?P<path>.*)$', 'django.views.static.serve',
116 {'document_root': settings.MEDIA_ROOT}),
117 )
118 '''
119
120 auf_settings_template = '''# -*- encoding: utf-8 -*-
121
122 import os
123 import socket
124 from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as DEFAULT_TEMPLATE_CONTEXT_PROCESSORS
125
126 # Rapports d'erreurs
127 EMAIL_SUBJECT_PREFIX = '[%(project_name)s - %%s] ' %% socket.gethostname()
128 ADMINS = (
129 ('Équipe ARI-SI', 'developpeurs@ca.auf.org'),
130 )
131
132 MANAGERS = ADMINS
133
134 TIME_ZONE = 'America/Montreal'
135
136 LANGUAGE_CODE = 'fr-ca'
137
138 MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media')
139 MEDIA_URL = '/media/'
140
141 STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static')
142 STATIC_URL = '/static/'
143
144 # Don't share this with anybody.
145 SECRET_KEY = '%(secret)s'
146
147 ROOT_URLCONF = '%(urlconf)s'
148
149 INSTALLED_APPS = (
150 'auf.django.skin',
151 'admin_tools',
152 'admin_tools.theming',
153 'admin_tools.menu',
154 'admin_tools.dashboard',
155 'django.contrib.auth',
156 'django.contrib.contenttypes',
157 'django.contrib.sessions',
158 'django.contrib.admin',
159 'django.contrib.staticfiles',
160 'south',
161 )
162
163 TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_TEMPLATE_CONTEXT_PROCESSORS + (
164 'django.core.context_processors.static',
165 'django.core.context_processors.request',
166 'auf.django.skin.context_processors.auf',
167 )
168
169
170 TEMPLATE_DIRS = (
171 os.path.join(os.path.dirname(__file__), "templates"),
172 )
173
174 SOUTH_TESTS_MIGRATE = False
175
176 ADMIN_TOOLS_INDEX_DASHBOARD = 'project.dashboard.CustomIndexDashboard'
177
178 from conf import *
179 '''
180
181 ################################################################################
182 # DEVELOPPEMENT
183 ################################################################################
184 auf_development_settings = '''# -*- encoding: utf-8 -*-
185
186 from %(project)s.settings import *
187 DEBUG=True
188 TEMPLATE_DEBUG=DEBUG
189
190 # Décommentez ces lignes pour activer la debugtoolbar
191 #INTERNAL_IPS = ('127.0.0.1',)
192 #INSTALLED_APPS += ('debug_toolbar',)
193 #MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
194
195 AUTH_PASSWORD_REQUIRED = False
196 '''
197
198 ################################################################################
199 # PRODUCTION
200 ################################################################################
201 auf_production_settings = ''' # -*- encoding: utf-8 -*-
202
203 # En production, rediriger la sortie terminal on disponible en WSGI
204 # vers la sortie fichier errorlog.
205 import sys
206 sys.stdout = sys.stderr
207
208 from %(project)s.settings import *
209 '''