bonus maessage

prod
Dmitriy Shesterkin 9 years ago
parent 57fc5c0070
commit 124d08546c
  1. 2
      src/customer/admin.py
  2. 44
      src/customer/context_processors.py
  3. 8
      src/customer/utils.py
  4. 20
      src/myauth/admin.py
  5. 8
      src/tests/test_utils.py
  6. 4
      templates/base.html

@ -21,7 +21,7 @@ class LicenseAdmin(admin.ModelAdmin):
'order_date',
'date_from',
'date_to',
'balance_days',
'balance_days'
)
list_display_links = list_display

@ -3,7 +3,7 @@ import logging
from datetime import datetime, timedelta
from django.core.cache import cache
from customer.models import License
from customer.utils import get_display_message_for_bonus
from customer.utils import get_display_message_for_bonus, check_confirm_bonus_to_user
log = logging.getLogger(__name__)
@ -15,6 +15,8 @@ def license_check_soon_ends(request):
days_left = cache.get(f'days_left_{request.user.username}', None)
cur_license = cache.get(f'cur_license_{request.user.username}', None)
print('license_15days=', license_15days)
if not days_left or not cur_license:
now = datetime.today()
cur_license = License.objects.filter(
@ -29,6 +31,9 @@ def license_check_soon_ends(request):
cache.set(f'days_left_{request.user.username}', days_left, 3600)
cache.set(f'cur_license_{request.user.username}', cur_license, 3600)
if license_cookie:
license_15days = ''
if not license_cookie:
now = datetime.today()
if license_15days is None:
@ -47,8 +52,8 @@ def license_check_soon_ends(request):
days_to_end = licenses_ends[0].date_to
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,
@ -56,28 +61,31 @@ def license_check_soon_ends(request):
'cur_license': cur_license,
}
except Exception as e:
log.warning(e)
log.info(e)
return {}
def confirm_user_bonus(request):
"""
If the user can get a notification about the bonus and
did not close the pop-up message, display this message
:param request: request( get from request user)
:return: context, dictionary
"""
context = {}
message = ''
if request.user:
context = {}
close_bonus_cookie = request.COOKIES.get('close_message_bonus')
confirm_bonus_days = cache.get(f'confirm_bonus_days_{request.user.username}', None)
if not confirm_bonus_days:
confirm_bonus_days = check_confirm_bonus_to_user(request.user)
cache.set(f'confirm_bonus_days_{request.user.username}', confirm_bonus_days, 3600)
if confirm_bonus_days >= 0:
message = get_display_message_for_bonus(confirm_bonus_days)
context['confirm_bonus'] = True
context['message'] = message
return context
if close_bonus_cookie:
message = ''
if not close_bonus_cookie:
pass
else:
return context
message = get_display_message_for_bonus(confirm_bonus_days)
# return {
# 'confirm_bonus': True,
# 'message_bonus': message
# }
context['message_bonus'] = message
return context

@ -110,7 +110,7 @@ def check_confirm_bonus_to_user(user):
If user already have licenses don't display message
:param user: DockUser instance
:return: count of days remaining for getting bonus,
integer or False if nothing to use
integer or integer (-1) if nothing to use
"""
from customer.models import License
@ -120,16 +120,16 @@ def check_confirm_bonus_to_user(user):
deleted=False
)
if lic:
return False
return -1
today = timezone.now().date()
date_join_start = today - timezone.timedelta(days=15)
date_join_end = today - timezone.timedelta(days=6)
date_join_end = today - timezone.timedelta(days=5)
if date_join_start <= user.date_joined.date() <= date_join_end:
delta = user.date_joined.date() - date_join_start
return delta.days
return False
return -1
def get_display_message_for_bonus(day_count):

@ -3,6 +3,7 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from customer.utils import check_confirm_bonus_to_user
from myauth.models import DokUser, ConfirmEmail
from myauth.forms import CustomUserChangeForm, CustomUserCreationForm
@ -28,10 +29,27 @@ class CustomUserAdmin(UserAdmin):
)
form = CustomUserChangeForm
add_form = CustomUserCreationForm
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'date_joined')
list_display = (
'username',
'email',
'first_name',
'last_name',
'is_staff',
'date_joined',
'remain_confirm_bonus_days'
)
search_fields = ('username', 'email', 'first_name', 'last_name')
ordering = ('email',)
def remain_confirm_bonus_days(self, obj):
confirm_bonus_days = check_confirm_bonus_to_user(obj)
if confirm_bonus_days != -1:
return confirm_bonus_days
else:
return '-'
remain_confirm_bonus_days.short_description = 'Дней для активации бонуса'
admin.site.register(DokUser, CustomUserAdmin)
admin.site.register(ConfirmEmail)

@ -8,11 +8,11 @@ from customer.utils import check_one_profile, check_confirm_bonus_to_user
from customer.utils import get_display_message_for_bonus
dates = [timezone.now() - timezone.timedelta(days=6),
dates = [timezone.now() - timezone.timedelta(days=5),
timezone.now() - timezone.timedelta(days=10),
timezone.now() - timezone.timedelta(days=15)]
dates_not_in_range = [timezone.now() - timezone.timedelta(days=5),
dates_not_in_range = [timezone.now() - timezone.timedelta(days=2),
timezone.now() - timezone.timedelta(days=16)]
days = [1, 5, 10, 4, 6, 0]
@ -44,7 +44,7 @@ def test_check_confirm_bonus_to_user_not_in_range(user, create_date):
user.date_joined = create_date
user.save()
day_remain = check_confirm_bonus_to_user(user)
assert day_remain is False
assert day_remain == -1
@pytest.mark.parametrize('create_date', dates)
@ -54,7 +54,7 @@ def test_check_confirm_bonus_to_user_with_license(lic, create_date):
user.date_joined = create_date
user.save()
day_remain = check_confirm_bonus_to_user(user)
assert day_remain is False
assert day_remain == -1
@pytest.mark.parametrize('count_day', days)

@ -17,7 +17,7 @@
<body>
{% cms_toolbar %}
{% if license_15days or confirm_bonus %}
{% if license_15days or message_bonus %}
<div id="content" class="clear">
<ul class="messagelist">
@ -25,7 +25,7 @@
<li class="error">{{ license_15days }} заканчивается Ваша лицензия на Документор. <a href="{% url 'customer_order_license' %}">Купите новую лицензию</a> заранее, чтобы работать без перерывов.<a href='#' class='close-message' data-close='close_message_license'>Закрыть</a></li>
{% endif %}
{% if confirm_bonus %}
{% if message_bonus %}
<li class="warning">{{ message_bonus| safe }}<a href='#' class='close-message' data-close='close_message_bonus'>Закрыть</a></li>
{% endif %}
</ul>

Loading…
Cancel
Save