Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/pootle_it/settings.py
blob: be1537cea87ecdb9d701d7275cd6a596bbf0daad (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2008-2009 Zuza Software Foundation
#
# This file is part of Pootle.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

"""This is a standard module defining some Django settings, as well as some
settings specific to Pootle.

Note that some of this can also be specified in localsettings.py in order to have a
configuration override outside of the code."""

import logging
import os

from pootle.install_dirs import *

INTERNAL_IPS = ('127.0.0.1',)
ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

# dummy translate function so we can extract text
_ = lambda x: x

TITLE = _("Pootle It Demo")

#l10n: Change the language code (en) to your language code, and replace ltr with rtl if you language is written from right to left.
DESCRIPTION = _("""
""")

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Africa/Johannesburg'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join('src', 'pootle_it', 'html')+'/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/html/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
# TODO: We should find a way to reset this for new installations.
SECRET_KEY = '^&4$dlpce2_pnronsi289xd7-9ke10q_%wa@9srm@zaa!ig@1k'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'pootle_misc.middleware.baseurl.BaseUrlMiddleware', # resolves paths
    'django.middleware.transaction.TransactionMiddleware', # needs to be before anything that writes to the db
    'pootle_misc.middleware.siteconfig.SiteConfigMiddleware', # must be early to detect the need to install or update schema, but must precede the cache middleware
    'django.middleware.cache.UpdateCacheMiddleware', # must be as high as possible (see above)
    'django.middleware.http.ConditionalGetMiddleware', # support for e-tag
    'django.middleware.gzip.GZipMiddleware', # compress responses
    'django.contrib.csrf.middleware.CsrfMiddleware', # protection against cross-site request forgery
    'django.contrib.sessions.middleware.SessionMiddleware', # must be before authentication
    'django.contrib.auth.middleware.AuthenticationMiddleware', # must be before anything user-related
    'django.middleware.locale.LocaleMiddleware', # user-related
    'pootle.middleware.setlocale.SetLocale', # sets Python's locale based on request's locale for sorting, etc.
    'pootle_misc.middleware.errorpages.ErrorPagesMiddleware', # nice 500 and 403 pages (must be after locale to have translated versions)
    'django.middleware.common.CommonMiddleware',
    #'pootle.middleware.check_cookies.CheckCookieMiddleware',
    'pootle.middleware.captcha.CaptchaMiddleware', # must be early in the response cycle (close to bottom)
    #'pootle.middleware.profile.ProfilerMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware' # must be last in the request cycle (at the bottom)
)

CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

ROOT_URLCONF = 'pootle.urls'

TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
                               "django.core.context_processors.i18n",
                               "django.core.context_processors.media",
                               "django.core.context_processors.request",
                               "pootle_misc.context_processors.pootle_context")

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    data_path('templates'),
)

INSTALLED_APPS = (
    'django.contrib.sessions',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sites',
    'django.contrib.admin',
    'pootle_app',
    'pootle_misc',
    'pootle_store',
    'pootle_language',
    'pootle_project',
    'pootle_translationproject',
    'pootle_profile',
    'pootle_statistics',
    'pootle_notifications',
    'pootle_autonotices',
    'pootle_terminology',
    'registration',
    'profiles',
    'djblets.siteconfig',
    'djblets.util',
    'contact_form_i18n',
    'gunicorn',
)

AUTH_PROFILE_MODULE = "pootle_profile.PootleProfile"

ENABLE_ALT_SRC = True

# number of rows in top contributors table
TOPSTAT_SIZE = 5

# django-registration configs
ACCOUNT_ACTIVATION_DAYS = 10

# keep stats cache for roughly a month
OBJECT_CACHE_TIMEOUT = 2500000

# terminology config
MIN_AUTOTERMS = 60
MAX_AUTOTERMS = 600

# defaults for localsettings vars
CONTACT_EMAIL = None
USE_CAPTCHA = False
AUTOSYNC = False
MT_BACKENDS = ()
CAN_CONTACT = True

# By default Pootle sends only text emails. If your organization would
# prefer to send mixed HTML/TEXT emails, set this to True, and update
# activation_email.txt and activation_email.html in the templates/registration/
# directory.
# NOTE: Password reset emails will still be sent in plain text. This is a limitation
# of the underlying system.
EMAIL_SEND_HTML = False

execfile(os.path.join("src", "pootle_it", "localsettings.py"))

if CONTACT_EMAIL:
    MANAGERS += (('CONTACT', CONTACT_EMAIL),)

if LIVE_TRANSLATION:
    # Look for localization files under PODIRECTORY/pootle
    LOCALE_PATHS = (os.path.join(PODIRECTORY, "pootle"), )
else:
    # look for localization files under mo directory
    LOCALE_PATHS = (data_path("mo"), )

from pootle.i18n import override, gettext_live, gettext
from django.utils import translation
from django.utils.translation import trans_real

LANGUAGES = override.find_languages(LOCALE_PATHS[0])

def hijack_translation():
    """sabotage django's fascist linguistical regime"""
    # override functions that check if language if language is
    # known to Django
    translation.check_for_language = lambda lang_code: True
    trans_real.check_for_language = lambda lang_code: True
    translation.get_language_from_request = override.get_language_from_request

    # override django's inadequate bidi detection
    translation.get_language_bidi = override.get_language_bidi

    if LIVE_TRANSLATION:
        trans_real.translation = override.translation_dummy
        override.override_gettext(gettext_live)
    else:
        # even when live translation is not enabled we hijack
        # gettext functions to install the safe variable
        # formatting override
        override.override_gettext(gettext)

hijack_translation()


# setup a tempdir inside the PODIRECTORY heirarchy, this way we have
# reasonable guarantee that temp files will be created on the same
# filesystem as translation files (required for save operations).
import tempfile
tempfile.tempdir = os.path.join(PODIRECTORY, ".tmp")
# ensure that temp dir exists
if not os.path.exists(tempfile.tempdir):
    os.mkdir(tempfile.tempdir)

TEMPLATE_DEBUG = DEBUG
if TEMPLATE_DEBUG:
    TEMPLATE_CONTEXT_PROCESSORS += ("django.core.context_processors.debug",)

if DEBUG:
    logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s',
            )
else:
    # Will log only CRITICAL errors to the console
    logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s %(levelname)s %(message)s',
            )


# cache template loading to reduce IO strain
if not DEBUG:
    template_cache = {}
    def cache_templates(f):
        def decorated_f(template_name):
            if template_name not in template_cache:
                template_cache[template_name] = f(template_name)
            return template_cache[template_name]
        return decorated_f

    from django.template import loader
    loader.get_template = cache_templates(loader.get_template)