43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# ITerativ GmbH
|
|
# http://www.iterativ.ch/
|
|
#
|
|
# Copyright (c) 2020 ITerativ GmbH. All rights reserved.
|
|
#
|
|
# Created on 20.02.20
|
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
|
import os
|
|
import shutil
|
|
|
|
from django.conf import settings
|
|
from django.core import management
|
|
from django.core.management import BaseCommand
|
|
from django.db import connection
|
|
|
|
from core import hep_client
|
|
from core.models import AdminData
|
|
from users.models import User, License
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
def ensure_clean_dir(self, folder):
|
|
path = os.path.join(settings.MEDIA_ROOT, folder)
|
|
if os.path.exists(path):
|
|
shutil.rmtree(path)
|
|
if not os.path.exists(path):
|
|
os.makedirs(path)
|
|
|
|
def handle(self, *args, **options):
|
|
"Update licenses via cronjob"
|
|
|
|
admin_token = AdminData.objects.get_admin_token()
|
|
hep_users = User.objects.filter(hep_id__isnull=False)
|
|
|
|
for hep_user in hep_users:
|
|
product = hep_client.myskillbox_product_for_customer(admin_token, hep_user.hep_id)
|
|
if License.objects.filter(licensee=hep_users, order_id=product['order_id']).count() == 0:
|
|
License.objects.create_license_for_role(hep_user, product['activated'], product['raw'],
|
|
product['edition'], product['order_id'])
|