-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
1815 lines (1646 loc) · 62.5 KB
/
common.py
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Django settings for kuma project.
import json
import os
import platform
import re
from collections import namedtuple
from os.path import dirname
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
import dj_database_url
import dj_email_url
from decouple import config, Csv
_Language = namedtuple("Language", "english native")
def path(*parts):
return os.path.join(BASE_DIR, *parts)
DEBUG = config("DEBUG", default=False, cast=bool)
# BASE_DIR used by django-extensions, such as ./manage.py notes
# ROOT used by some Kuma application code
BASE_DIR = ROOT = dirname(dirname(dirname(os.path.abspath(__file__))))
ADMIN_EMAILS = config("ADMIN_EMAILS", default="mdn-dev@mozilla.com", cast=Csv())
ADMINS = zip(config("ADMIN_NAMES", default="MDN devs", cast=Csv()), ADMIN_EMAILS)
PROTOCOL = config("PROTOCOL", default="https://")
DOMAIN = config("DOMAIN", default="developer.mozilla.org")
SITE_URL = config("SITE_URL", default=PROTOCOL + DOMAIN)
PRODUCTION_DOMAIN = "developer.mozilla.org"
PRODUCTION_URL = "https://" + PRODUCTION_DOMAIN
STAGING_DOMAIN = "developer.allizom.org"
STAGING_URL = "https://" + STAGING_DOMAIN
_PROD_INTERACTIVE_EXAMPLES = "https://interactive-examples.mdn.mozilla.net"
INTERACTIVE_EXAMPLES_BASE = config(
"INTERACTIVE_EXAMPLES_BASE", default=_PROD_INTERACTIVE_EXAMPLES
)
MAINTENANCE_MODE = config("MAINTENANCE_MODE", default=False, cast=bool)
REVISION_HASH = config("REVISION_HASH", default="undefined")
MANAGERS = ADMINS
# CONN_MAX_AGE: 'persistent' to keep open connection, or max seconds before
# releasing. Default is 0 for a new connection per request.
def parse_conn_max_age(value):
try:
return int(value)
except ValueError:
assert value.lower() == "persistent", 'Must be int or "persistent"'
return None
CONN_MAX_AGE = config("CONN_MAX_AGE", default=60, cast=parse_conn_max_age)
DEFAULT_DATABASE = config(
"DATABASE_URL",
default="mysql://kuma:kuma@localhost:3306/kuma",
cast=dj_database_url.parse,
)
if "mysql" in DEFAULT_DATABASE["ENGINE"]:
# These are the production settings for OPTIONS.
DEFAULT_DATABASE.update(
{
"CONN_MAX_AGE": CONN_MAX_AGE,
"OPTIONS": {
"charset": "utf8",
"use_unicode": True,
"init_command": "SET "
"innodb_strict_mode=1,"
"storage_engine=INNODB,"
"sql_mode='STRICT_TRANS_TABLES',"
"character_set_connection=utf8,"
"collation_connection=utf8_general_ci",
},
"TEST": {"CHARSET": "utf8", "COLLATION": "utf8_general_ci"},
}
)
DATABASES = {
"default": DEFAULT_DATABASE,
}
SILENCED_SYSTEM_CHECKS = [
"django_mysql.W003",
# As of django-recaptcha==2.0.4 it checks that you have set either
# settings.RECAPTCHA_PRIVATE_KEY or settings.RECAPTCHA_PUBLIC_KEY.
# If you haven't it assumes to use the default test keys (from Google).
# We don't set either of these keys so they think we haven't thought
# about using real values. However, we use django-constance for this
# and not django.conf.settings so the warning doesn't make sense to us.
"captcha.recaptcha_test_key_error",
]
# Cache Settings
CACHE_PREFIX = "kuma"
CACHE_COUNT_TIMEOUT = 60 # in seconds
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"TIMEOUT": CACHE_COUNT_TIMEOUT * 60,
"KEY_PREFIX": CACHE_PREFIX,
"LOCATION": config("REDIS_CACHE_SERVER", default="127.0.0.1:6379"),
}
}
# Email
vars().update(config("EMAIL_URL", default="console://", cast=dj_email_url.parse))
EMAIL_SUBJECT_PREFIX = config("EMAIL_SUBJECT_PREFIX", default="[mdn]")
# Ensure EMAIL_SUBJECT_PREFIX has one trailing space
EMAIL_SUBJECT_PREFIX = EMAIL_SUBJECT_PREFIX.strip() + " "
# Addresses email comes from
DEFAULT_FROM_EMAIL = config(
"DEFAULT_FROM_EMAIL", default="notifications@developer.mozilla.org"
)
SERVER_EMAIL = config("SERVER_EMAIL", default="server-error@developer.mozilla.org")
PLATFORM_NAME = platform.node()
# 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 = "US/Pacific"
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-US"
# Accepted locales.
# The order of some codes is important. For example, 'pt-PT' comes before
# 'pt-BR', so that 'pt-PT' will be selected when the generic 'pt' is requested.
# Candidate locales should be included here and in CANDIDATE_LOCALES
ACCEPTED_LOCALES = (
"en-US", # English
"ar", # Arabic
"bg", # Bulgarian
"bm", # Bambara
"bn", # Bengali
"ca", # Catalan
"de", # German
"el", # Greek
"es", # Spanish
"fa", # Persian
"fi", # Finnish
"fr", # French
"he", # Hebrew
"hi-IN", # Hindi (India)
"hu", # Hungarian
"id", # Indonesian
"it", # Italian
"ja", # Japanese
"kab", # Kabyle
"ko", # Korean
"ms", # Malay
"my", # Burmese
"nl", # Dutch
"pl", # Polish
"pt-PT", # Portuguese (Portugal)
"pt-BR", # Portuguese (Brazil)
"ru", # Russian
"sv-SE", # Swedish (Sweden)
"th", # Thai
"tr", # Turkish
"uk", # Ukranian
"vi", # Vietnamese
"zh-CN", # Chinese (China)
"zh-TW", # Chinese (Taiwan, Province of China)
)
# When there are multiple options for a given language, this gives the
# preferred locale for that language (language => preferred locale).
PREFERRED_LOCALE = {
"pt": "pt-PT",
"zh": "zh-CN",
}
# Locales being considered for MDN. This makes the UI strings available for
# localization in Pontoon, but pages can not be translated into this language.
# https://developer.mozilla.org/en-US/docs/MDN/Contribute/Localize/Starting_a_localization
# These should be here and in the ACCEPTED_LOCALES list
CANDIDATE_LOCALES = ()
# Asserted here to avoid a unit test that is skipped when empty
for candidate in CANDIDATE_LOCALES:
assert candidate in ACCEPTED_LOCALES
ENABLE_CANDIDATE_LANGUAGES = config(
"ENABLE_CANDIDATE_LANGUAGES", default=DEBUG, cast=bool
)
if ENABLE_CANDIDATE_LANGUAGES:
ENABLED_LOCALES = ACCEPTED_LOCALES[:]
else:
ENABLED_LOCALES = [
locale for locale in ACCEPTED_LOCALES if locale not in CANDIDATE_LOCALES
]
RTL_LANGUAGES = ("ar", "fa", "he")
# Override generic locale handling with explicit mappings.
# Keys are the requested locale (lowercase); values are the delivered locale.
LOCALE_ALIASES = {
# Create aliases for over-specific locales.
"cn": "zh-CN",
# Create aliases for locales which use region subtags to assume scripts.
"zh-hans": "zh-CN",
"zh-hant": "zh-TW",
# Map locale whose region subtag is separated by `_`(underscore)
"zh_cn": "zh-CN",
"zh_tw": "zh-TW",
}
LANGUAGE_URL_MAP = dict([(i.lower(), i) for i in ENABLED_LOCALES])
for requested_lang, delivered_lang in LOCALE_ALIASES.items():
if delivered_lang in ENABLED_LOCALES:
LANGUAGE_URL_MAP[requested_lang.lower()] = delivered_lang
def _get_locales():
"""
Load LOCALES data from languages.json
languages.json is from the product-details project:
https://product-details.mozilla.org/1.0/languages.json
"""
lang_path = path("kuma", "settings", "languages.json")
with open(lang_path, "r") as lang_file:
json_locales = json.load(lang_file)
locales = {}
for locale, meta in json_locales.items():
locales[locale] = _Language(meta["English"], meta["native"])
return locales
LOCALES = _get_locales()
LANGUAGES = [(locale, LOCALES[locale].native) for locale in ENABLED_LOCALES]
# Language list sorted for forms (English, then alphabetical by locale code)
SORTED_LANGUAGES = [LANGUAGES[0]] + sorted(LANGUAGES[1:])
# List of MindTouch locales mapped to Kuma locales.
#
# Language in MindTouch pages are first determined from the locale in the page
# title, with a fallback to the language in the page record.
#
# So, first MindTouch locales were inventoried like so:
#
# mysql --skip-column-names -uroot wikidb -B \
# -e 'select page_title from pages where page_namespace=0' \
# > page-titles.txt
#
# grep '/' page-titles.txt | cut -d'/' -f1 | sort -f | uniq -ci | sort -rn
#
# Then, the database languages were inventoried like so:
#
# select page_language, count(page_id) as ct
# from pages group by page_language order by ct desc;
#
# Also worth noting, these are locales configured in the prod Control Panel:
#
# en,ar,ca,cs,de,el,es,fa,fi,fr,he,hr,hu,it,ja,
# ka,ko,nl,pl,pt,ro,ru,th,tr,uk,vi,zh-cn,zh-tw
#
# The Kuma side was picked from elements of the MDN_LANGUAGES list in
# settings.py, and a few were added to match MindTouch locales.
#
# Most of these end up being direct mappings, but it's instructive to go
# through the mapping exercise.
MT_TO_KUMA_LOCALE_MAP = {
"en": "en-US",
"ja": "ja",
"pl": "pl",
"fr": "fr",
"es": "es",
"": "en-US",
"cn": "zh-CN",
"zh_cn": "zh-CN",
"zh-cn": "zh-CN",
"zh_tw": "zh-TW",
"zh-tw": "zh-TW",
"ko": "ko",
"pt": "pt-PT",
"de": "de",
"it": "it",
"ca": "ca",
"ru": "ru",
"nl": "nl",
"hu": "hu",
"he": "he",
"el": "el",
"fi": "fi",
"tr": "tr",
"vi": "vi",
"ar": "ar",
"th": "th",
"fa": "fa",
}
LANGUAGE_COOKIE_DOMAIN = DOMAIN
# The number of seconds we are keeping the language preference cookie. (1 year)
LANGUAGE_COOKIE_AGE = 365 * 24 * 60 * 60
SITE_ID = config("SITE_ID", default=1, cast=int)
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (path("locale"),)
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = config("MEDIA_ROOT", default=path("media"))
# 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 = config("MEDIA_URL", default="/media/")
STATIC_URL = config("STATIC_URL", default="/static/")
STATIC_ROOT = path("static")
SERVE_MEDIA = False
# Serve diagrams, presentations, and samples from 2005-2012
SERVE_LEGACY = config("SERVE_LEGACY", default=False, cast=bool)
LEGACY_ROOT = config("LEGACY_ROOT", default=None)
# Paths that don't require a locale prefix.
LANGUAGE_URL_IGNORED_PATHS = (
"healthz",
"readiness",
"media",
"admin",
"robots.txt",
"contribute.json",
"services",
"static",
"1",
"files",
"@api",
"__debug__",
".well-known",
"users/github/login/callback/",
"favicon.ico",
"_kuma_status.json",
# Legacy files, circa 2008, served in AWS
"diagrams",
"presentations",
"samples",
# Legacy files, circa 2008, now return 404
"patches",
"web-tech",
"css",
"index.php", # Legacy MediaWiki endpoint, return 404
# Served in AWS
"sitemap.xml",
"sitemaps/",
"i18n",
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = config(
"SECRET_KEY", default="#%tc(zja8j01!r#h_y)=hy!^k)9az74k+-ib&ij&+**s3-e^_z"
)
_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.request",
"django.template.context_processors.csrf",
"django.contrib.messages.context_processors.messages",
"kuma.core.context_processors.global_settings",
"kuma.core.context_processors.i18n",
"kuma.core.context_processors.next_url",
"constance.context_processors.config",
)
MIDDLEWARE = (
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
# must come before LocaleMiddleware
"redirect_urls.middleware.RedirectsMiddleware",
"kuma.core.middleware.SetRemoteAddrFromForwardedFor",
(
"kuma.core.middleware.ForceAnonymousSessionMiddleware"
if MAINTENANCE_MODE
else "django.contrib.sessions.middleware.SessionMiddleware"
),
"kuma.core.middleware.LangSelectorMiddleware",
"kuma.core.middleware.LocaleStandardizerMiddleware",
# LocaleMiddleware must be before any middleware that uses
# kuma.core.urlresolvers.reverse() to add locale prefixes to URLs:
"kuma.core.middleware.LocaleMiddleware",
"kuma.wiki.middleware.ReadOnlyMiddleware",
"kuma.core.middleware.Forbidden403Middleware",
"ratelimit.middleware.RatelimitMiddleware",
"django.middleware.http.ConditionalGetMiddleware",
"django.middleware.common.CommonMiddleware",
"kuma.core.middleware.SlashMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
)
if not MAINTENANCE_MODE:
# We don't want this in maintence mode, as it adds "Cookie"
# to the Vary header, which in turn, kills caching.
MIDDLEWARE += ("django.middleware.csrf.CsrfViewMiddleware",)
MIDDLEWARE += (
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"kuma.core.middleware.WaffleWithCookieDomainMiddleware",
"kuma.core.middleware.RestrictedEndpointsMiddleware",
)
CSP_ENABLE_MIDDLEWARE = config("CSP_ENABLE_MIDDLEWARE", default=False, cast=bool)
if CSP_ENABLE_MIDDLEWARE:
# For more config, see "Content Security Policy (CSP)" below
MIDDLEWARE += ("csp.middleware.CSPMiddleware",)
ENABLE_QUERYCOUNT = config("ENABLE_QUERYCOUNT", default=False, cast=bool)
if ENABLE_QUERYCOUNT:
# Prints heavy query counts per request.
QUERYCOUNT = {
"IGNORE_REQUEST_PATTERNS": [r"^/admin/"],
"DISPLAY_DUPLICATES": config(
"QUERYCOUNT_DISPLAY_DUPLICATES", cast=int, default=0
),
}
MIDDLEWARE += ("querycount.middleware.QueryCountMiddleware",)
# Auth
AUTHENTICATION_BACKENDS = (
"kuma.users.auth_backends.KumaAuthBackend", # Handles User Bans
"allauth.account.auth_backends.AuthenticationBackend", # Legacy
)
AUTH_USER_MODEL = "users.User"
if urlsplit(STATIC_URL).hostname in (None, "localhost"):
# Avatar needs a publicly available default image
DEFAULT_AVATAR = PRODUCTION_URL + "/static/img/avatar.png"
else:
DEFAULT_AVATAR = STATIC_URL + "img/avatar.png"
ROOT_URLCONF = "kuma.urls"
CKEDITOR_DEV = config("CKEDITOR_DEV", default=False, cast=bool)
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"pipeline.finders.CachedFileFinder",
"pipeline.finders.PipelineFinder",
)
STATICFILES_STORAGE = (
"pipeline.storage.NonPackagingPipelineStorage"
if DEBUG
else "kuma.core.pipeline.storage.ManifestPipelineStorage"
)
STATICFILES_DIRS = [
path("assets", "static"),
path("kuma", "static"),
path("kuma", "javascript", "dist"),
path("build", "locale"),
path("jinja2", "includes/icons"),
("js/libs/ckeditor4/build", path("assets", "ckeditor4", "build")),
]
if CKEDITOR_DEV:
STATICFILES_DIRS.append(
("js/libs/ckeditor4/source", path("assets", "ckeditor4", "source"))
)
# TODO: Figure out why changing the order of apps (for example, moving taggit
# higher in the list) breaks tests.
INSTALLED_APPS = (
# django
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.admin",
"django.contrib.sitemaps",
"django.contrib.staticfiles",
"soapbox", # must be before kuma.wiki, or RemovedInDjango19Warning
# MDN
"kuma.payments.apps.PaymentsConfig",
"kuma.core.apps.CoreConfig",
"kuma.banners",
"kuma.feeder.apps.FeederConfig",
"kuma.landing",
"kuma.redirects",
"kuma.scrape",
"kuma.search.apps.SearchConfig",
"kuma.users.apps.UserConfig",
"kuma.wiki.apps.WikiConfig",
"kuma.api.apps.APIConfig",
"kuma.attachments.apps.AttachmentsConfig",
"allauth",
"allauth.account",
"allauth.socialaccount",
"kuma.users.providers.github",
"kuma.users.providers.google",
# util
"django_jinja",
"pipeline",
"puente",
"constance.backends.database",
"constance",
"waffle",
"kuma.authkeys",
"tidings",
"taggit",
"honeypot",
"cacheback",
"django_extensions",
"kuma.dashboards",
"statici18n",
"rest_framework",
"rest_framework.authtoken",
"django_mysql",
# other
"redirect_urls",
)
# Feed fetcher config
FEEDER_TIMEOUT = 6 # in seconds
TEMPLATES = [
{
"NAME": "jinja2",
"BACKEND": "django_jinja.backend.Jinja2",
"DIRS": [path("jinja2"), path("static")],
"APP_DIRS": True,
"OPTIONS": {
# Use jinja2/ for jinja templates
"app_dirname": "jinja2",
# Don't figure out which template loader to use based on
# file extension
"match_extension": "",
"newstyle_gettext": True,
"context_processors": _CONTEXT_PROCESSORS,
"undefined": "jinja2.Undefined",
"extensions": [
"jinja2.ext.do",
"jinja2.ext.loopcontrols",
"jinja2.ext.i18n",
"puente.ext.i18n",
"django_jinja.builtins.extensions.CsrfExtension",
"django_jinja.builtins.extensions.CacheExtension",
"django_jinja.builtins.extensions.TimezoneExtension",
"django_jinja.builtins.extensions.UrlsExtension",
"django_jinja.builtins.extensions.StaticFilesExtension",
"django_jinja.builtins.extensions.DjangoFiltersExtension",
"pipeline.jinja2.PipelineExtension",
"waffle.jinja.WaffleExtension",
"kuma.core.i18n.TranslationExtension",
],
},
},
{
"NAME": "django",
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [path("templates")],
"APP_DIRS": False,
"OPTIONS": {
"debug": DEBUG,
"context_processors": _CONTEXT_PROCESSORS,
"loaders": [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
},
},
]
PUENTE = {
"VERSION": "2020.04",
"BASE_DIR": BASE_DIR,
"TEXT_DOMAIN": "django",
# Tells the extract script what files to look for l10n in and what function
# handles the extraction.
"DOMAIN_METHODS": {
"django": [
("kumascript/node_modules/**", "ignore"),
("kuma/**.py", "python"),
("**/templates/**.html", "django_babel.extract.extract_django"),
("**/jinja2/**.html", "jinja2"),
("**/jinja2/**.ltxt", "jinja2"),
],
"javascript": [
# We can't say **.js because that would dive into any libraries.
("kuma/static/js/*.js", "javascript"),
("kuma/static/js/components/**.js", "javascript"),
("assets/ckeditor4/source/plugins/mdn-**/*.js", "javascript"),
],
"react": [
("kuma/javascript/src/**.js", "javascript"),
("kuma/javascript/src/**.jsx", "javascript"),
],
},
"PROJECT": "MDN",
"MSGID_BUGS_ADDRESS": ADMIN_EMAILS[0],
}
# Combine JavaScript strings into React domain
PUENTE["DOMAIN_METHODS"]["react"] = (
PUENTE["DOMAIN_METHODS"]["javascript"] + PUENTE["DOMAIN_METHODS"]["react"]
)
STATICI18N_ROOT = "build/locale"
STATICI18N_DOMAIN = "javascript"
# Cache non-versioned static files for one week
WHITENOISE_MAX_AGE = 60 * 60 * 24 * 7
def pipeline_scss(output, sources, **kwargs):
"""Define a CSS file generated from multiple SCSS files."""
definition = {
"source_filenames": tuple("styles/%s.scss" % src for src in sources),
"output_filename": "build/styles/%s.css" % output,
}
definition.update(kwargs)
return definition
def pipeline_one_scss(slug, **kwargs):
"""Define a CSS file that shares the name with the one input SCSS."""
return pipeline_scss(slug, [slug], **kwargs)
PIPELINE_CSS = {
# Combines the mdn, wiki and wiki-compat-tables styles into
# one bundle for use by pages that are part of the new
# single page app.
"react-mdn": {
"source_filenames": ("styles/react-mdn.scss",),
"output_filename": "build/styles/react-mdn.css",
},
"react-header": {
"source_filenames": ("styles/minimalist/organisms/header.scss",),
"output_filename": "build/styles/react-header.css",
},
"react-search": {
"source_filenames": ("styles/minimalist/search-page.scss",),
"output_filename": "build/styles/react-search.css",
},
"mdn": {
"source_filenames": ("styles/main.scss",),
"output_filename": "build/styles/mdn.css",
},
"banners": {
"source_filenames": ("styles/components/banners/base.scss",),
"output_filename": "build/styles/banners.css",
},
"home": {
"source_filenames": ("styles/home.scss",),
"output_filename": "build/styles/home.css",
},
"home_base": {
"source_filenames": ("styles/minimalist/home.scss",),
"output_filename": "build/styles/home_base.css",
},
"callout": {
"source_filenames": ("styles/minimalist/components/callout.scss",),
"output_filename": "build/styles/callout.css",
},
"home_newsletter": {
"source_filenames": ("styles/minimalist/components/home-newsletter.scss",),
"output_filename": "build/styles/home_newsletter.css",
},
"mozilla_foundation": {
"source_filenames": (
"styles/minimalist/components/featured-banners/mozilla-foundation.scss",
),
"output_filename": "build/styles/mozilla_foundation.css",
},
"home_featured": {
"source_filenames": (
"styles/minimalist/components/featured-banners/featured.scss",
),
"output_filename": "build/styles/home_featured.css",
},
"print": {
"source_filenames": ("styles/minimalist/print.scss",),
"output_filename": "build/styles/print.css",
"extra_context": {"media": "print"},
},
"search": {
"source_filenames": ("styles/search.scss",),
"output_filename": "build/styles/search.css",
},
"wiki": {
"source_filenames": ("styles/wiki.scss",),
"output_filename": "build/styles/wiki.css",
},
"wiki-revisions": {
"source_filenames": ("styles/wiki-revisions.scss",),
"output_filename": "build/styles/wiki-revisions.css",
},
"wiki-edit": {
"source_filenames": ("styles/wiki-edit.scss",),
"output_filename": "build/styles/wiki-edit.css",
},
"wiki-compat-tables": {
"source_filenames": ("styles/wiki-compat-tables.scss",),
"output_filename": "build/styles/wiki-compat-tables.css",
"template_name": "pipeline/javascript-array.jinja",
},
"users": {
"source_filenames": ("styles/users.scss",),
"output_filename": "build/styles/users.css",
},
"delete-user-modal": {
"source_filenames": ("styles/minimalist/components/delete-user-modal.scss",),
"output_filename": "build/styles/delete-user-modal.css",
},
"tagit": {
"source_filenames": ("styles/libs/jquery.tagit.css",),
"output_filename": "build/styles/tagit.css",
},
"promote": {
"source_filenames": ("styles/promote.scss",),
"output_filename": "build/styles/promote.css",
},
"error": {
"source_filenames": ("styles/error.scss",),
"output_filename": "build/styles/error.css",
},
"error-404": {
"source_filenames": ("styles/error-404.scss",),
"output_filename": "build/styles/error-404.css",
},
"dashboards": {
"source_filenames": ("styles/dashboards.scss",),
"output_filename": "build/styles/dashboards.css",
},
"submission": {
"source_filenames": ("styles/submission.scss",),
"output_filename": "build/styles/submission.css",
},
"signupflow": {
"source_filenames": ("styles/minimalist/structure/signup-flow.scss",),
"output_filename": "build/styles/signup-flow.css",
},
"auth-modal": {
"source_filenames": ("styles/minimalist/components/auth-modal.scss",),
"output_filename": "build/styles/auth-modal.css",
},
"user-banned": {
"source_filenames": ("styles/user-banned.scss",),
"output_filename": "build/styles/user-banned.css",
},
"user-delete": {
"source_filenames": ("styles/user-delete.scss",),
"output_filename": "build/styles/user-delete.css",
},
"stripe-subscription": {
"source_filenames": ("styles/stripe-subscription.scss",),
"output_filename": "build/styles/stripe-subscription.css",
},
"error-403-alternate": {
"source_filenames": ("styles/error-403-alternate.scss",),
"output_filename": "build/styles/error-403-alternate.css",
},
"editor-content": {
"source_filenames": ("styles/editor-content.scss",),
"output_filename": "build/styles/editor-content.css",
"template_name": "pipeline/javascript-array.jinja",
},
# for maintenance mode page
"maintenance-mode": {
"source_filenames": ("styles/maintenance-mode.scss",),
"output_filename": "build/styles/maintenance-mode.css",
},
# global maintenance-mode-styles
"maintenance-mode-global": {
"source_filenames": ("styles/maintenance-mode-global.scss",),
"output_filename": "build/styles/maintenance-mode-global.css",
},
# embeded iframe for live samples
"samples": {
"source_filenames": ("styles/samples.scss",),
"output_filename": "build/styles/samples.css",
},
"prism": {
"source_filenames": (
"styles/libs/prism/prism.css",
"styles/libs/prism/prism-line-highlight.css",
"styles/libs/prism/prism-line-numbers.css",
),
"output_filename": "build/styles/prism.css",
},
"jquery-ui": {
"source_filenames": (
"js/libs/jquery-ui-1.10.3.custom/css/ui-lightness/jquery-ui-1.10.3.custom.min.css",
"styles/libs/jqueryui/moz-jquery-plugins.css",
"css/jquery-ui-customizations.scss",
),
"output_filename": "build/styles/jquery-ui.css",
},
}
# Locales that are well supported by the Zilla family
LOCALE_USE_ZILLA = [
"ca",
"de",
"en-US",
"es",
"fi",
"fr",
"hu",
"id",
"it",
"kab",
"ms",
"nl",
"pl",
"pt-BR",
"pt-PT",
"sv-SE",
]
PIPELINE_JS = {
"main": {
"source_filenames": (
"js/libs/jquery/jquery.js",
"js/libs/jquery-ajax-prefilter.js",
"js/libs/icons.js",
"js/components.js",
"js/analytics.js",
"js/main.js",
"js/components/nav-main-search.js",
"js/auth.js",
"js/highlight.js",
"js/wiki-compat-trigger.js",
"js/lang-switcher.js",
),
"output_filename": "build/js/main.js",
},
"react-main": {
"source_filenames": (
# TODO: these are the last legacy files from the wiki site
# that we're still using on the React-based pages. Ideally
# we should just move these to the React code so webpack
# can deal with them.
"js/utils/post-message-handler.js",
"js/analytics.js",
# Custom Prism build
# TODO: the prism.js file should be imported dynamcally
# when we need it instead of being hardcoded in here.
"js/libs/prism/prism-core.js",
"js/libs/prism/prism-bash.js",
"js/libs/prism/prism-markup.js",
"js/libs/prism/prism-css.js",
"js/libs/prism/prism-clike.js",
"js/libs/prism/prism-javascript.js",
"js/libs/prism/prism-json.js",
"js/libs/prism/prism-jsonp.js",
"js/libs/prism/prism-css-extras.js",
"js/libs/prism/prism-rust.js",
"js/libs/prism/prism-wasm.js",
"js/libs/prism/prism-line-highlight.js",
"js/libs/prism/prism-line-numbers.js",
# The react.js file is created by webpack and
# placed in the kuma/javascript/dist/ directory.
"react.js",
),
"output_filename": "build/js/react-main.js",
"extra_context": {"defer": True},
},
"bcd-signal": {
"source_filenames": ("bcd-signal.js",),
"output_filename": "build/js/react-bcd-signal.js",
"extra_context": {"defer": True},
},
"banners": {
"source_filenames": (
"js/components/banners/utils/banners-event-util.js",
"js/components/banners/utils/banners-state-util.js",
"js/components/banners/banners.js",
),
"output_filename": "build/js/banners.js",
"extra_context": {"async": True},
},
"users": {
"source_filenames": (
"js/libs/tag-it.js",
"js/moz-jquery-plugins.js",
"js/users.js",
),
"output_filename": "build/js/users.js",
"extra_context": {"async": True},
},
"user-signup": {
"source_filenames": ("js/components/user-signup/signup.js",),
"output_filename": "build/js/signup.js",
"extra_context": {"async": True},
},
"delete-user-page": {
"source_filenames": (
"js/components/account-management/delete-user-confirmation-button.js",
),
"output_filename": "build/js/delete-user-confirmation-button.js",
"extra_context": {"defer": True},
},
"delete-user-modal": {
"source_filenames": (
"js/components/modal.js",
"js/components/account-management/delete-user-modal.js",
"js/components/account-management/delete-user-confirmation-button.js",
),
"output_filename": "build/js/delete-user-modal.js",
"extra_context": {"defer": True},
},
"auth-modal": {
"source_filenames": (
"js/components/modal.js",
"js/components/user-signup/auth-modal.js",
),
"output_filename": "build/js/auth-modal.js",
"extra_context": {"defer": True},
},
"dashboard": {
"source_filenames": ("js/dashboard.js",),
"output_filename": "build/js/dashboard.js",
"extra_context": {"async": True},
},
"jquery-ui": {
"source_filenames": (
"js/libs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js",
"js/libs/jquery-ajax-prefilter.js",
"js/moz-jquery-plugins.js",
),
"output_filename": "build/js/jquery-ui.js",
},
"search": {
"source_filenames": ("js/search.js",),
"output_filename": "build/js/search.js",
"extra_context": {"async": True},
},
"payments": {
"source_filenames": ("js/components/payments/payments-manage.js",),
"output_filename": "build/js/payments.js",
},
"stripe-subscription": {
"source_filenames": ("js/stripe-subscription.js",),
"output_filename": "build/js/stripe-subscription.js",
},
"framebuster": {
"source_filenames": ("js/framebuster.js",),
"output_filename": "build/js/framebuster.js",
},
"syntax-prism": {
"source_filenames": (
# Custom Prism build
"js/libs/prism/prism-core.js",
"js/libs/prism/prism-bash.js",
"js/libs/prism/prism-markup.js",
"js/libs/prism/prism-css.js",
"js/libs/prism/prism-clike.js",
"js/libs/prism/prism-javascript.js",
"js/libs/prism/prism-json.js",
"js/libs/prism/prism-jsonp.js",
"js/libs/prism/prism-css-extras.js",
"js/libs/prism/prism-rust.js",
"js/libs/prism/prism-wasm.js",
"js/libs/prism/prism-line-highlight.js",
"js/libs/prism/prism-line-numbers.js",
"js/syntax-prism.js",
),
"output_filename": "build/js/syntax-prism.js",
"template_name": "pipeline/javascript-array.jinja",
},
"wiki": {
"source_filenames": (
"js/utils/utils.js",
"js/utils/post-message-handler.js",
"js/wiki.js",
"js/interactive.js",