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.
 
 
 
 

24 lines
616 B

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from datetime import datetime
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)
return None