# -*- coding: utf-8 -*- # # ITerativ GmbH # http://www.iterativ.ch/ # # Copyright (c) 2020 ITerativ GmbH. All rights reserved. # # Created on 27.01.20 # @author: chrigu from datetime import timedelta from django.db import models from core.hep_client import TEACHER_EDITION_DURATION, STUDENT_EDITION_DURATION from users.models import Role class LicenseManager(models.Manager): def create_license_for_role(self, licensee, activation_date, raw, role): if role == 'teacher': user_role = Role.objects.get_default_teacher_role() expiry_date = activation_date + timedelta(TEACHER_EDITION_DURATION) else: user_role = Role.objects.get_default_student_role() expiry_date = activation_date + timedelta(STUDENT_EDITION_DURATION) return self._create_license_for_role(licensee, expiry_date, raw, user_role) def _create_license_for_role(self, licensee, expiry_date, raw, role): return self.create(licensee=licensee, expire_date=expiry_date, raw=raw, for_role=role)