parent
0ee9b5fb6d
commit
21620ebd4f
6 changed files with 54 additions and 17 deletions
@ -0,0 +1,26 @@ |
||||
# -*- 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: |
||||
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__gte=now - timedelta(15), status__in=[-1, 1, 2], deleted=False) |
||||
next_licenses = License.objects.filter(company=request.user.profile, date_from__gte=now - timedelta(15), 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) |
||||
license_15days = days_to_end |
||||
else: |
||||
license_15days = '' |
||||
|
||||
return { |
||||
#'license_15days': license_15days == 'Y' |
||||
'license_15days': license_15days |
||||
} |
||||
except: |
||||
return { } |
||||
Loading…
Reference in new issue