Merge branch 'master' of gitlab.com:lilschool/site into hotfix/shedules-fix

remotes/origin/hotfix/shedules-fix
gzbender 6 years ago
commit 86bd9dd1bf
  1. 21
      apps/payment/tasks.py
  2. 33
      project/settings.py
  3. 36
      project/views.py

@ -1,5 +1,6 @@
import logging
import requests
import json
from mixpanel import Mixpanel
@ -8,6 +9,7 @@ from django.conf import settings
from project.celery import app
logger = logging.getLogger(__name__)
logger_roistat = logging.getLogger('roistat')
@app.task
@ -53,13 +55,24 @@ def transaction_to_roistat(user_id, payment_id, event_name, amount, time, status
}]
project = settings.ROISTAT_PROJECT
key = settings.ROISTAT_KEY
url = settings.ROISTAT_API_URL + f'/project/add-orders?key={key}&project={project}'
resp = requests.post(url, json=body)
url = settings.ROISTAT_API_URL + \
f'/project/add-orders?key={key}&project={project}'
payload = json.dumps(body)
headers = {'content-type': 'application/json'}
resp = requests.request("POST", url, data=payload, headers=headers)
try:
resp_json = resp.json()
except:
resp_json = None
if resp.status_code != 200 or not resp_json or not resp_json.get('processed'):
logger.error('TRANSACTION_TO_ROISTAT for payment # %d, %s RUB: %s' % (payment_id, amount, resp.text))
logger.error('TRANSACTION_TO_ROISTAT for payment # %d, %s RUB: %s' % (
payment_id, amount, resp.text))
logger_roistat.debug('TRANSACTION_TO_ROISTAT for payment # %d, %s RUB: %s' % (
payment_id, amount, resp.text))
else:
logger.info('TRANSACTION_TO_ROISTAT: ' + str(resp))
logger.info('TRANSACTION_TO_ROISTAT: ' + str(resp.text))
logger_roistat.debug('TRANSACTION_TO_ROISTAT: ' + str(resp.text))

@ -25,7 +25,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('SECRET_KEY', 'jelm*91lj(_-o20+6^a+bgv!4s6e_efry^#+f#=1ak&s1xr-2j')
SECRET_KEY = os.getenv(
'SECRET_KEY', 'jelm*91lj(_-o20+6^a+bgv!4s6e_efry^#+f#=1ak&s1xr-2j')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False)
@ -200,6 +201,12 @@ LOGGING = {
'level': 'WARNING',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/app/media/main.log',
'formatter': 'verbose',
},
},
'loggers': {
'django.request': {
@ -214,9 +221,13 @@ LOGGING = {
'handlers': ['console', ],
},
'': {
'handlers': ['sentry',],
'handlers': ['sentry', ],
'level': "INFO",
},
'roistat': {
'handlers': ['file'],
'level': 'DEBUG'
},
}
}
@ -258,7 +269,8 @@ SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
# SMS
# https://github.com/twilio/twilio-python
TWILIO_ACCOUNT = os.getenv('TWILIO_ACCOUNT', 'ACdf4a96b776cc764bc3ec0f0e136ba550')
TWILIO_ACCOUNT = os.getenv(
'TWILIO_ACCOUNT', 'ACdf4a96b776cc764bc3ec0f0e136ba550')
TWILIO_TOKEN = os.getenv('TWILIO_TOKEN', '559a6b1fce121759c9af2dcbb3f755ea')
TWILIO_FROM_PHONE = os.getenv('TWILIO_FROM_PHONE', '+37128914409')
@ -297,8 +309,10 @@ REST_FRAMEWORK = {
# Celery settings
CELERY_BROKER_URL = os.getenv('REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_BROKER_DB', '0')
CELERY_RESULT_BACKEND = os.getenv('REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_RESULTS_DB', '1')
CELERY_BROKER_URL = os.getenv(
'REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_BROKER_DB', '0')
CELERY_RESULT_BACKEND = os.getenv(
'REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_RESULTS_DB', '1')
CELERY_TASK_SERIALIZER = 'json'
CELERY_BEAT_SCHEDULE = {
@ -350,8 +364,10 @@ except ImportError:
pass
else:
Paymentwall.set_api_type(Paymentwall.API_GOODS)
Paymentwall.set_app_key(os.getenv('PAYMENTWALL_APP_KEY', 'd6f02b90cf6b16220932f4037578aff7'))
Paymentwall.set_secret_key(os.getenv('PAYMENTWALL_SECRET_KEY', '4ea515bf94e34cf28646c2e12a7b8707'))
Paymentwall.set_app_key(
os.getenv('PAYMENTWALL_APP_KEY', 'd6f02b90cf6b16220932f4037578aff7'))
Paymentwall.set_secret_key(
os.getenv('PAYMENTWALL_SECRET_KEY', '4ea515bf94e34cf28646c2e12a7b8707'))
# Mixpanel settings
MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd')
@ -361,7 +377,8 @@ MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd')
if DEBUG:
CORS_ORIGIN_ALLOW_ALL = True
else:
CORS_ORIGIN_WHITELIST = os.getenv('CORS_ORIGIN_WHITELIST', 'lilcity.9ev.ru:8080').split(',')
CORS_ORIGIN_WHITELIST = os.getenv(
'CORS_ORIGIN_WHITELIST', 'lilcity.9ev.ru:8080').split(',')
# Swagger doc settings

@ -31,13 +31,15 @@ class IndexView(TemplateView):
now_time = now()
try:
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday(), is_camp=True)
school_schedule = SchoolSchedule.objects.get(
weekday=now_time.isoweekday(), is_camp=True)
except SchoolSchedule.DoesNotExist:
online = False
online_coming_soon = False
school_schedule = None
else:
end_at = datetime.combine(now_time.today(), school_schedule.start_at)
end_at = datetime.combine(
now_time.today(), school_schedule.start_at)
online = (
school_schedule.start_at <= now_time.time() and
(end_at + timedelta(hours=1)).time() >= now_time.time() and
@ -45,7 +47,8 @@ class IndexView(TemplateView):
)
online_coming_soon = (
school_schedule.start_at > now_time.time() and
datetime.combine(datetime.today(), school_schedule.start_at) - timedelta(hours=12)
datetime.combine(
datetime.today(), school_schedule.start_at) - timedelta(hours=12)
<= datetime.combine(datetime.today(), now_time.time()) and
school_schedule.current_camp_lesson
)
@ -91,15 +94,19 @@ class IndexView(TemplateView):
if user_gift_certificate:
try:
user_gift_certificate = short_url.decode_url(user_gift_certificate)
user_gift_certificate = UserGiftCertificate.objects.get(pk=user_gift_certificate, bonuses_sent__isnull=True)
user_gift_certificate = short_url.decode_url(
user_gift_certificate)
user_gift_certificate = UserGiftCertificate.objects.get(
pk=user_gift_certificate, bonuses_sent__isnull=True)
except:
user_gift_certificate = None
review_images = list(map(str, range(1, 107)))
shuffle(review_images)
teachers = User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True)
if teachers.count() % 2 == 0:
teachers = User.objects.filter(
role=User.TEACHER_ROLE, show_in_mainpage=True)
if teachers.count() % 2 == 0 and teachers.count() > 2:
teachers = teachers[:teachers.count() - 1]
context.update({
@ -128,6 +135,7 @@ class IndexView(TemplateView):
'is_purchased_future': False,
})
return context
@ -136,7 +144,8 @@ class SchoolSchedulesView(TemplateView):
def get_context_data(self):
context = super().get_context_data()
context['school_schedules'] = SchoolSchedule.objects.filter(is_camp=True)
context['school_schedules'] = SchoolSchedule.objects.filter(
is_camp=True)
return context
@ -163,12 +172,13 @@ class PackagesView(TemplateView):
context['last_school_payment'] = last_school_payment
if last_school_payment:
next_month = (last_school_payment.date_end + timedelta(1)).month
context['next_buy_date'] = last_school_payment.date_end + timedelta(1)
context['next_buy_date'] = last_school_payment.date_end + \
timedelta(1)
context['school_months_left'] = (school_end.month - next_month
if next_month <= school_end.month
else (school_end.month + 13) - next_month)
if next_month <= school_end.month
else (school_end.month + 13) - next_month)
else:
context['school_months_left'] = (school_end.month - today.month
if today.month <= school_end.month
else (school_end.month + 13) - today.month)
if today.month <= school_end.month
else (school_end.month + 13) - today.month)
return context

Loading…
Cancel
Save