test logger to file

remotes/origin/roistat-logger-gleb
Gleb Mikhaylov 7 years ago
parent 276c33c694
commit f9e65a3d5a
  1. 32
      project/settings.py
  2. 38
      project/views.py

@ -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/ # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False) DEBUG = os.getenv('DEBUG', False)
@ -200,6 +201,11 @@ LOGGING = {
'level': 'WARNING', 'level': 'WARNING',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
}, },
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'media/logs/main.log',
},
}, },
'loggers': { 'loggers': {
'django.request': { 'django.request': {
@ -214,9 +220,13 @@ LOGGING = {
'handlers': ['console', ], 'handlers': ['console', ],
}, },
'': { '': {
'handlers': ['sentry',], 'handlers': ['sentry', ],
'level': "INFO", 'level': "INFO",
}, },
'roistat': {
'handlers': ['file'],
'level': 'DEBUG'
},
} }
} }
@ -258,7 +268,8 @@ SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
# SMS # SMS
# https://github.com/twilio/twilio-python # 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_TOKEN = os.getenv('TWILIO_TOKEN', '559a6b1fce121759c9af2dcbb3f755ea')
TWILIO_FROM_PHONE = os.getenv('TWILIO_FROM_PHONE', '+37128914409') TWILIO_FROM_PHONE = os.getenv('TWILIO_FROM_PHONE', '+37128914409')
@ -297,8 +308,10 @@ REST_FRAMEWORK = {
# Celery settings # Celery settings
CELERY_BROKER_URL = os.getenv('REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_BROKER_DB', '0') CELERY_BROKER_URL = os.getenv(
CELERY_RESULT_BACKEND = os.getenv('REDIS_SERVICE_HOST', 'redis://redis:6379/') + os.getenv('REDIS_RESULTS_DB', '1') '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_TASK_SERIALIZER = 'json'
CELERY_BEAT_SCHEDULE = { CELERY_BEAT_SCHEDULE = {
@ -350,8 +363,10 @@ except ImportError:
pass pass
else: else:
Paymentwall.set_api_type(Paymentwall.API_GOODS) Paymentwall.set_api_type(Paymentwall.API_GOODS)
Paymentwall.set_app_key(os.getenv('PAYMENTWALL_APP_KEY', 'd6f02b90cf6b16220932f4037578aff7')) Paymentwall.set_app_key(
Paymentwall.set_secret_key(os.getenv('PAYMENTWALL_SECRET_KEY', '4ea515bf94e34cf28646c2e12a7b8707')) os.getenv('PAYMENTWALL_APP_KEY', 'd6f02b90cf6b16220932f4037578aff7'))
Paymentwall.set_secret_key(
os.getenv('PAYMENTWALL_SECRET_KEY', '4ea515bf94e34cf28646c2e12a7b8707'))
# Mixpanel settings # Mixpanel settings
MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd') MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd')
@ -361,7 +376,8 @@ MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd')
if DEBUG: if DEBUG:
CORS_ORIGIN_ALLOW_ALL = True CORS_ORIGIN_ALLOW_ALL = True
else: 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 # Swagger doc settings

@ -12,6 +12,9 @@ from apps.course.models import Course
from apps.school.models import SchoolSchedule from apps.school.models import SchoolSchedule
from apps.payment.models import SchoolPayment, UserGiftCertificate, Payment, DrawingCampPayment from apps.payment.models import SchoolPayment, UserGiftCertificate, Payment, DrawingCampPayment
from apps.content.models import Banner, Package from apps.content.models import Banner, Package
import logging
logger_roistat = logging.getLogger('roistat')
User = get_user_model() User = get_user_model()
@ -31,13 +34,15 @@ class IndexView(TemplateView):
now_time = now() now_time = now()
try: 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: except SchoolSchedule.DoesNotExist:
online = False online = False
online_coming_soon = False online_coming_soon = False
school_schedule = None school_schedule = None
else: else:
end_at = datetime.combine(now_time.today(), school_schedule.start_at) end_at = datetime.combine(
now_time.today(), school_schedule.start_at)
online = ( online = (
school_schedule.start_at <= now_time.time() and school_schedule.start_at <= now_time.time() and
(end_at + timedelta(hours=1)).time() >= now_time.time() and (end_at + timedelta(hours=1)).time() >= now_time.time() and
@ -45,7 +50,8 @@ class IndexView(TemplateView):
) )
online_coming_soon = ( online_coming_soon = (
school_schedule.start_at > now_time.time() and 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 <= datetime.combine(datetime.today(), now_time.time()) and
school_schedule.current_camp_lesson school_schedule.current_camp_lesson
) )
@ -91,14 +97,17 @@ class IndexView(TemplateView):
if user_gift_certificate: if user_gift_certificate:
try: try:
user_gift_certificate = short_url.decode_url(user_gift_certificate) user_gift_certificate = short_url.decode_url(
user_gift_certificate = UserGiftCertificate.objects.get(pk=user_gift_certificate, bonuses_sent__isnull=True) user_gift_certificate)
user_gift_certificate = UserGiftCertificate.objects.get(
pk=user_gift_certificate, bonuses_sent__isnull=True)
except: except:
user_gift_certificate = None user_gift_certificate = None
review_images = list(map(str, range(1, 107))) review_images = list(map(str, range(1, 107)))
shuffle(review_images) shuffle(review_images)
teachers = User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True) teachers = User.objects.filter(
role=User.TEACHER_ROLE, show_in_mainpage=True)
if teachers.count() % 2 == 0: if teachers.count() % 2 == 0:
teachers = teachers[:teachers.count() - 1] teachers = teachers[:teachers.count() - 1]
@ -128,6 +137,9 @@ class IndexView(TemplateView):
'is_purchased_future': False, 'is_purchased_future': False,
}) })
logger_roistat.debug('hi from home page!')
return context return context
@ -136,7 +148,8 @@ class SchoolSchedulesView(TemplateView):
def get_context_data(self): def get_context_data(self):
context = super().get_context_data() 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 return context
@ -163,12 +176,13 @@ class PackagesView(TemplateView):
context['last_school_payment'] = last_school_payment context['last_school_payment'] = last_school_payment
if last_school_payment: if last_school_payment:
next_month = (last_school_payment.date_end + timedelta(1)).month 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 context['school_months_left'] = (school_end.month - next_month
if next_month <= school_end.month if next_month <= school_end.month
else (school_end.month + 13) - next_month) else (school_end.month + 13) - next_month)
else: else:
context['school_months_left'] = (school_end.month - today.month context['school_months_left'] = (school_end.month - today.month
if today.month <= school_end.month if today.month <= school_end.month
else (school_end.month + 13) - today.month) else (school_end.month + 13) - today.month)
return context return context

Loading…
Cancel
Save