You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.1 KiB
28 lines
1.1 KiB
# -*- coding: utf-8 -*-
|
|
from datetime import datetime, timedelta
|
|
from django.core.cache import cache
|
|
from .models import License
|
|
|
|
|
|
def license_check_soon_ends(request):
|
|
try:
|
|
license_cookie = request.COOKIES.get('close_message_license')
|
|
if not license_cookie:
|
|
now = datetime.today()
|
|
license_15days = cache.get('license_15_%s' % (request.user.username,), None)
|
|
if license_15days is None:
|
|
licenses_ends = License.objects.filter(company=request.user.profile, date_to__lte=now + timedelta(15), status__in=[-1, 1, 2], deleted=False)
|
|
next_licenses = License.objects.filter(company=request.user.profile, status=1, deleted=False)
|
|
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)
|
|
license_15days = days_to_end
|
|
else:
|
|
license_15days = ''
|
|
|
|
return {
|
|
'license_15days': license_15days
|
|
}
|
|
return { }
|
|
except:
|
|
return { }
|
|
|