-
Notifications
You must be signed in to change notification settings - Fork 5
/
base.py
551 lines (478 loc) · 18 KB
/
base.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
"""
Django settings for shopelectro project.
Generated by 'django-admin startproject' using Django 1.9.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
import socket
from collections import defaultdict
from datetime import datetime
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(
os.path.dirname(os.path.abspath(__file__))))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'so_secret_key')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# http://bit.ly/sorl-thumbnail-docs
THUMBNAIL_DEBUG = False
ALLOWED_HOSTS = ['*']
TEST_ENV = os.environ.get('TEST_ENV', False)
if TEST_ENV:
# disable https in CI
# https://docs.djangoproject.com/en/1.9/ref/settings/#secure-proxy-ssl-header
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'http')
# Enable in frame loading for Ya.Metric
# https://docs.djangoproject.com/es/1.10/ref/clickjacking/
# https://yandex.ru/support/metrika/general/counter-webvisor.xml#download-page
X_FRAME_OPTIONS = 'ALLOW-FROM http://webvisor.com'
# Application definition
INSTALLED_APPS = [
# https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.autodiscover
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.messages',
'django.contrib.redirects',
'django.contrib.sessions',
'django.contrib.sitemaps',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django_user_agents',
'django_extensions',
'generic_admin',
'django.contrib.admin.apps.SimpleAdminConfig',
'debug_toolbar',
'mptt',
'widget_tweaks',
'sorl.thumbnail',
'django_select2',
'images',
'refarm_redirects',
'pages',
'catalog',
'search',
'ecommerce',
'refarm_test_utils',
'shopelectro',
]
# Stick to this ordering
# https://docs.djangoproject.com/en/1.11/ref/middleware/#middleware-ordering
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_user_agents.middleware.UserAgentMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'refarm_redirects.middleware.RedirectAllMiddleware',
]
ROOT_URLCONF = 'shopelectro.urls'
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.media',
'django.template.context_processors.request',
'django.template.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'ecommerce.context_processors.cart',
'shopelectro.context_processors.shop',
],
},
},
]
WSGI_APPLICATION = 'shopelectro.wsgi.application'
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LOCALE_NAME = 'en_US'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = [os.path.join(BASE_DIR, 'shopelectro/locale')]
FORMAT_MODULE_PATH = [
'shopelectro.formats',
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
ASSETS_DIR = os.path.join(BASE_DIR, 'assets')
STATICFILES_STORAGE = 'shopelectro.static_storage.DroppedPricesManifestStaticFilesStorage'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'front_build'),
ASSETS_DIR,
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# to activate django connections pool for persistent connections.
# https://docs.djangoproject.com/en/1.11/ref/databases/#persistent-connections
CONN_MAX_AGE = None
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['POSTGRES_DB'],
'USER': os.environ['POSTGRES_USER'],
'PASSWORD': os.environ['POSTGRES_PASSWORD'],
'HOST': os.environ['POSTGRES_URL'],
'PORT': '5432',
}
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'pages': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'catalog': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'search': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'ecommerce': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'images': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'shopelectro': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
},
}
TEST_RUNNER = 'refarm_test_utils.runners.RefarmTestRunner'
# address for selenium-based tests
# CI doesn't resolve a host name, so we have to use the host address
LIVESERVER_HOST = socket.gethostbyname(socket.gethostname())
SITE_CREATED = datetime(2013, 1, 1)
LOCALHOST = 'http://127.0.0.1:8000/'
BASE_URL = 'https://www.shopelectro.ru'
PLACEHOLDER_IMAGE = 'images/logo.png'
PLACEHOLDER_ALT = 'Логотип компании Shopelectro'
# Autocomplete and search settings
SEARCH_SEE_ALL_LABEL = 'Смотреть все результаты'
# For sitemaps and sites framework
SITE_ID = 1
SITE_DOMAIN_NAME = 'www.shopelectro.ru'
# Used to retrieve instances in ecommerce.Cart
CART_ID = 'cart'
# It is fake-pass. Correct pass will be created on `docker-compose up` stage from `docker/.env`
YANDEX_SHOP_PASS = os.environ.get('YANDEX_SHOP_PASS', 'so_secret_pass')
# Used for order's email in ecommerce app
FAKE_ORDER_NUMBER = 6000
# Subjects for different types of emails sent from SE.
EMAIL_SUBJECTS = {
'call': 'Обратный звонок',
'order': 'Заказ №{0.fake_order_number}',
'yandex_order': 'Заказ №{0.fake_order_number} | Яндекс.Касса',
'one_click': 'Заказ в один клик №{0.fake_order_number}',
'ya_feedback_request': 'Оцените нас на Яндекс.Маркете',
}
# Email configs
# It is fake-pass. Correct pass will be created on `docker-compose up` stage from `docker/.env`
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', 'so_secret_pass')
EMAIL_HOST_USER = 'info@shopelectro.ru'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 587
EMAIL_SENDER = 'info@shopelectro.ru'
EMAIL_RECIPIENTS = os.environ.get('EMAIL_RECIPIENTS', 'info@shopelectro.ru').split(',')
# FTP configs
FTP_USER = os.environ.get('FTP_USER', 'user')
FTP_PASS = os.environ.get('FTP_PASS', 'pass')
FTP_IP = os.environ.get('FTP_IP', '0.0.0.0')
ENV_TYPE = os.environ.get('ENV_TYPE', 'PROD') # LOCAL | CI | PROD
# 'Prod' <-> 'Product #1 of Category #0 of Category #1' = 0.17
# About trigram similarity: https://goo.gl/uYFcxN
TRIGRAM_MIN_SIMILARITY = 0.15
# Used in admin image uploads
MODEL_TYPES = {
'Product': {
'app_name': 'shopelectro',
'dir_name': 'products',
},
'Category': {
'app_name': 'shopelectro',
'dir_name': 'categories',
}
}
# This need for using {% debug %} variable in templates.
INTERNAL_IPS = (
'127.0.0.1',
)
TOP_PRODUCTS = [291, 438, 1137, 2166, 2725, 2838, 3288, 3884, 3959, 2764]
CATEGORY_STEP_MULTIPLIERS = [12, 15, 24, 25, 48, 50, 60, 100]
SHOP = {
'id': '69886',
'scid': '64788',
'success_url': BASE_URL + '/shop/order-success/',
'fail_url': BASE_URL + '/',
'cps_phone': '+78124163200',
'cps_formatted_phone': '416-32-00',
'cps_email': 'info@shopelectro.ru',
'local_delivery_cost': 300,
'local_delivery_cost_threshold': 5000,
}
def get_robots_content():
with open(os.path.join(TEMPLATE_DIR, 'robots.txt')) as robots_file:
return robots_file.read()
# @todo #265:60m Move content-based settings to db.
# Content guys should be able to change settings like
# `MAIN_PAGE_TILE` or `FOOTER_LINKS` from admin panel.
# used in data-migrations and tests
CUSTOM_PAGES = {
'index': {
'slug': '',
'name': 'Интернет-магазин элементов питания "ShopElectro"',
'menu_title': 'Главная',
'title': 'Интернет-магазин элементов питания с доставкой по России',
'description': 'Элементы питания в СПб с доставкой по России - интернет-магазин элементов питания ShopElectro',
},
'sitemap': {
'slug': 'sitemap',
'h1': 'Карта сайта',
'name': 'Карта сайта',
},
'order': {
'slug': 'order',
'name': 'Оформление заказа',
'title': 'Корзина Интернет-магазин shopelectro.ru Санкт-Петербург',
},
'search': {
'slug': 'search',
'name': 'Результаты поиска',
},
'catalog': {
'slug': 'catalog',
'name': 'Каталог товаров',
'menu_title': 'Каталог',
},
'order_success': {
'slug': 'order-success',
'name': 'Заказ принят',
},
'robots': {
'slug': 'robots.txt',
'content': get_robots_content(),
},
}
TAGS_URL_DELIMITER = '-or-'
TAG_GROUPS_URL_DELIMITER = '-and-'
TAGS_TITLE_DELIMITER = ' или '
TAG_GROUPS_TITLE_DELIMITER = ' и '
# -- App business logic --
# every product price will be multiplied on this value
# during import from 1C.
# Multipliers are related to prices in this order:
# big/medium/small/retail. First three are wholesale prices.
PRICE_MULTIPLIERS = 1.0, 1.0, 1.0, 1.0
# default for local tests. Prod's one may differ
YANDEX_KASSA_LINK = 'https://money.yandex.ru/eshop.xml'
PRODUCT_SIBLINGS_COUNT = 10
CATEGORY_SORTING_OPTIONS = {
0: {
'label': 'Цене, сначала дешёвые',
'field': 'price',
'direction': ''
},
1: {
'label': 'Цене, сначала дорогие',
'field': 'price',
'direction': '-'
},
2: {
'label': 'Названию, А-Я',
'field': 'name',
'direction': ''
},
3: {
'label': 'Названию, Я-А',
'field': 'name',
'direction': '-'
},
4: {
'label': 'Артикулу',
'field': 'vendor_code',
'direction': ''
},
}
# Tile on main page.
# Every link should have either slug or url.
MAIN_PAGE_TILE = {
'accumulators': [
{'name': 'Типоразмера AA',
'url': '/catalog/categories/akkumuliatory-270/tags/aa/'},
{'name': 'Типоразмера ААА',
'url': '/catalog/categories/akkumuliatory-270/tags/aaa/'},
{'name': 'Для радиомоделей и игрушек',
'slug': 'akkumuliatory-dlia-radioupravliaemykh-modelei-i-igrushek'},
{'name': 'Свинцово-кислотные',
'slug': 'akkumuliatory-svintsovo-kislotnye-4-v-6-v-12-v-lca'},
{'name': 'Внешние универсальные',
'slug': 'vneshnie-universalnye-akkumuliatory'},
{'name': 'Адаптеры, отсеки и футляры',
'slug': 'adaptery-otseki-i-futliary-dlia-akkumuliatorov'},
],
'inverter': [
{'name': 'Инверторы', 'slug': 'invertory'},
{'name': 'Преобразователи DC 24 В/12 В KALLER',
'slug': 'preobrazovateli-napriazheniia-dc-24-v12-v-kaller'},
],
'batteries': [
{'name': 'Типоразмера АА', 'slug': 'batareiki-aa'},
{'name': 'Часовые', 'slug': 'chasovye-batareiki-alkalinovye'},
{'name': 'Дисковые литиевые', 'slug': 'diskovye-litievye-batareiki-3-v'},
],
'lights': [
{'name': 'Ручные', 'url': '/catalog/categories/fonari-226/tags/ruchnoi/'},
{'name': 'Налобные', 'url': '/catalog/categories/fonari-226/tags/nalobnyi/'},
{'name': 'Туристические', 'url': '/categories/fonari-226/tags/kempingovye/'},
{'name': 'Автомобильные', 'slug': 'avtomobilnye-fonari'},
],
'chargers': [
{'name': 'Для фотоаппаратов',
'slug': 'zariadnye-ustroistva-dlia-fotoapparatov'},
{'name': 'Для видеокамер', 'slug': 'zariadnye-ustroistva-dlia-videokamer'},
{'name': 'Для свинцовых',
'slug': 'zariadnye-ustroistva-dlia-svintsovykh-akkumuliatorov'},
],
'multimeters': [
{'name': 'MY68 Master Professional', 'slug': '1411'},
{'name': 'MY67 Master Professional', 'slug': '1692'},
{'name': 'MY64 Master Professional', 'slug': '1407'},
],
'adapters': [
{'id': 1, 'name': '220В для ноутбуков',
'slug': 'bloki-pitaniia-dlia-noutbukov-ot-seti-220v'},
{'id': 1, 'name': '12В для ноутбуков',
'slug': 'bloki-pitaniia-dlia-noutbukov-ot-seti-12v'},
{'id': 1, 'name': 'Трансформаторные',
'slug': 'bloki-pitaniia-transformatornye'},
],
}
# add/exclude logic works only for root menu items
HEADER_LINKS = {
'exclude': ['radiopriiomniki'],
'add': ['remont-akkumulyatorov'],
}
FOOTER_LINKS = {
'services': [
{'name': 'Ремонт аккумуляторов', 'slug': 'remont-akkumulyatorov'},
{'name': 'Пайка на заказ', 'slug': 'soldering'},
{'name': 'Доставка по всей России', 'slug': 'delivery'},
],
'about': [
{'name': 'Реквизиты', 'type': 'navigation', 'slug': 'rekvisity'},
{'name': 'Купить оптом', 'type': 'articles', 'slug': 'wholesale'},
{'name': 'Возврат и гарантии', 'type': 'navigation', 'slug': 'return-goods-instr'},
],
}
BRAND_TAG_GROUP_NAME = 'Производитель'
# products with price lower this value should not be presented at gm.yml price
PRICE_GM_LOWER_BOUND = 200.0
# Online market services, that works with our prices.
# Dict keys - url targets for every service.
# @todo #666:30m Move UTM_PRICE_MAP to an iterable Enum
UTM_PRICE_MAP = {
'YM': 'yandex.yml',
'priceru': 'priceru.xml',
'GM': 'gm.yml',
'SE78': 'se78.yml',
}
PRICE_IGNORED_CATEGORIES_MAP = defaultdict(list, {
'GM': ['Усилители звука для слабослышащих'],
'YM': ['Пиротехника'],
# will be ignored by every category
'default': [
'Измерительные приборы', 'Новогодние вращающиеся светодиодные лампы',
'Новогодние лазерные проекторы', 'MP3- колонки', 'Беспроводные звонки',
'Радиоприёмники', 'Фонари', 'Отвертки', 'Весы электронные портативные',
]
})
# be careful, list of values should contain vendor_codes, not ids
PRICE_IGNORED_PRODUCTS_MAP = defaultdict(list, {
'YM': [1, 2, 3],
})
# Number of pagination neighbors shown for page.
# If PAGINATION_NEIGHBORS = 4 and number of a page = 5,
# then will be shown neighbors by number: 3, 4, 6, 7
PAGINATION_NEIGHBORS = 10
PRODUCTS_ON_PAGE_PC = 48
PRODUCTS_ON_PAGE_MOB = 12
TG_BOT_TOKEN = os.environ.get('TG_BOT_TOKEN')
TG_REPORT_ADDRESSEES = os.environ.get(
'TG_REPORT_ADDRESSEES', '@shopelectro_reports'
).split(',')
CHECK_PURCHASE_RETRIES = int(os.environ.get('CHECK_PURCHASE_RETRIES', '3'))
SENTRY_DSN = os.environ.get('SENTRY_DSN')
SENTRY_FRONT_DSN = os.environ.get('SENTRY_FRONT_DSN')
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[
DjangoIntegration(),
CeleryIntegration(),
]
)
# At 17.05.2019 it's relevant pack group data
PACK_GROUP_UUID = 'ae30f766-0bb8-11e6-80ea-02d2cc20e118'
PACK_GROUP_NAME = 'Упаковка'
WORKING_HOURS = {
'ELIZ': 'пн-чт 10:00-18:00, пт 10:00-17:00',
'JUNO': 'пн 11:00-17:00, вт-вс 10:00-18:00',
}