# -*- coding: utf-8 -*- from __future__ import absolute_import from datetime import datetime, timedelta from celery import shared_task from project.commons.utils import mail_exception from project.customer.models import License, UserProfile from project.customer.utils import check_one_profile from project.customer import consts @shared_task def check_license(): profiles = UserProfile.objects.all() now_ = datetime.today() #licenses = License.objects.filter(date_to__lt=now_, status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE], deleted=False) #licenses.update(status=consts.LICENSE_EXPIRED) licenses = License.objects.filter(order_date__lte = now_ - timedelta(days=consts.LICENSE_PAY_DAYS), status=consts.LICENSE_UNPAID, deleted=False) licenses.update(status=consts.LICENSE_SUSPENDED) for profile in profiles: try: check_one_profile(profile, License, now_) except Exception as e: mail_exception(u'customer: check_license error', u'Profile id=%d.' % profile.pk, e) return None