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.
29 lines
901 B
29 lines
901 B
# -*- coding: utf-8 -*-
|
|
from __future__ import absolute_import
|
|
from datetime import datetime, timedelta
|
|
|
|
from celery import shared_task
|
|
from .models import License, UserProfile
|
|
|
|
|
|
@shared_task
|
|
def check_license():
|
|
profiles = UserProfile.objects.all()
|
|
now = datetime.now()
|
|
|
|
for profile in profiles:
|
|
licenses = License.objects.filter(user=profile.user, date_from__lte=now, date_to__gte=now, status__in=[-1, 1, 2])
|
|
if licenses:
|
|
profile.active = True
|
|
else:
|
|
profile.active = False
|
|
profile.save()
|
|
licenses.filter(status=1).update(status=2)
|
|
|
|
licenses = License.objects.filter(user=profile.user, date_to__lt=now, status__in=[-1, 2])
|
|
licenses.update(status=3)
|
|
licenses = License.objects.filter(user=profile.user, order_date__lt=now - timedelta(10), status=0)
|
|
licenses.update(status=4)
|
|
|
|
return None
|
|
|
|
|