From ebfe8b6055f8701f6e0c19efdfd2f771e4888345 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Tue, 27 Jun 2017 17:06:25 +0300 Subject: [PATCH] fix debug toolbar --- .gitignore | 1 - deploy/common.py | 4 ---- deploy/stage.py.example | 7 ------ fabfile.py | 4 ++-- src/customer/context_processors.py | 38 +++++++++++++++++++++++------- src/dokumentor/settings/common.py | 3 ++- src/dokumentor/urls.py | 2 +- src/myauth/views.py | 9 +++---- static/js/commons.js | 18 ++++++++++---- static/js/license.js | 9 ++----- templates/base.html | 5 +++- 11 files changed, 58 insertions(+), 42 deletions(-) delete mode 100644 deploy/common.py delete mode 100644 deploy/stage.py.example diff --git a/.gitignore b/.gitignore index 6b0f790..d9dc4c9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ conf/env !form.html /static/vendor -# deploy settings /deploy/stage.py ######################All system################################################ diff --git a/deploy/common.py b/deploy/common.py deleted file mode 100644 index 7a4f9d3..0000000 --- a/deploy/common.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -PROJECT_NAME = 'dokumentor' -REPO = 'git@bitbucket.org:Air51/dokumentor_dev.git' -BRANCH = 'develop' diff --git a/deploy/stage.py.example b/deploy/stage.py.example deleted file mode 100644 index 8475f7e..0000000 --- a/deploy/stage.py.example +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -from deploy.common import * # noqa - -USER = 'username' -PASS = 'password' -HOSTS = ['domain_name:ssh_port'] - diff --git a/fabfile.py b/fabfile.py index 78b14bc..c05ae69 100644 --- a/fabfile.py +++ b/fabfile.py @@ -2,8 +2,8 @@ # flake8: noqa from fabric.api import * -from deploy.common import BRANCH, PROJECT_NAME -from deploy.stage import HOSTS, USER, PASS +from conf.deploy.common import BRANCH, PROJECT_NAME +from conf.deploy.stage import HOSTS, USER, PASS PROJECT_DIR = f'projects/{PROJECT_NAME}' env.user = USER diff --git a/src/customer/context_processors.py b/src/customer/context_processors.py index 48490da..3571e54 100644 --- a/src/customer/context_processors.py +++ b/src/customer/context_processors.py @@ -1,15 +1,24 @@ # -*- coding: utf-8 -*- +import logging from datetime import datetime, timedelta from django.core.cache import cache from customer.models import License +log = logging.getLogger(__name__) + def license_check_soon_ends(request): try: license_cookie = request.COOKIES.get('close_message_license') - license_15days = cache.get('license_15_%s' % (request.user.username,), None) - days_left = cache.get('days_left_%s' % (request.user.username,), None) - cur_license = cache.get('cur_license_%s' % (request.user.username,), None) + license_15days = cache.get(f'license_15_{request.user.username}', None) + days_left = cache.get(f'days_left_{request.user.username}', None) + cur_license = cache.get(f'cur_license_{request.user.username}', None) + + print(license_cookie) + print(license_15days) + print(days_left) + print(cur_license) + if not days_left or not cur_license: now = datetime.today() cur_license = License.objects.filter( @@ -21,8 +30,8 @@ def license_check_soon_ends(request): if cur_license: cur_license = cur_license[0] days_left = (cur_license.date_to - now.date()).days - cache.set('days_left_%s' % (request.user.username,), days_left, 3600) - cache.set('cur_license_%s' % (request.user.username,), cur_license, 3600) + cache.set(f'days_left_{request.user.username}', days_left, 3600) + cache.set(f'cur_license_{request.user.username}', cur_license, 3600) if not license_cookie: now = datetime.today() @@ -40,10 +49,10 @@ def license_check_soon_ends(request): ) if licenses_ends and not next_licenses: days_to_end = licenses_ends[0].date_to - cache.set('license_15_%s' % (request.user.username,), days_to_end, 3600) + cache.set(f'license_15_{request.user.username}', days_to_end, 3600) license_15days = days_to_end - else: - license_15days = '' + else: + license_15days = '' return { 'license_15days': license_15days, @@ -51,5 +60,16 @@ def license_check_soon_ends(request): 'cur_license': cur_license, } except Exception as e: - # print e + log.warning(e) return {} + + +def confirm_user_bonus(request): + if request.user: + bonus_url = '#' + message = f'У вас есть ещё 10 дней, чтобы получить бонус' + test_message = 'This message is personal confirm for current user' + return { + 'confirm_bonus': True, + 'message_bonus': message + } diff --git a/src/dokumentor/settings/common.py b/src/dokumentor/settings/common.py index 38d5ddf..5ab0357 100644 --- a/src/dokumentor/settings/common.py +++ b/src/dokumentor/settings/common.py @@ -110,7 +110,8 @@ TEMPLATES = [ 'sekizai.context_processors.sekizai', 'cms.context_processors.cms_settings', 'callback.context_processors.add_forms', - 'src.customer.context_processors.license_check_soon_ends' + 'src.customer.context_processors.license_check_soon_ends', + 'src.customer.context_processors.confirm_user_bonus', ], 'loaders': [ 'django.template.loaders.filesystem.Loader', diff --git a/src/dokumentor/urls.py b/src/dokumentor/urls.py index 7b4d808..c8a4922 100644 --- a/src/dokumentor/urls.py +++ b/src/dokumentor/urls.py @@ -31,6 +31,6 @@ urlpatterns = [ if settings.DEBUG: import debug_toolbar - urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))] + urlpatterns = [url(r'^__debug__/', include(debug_toolbar.urls))] + urlpatterns urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/src/myauth/views.py b/src/myauth/views.py index baeab16..50cfbb5 100644 --- a/src/myauth/views.py +++ b/src/myauth/views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import hashlib +import logging from datetime import datetime from dateutil.relativedelta import relativedelta import random @@ -19,6 +20,8 @@ from customer.models import UserProfile, UserProfileFilters, License from myauth import forms, models, emails +log = logging.getLogger(__name__) + @sensitive_variables() def _create_user(request, **kwargs): @@ -255,12 +258,10 @@ def logout(request): try: request.user.profile.user_session_key = '' request.user.profile.save() - except: - # TODO: ??? - pass + except Exception as e: + log.warning(e)(e) django_logout(request) response = redirect('/') - response.delete_cookie('close_message_license') return response diff --git a/static/js/commons.js b/static/js/commons.js index c847c54..e50ed16 100644 --- a/static/js/commons.js +++ b/static/js/commons.js @@ -1,4 +1,16 @@ $(document).ready(function() { + + function midnight_cookie(name, value, path) { + var now = new Date(); + var expire = new Date(); + expire.setFullYear(now.getFullYear()); + expire.setMonth(now.getMonth()); + expire.setDate(now.getDate()+1); + expire.setHours(0); + expire.setMinutes(0); + document.cookie = name+"="+value+"; expires=" + expire.toString() +"; path=" + path; + } + var show_cabinet = false; $('.has-datepicker').datepicker({dateFormat: 'dd.mm.yy', showOn:"button", buttonImageOnly:true, buttonImage:"/static/img/icon-calendar.png"}); $('#reasons').mouseout(function(e){ @@ -43,12 +55,8 @@ $(document).ready(function() { e.preventDefault(); $(this).closest('li').hide(); var close_action = $(this).data('close'); - $.cookie(close_action, true, {path: '/'}); + midnight_cookie(close_action, true, '/'); }); - // $('.return_to_index').click(function(e){ - // e.preventDefault(); - // window.location = '/'; - // }); function show_overlay() { if ($('.ui-widget-overlay.ui-front').length == 0 ) { $('#cabinet-show').css({'z-index':'101'}); diff --git a/static/js/license.js b/static/js/license.js index f6c8bf8..dcd7079 100644 --- a/static/js/license.js +++ b/static/js/license.js @@ -1,21 +1,16 @@ $(document).ready(function() { - function show_month() { + function show_month() { var terms = $('[name="term"]'); if ($('[name="payform"]:checked').val() == '0'){ $(terms[0]).closest('li').hide(); if (terms.index(terms.filter(':checked')) == 0){ $(terms[1]).prop('checked', true); } - } else { + } else { $($('[name="term"]')[0]).closest('li').show(); } } - // show_month(); - // $('[name="payform"]').change(function(){ - // show_month() - // }); - $('.delete_license').click(function(e){ e.preventDefault(); var lic_pk = $(this).data('id'); diff --git a/templates/base.html b/templates/base.html index e7d12cb..4f9c850 100644 --- a/templates/base.html +++ b/templates/base.html @@ -17,7 +17,7 @@ {% cms_toolbar %} -{% if license_15days %} +{% if license_15days or confirm_bonus %}
{% endif %}