from django.db import models from django.conf import settings from django.utils import timezone from django.utils.translation import gettext_lazy as _ from datetime import timedelta class OnlineExamRegistrate(models.Model): PAYMENT_CODE = 0 PAYMENT_ONLINE = 1 PAYMENT_CHOICES = ( (PAYMENT_CODE, _('promotion code')), (PAYMENT_ONLINE, _('online payment')) ) FLAG_PCTA = 'PCTA' FLAG_PCTP = 'PCTP' FLAG_CHOICES = ( (FLAG_PCTA, 'PCTA'), (FLAG_PCTP, 'PCTP') ) EXAM_MODIFY_MAX_TIMES = 2 user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING) online_exam = models.ForeignKey( 'university.OnlineExam', on_delete=models.CASCADE) flag = models.CharField( max_length=32, default=FLAG_PCTA, choices=FLAG_CHOICES) name = models.CharField(max_length=64) chinese_id = models.CharField(max_length=64) phone = models.CharField(max_length=64) email = models.EmailField() company = models.CharField(max_length=64) city = models.CharField(max_length=64) tug_role = models.CharField(max_length=64) payment_method = models.SmallIntegerField(choices=PAYMENT_CHOICES, default=PAYMENT_CODE) promotion_code = models.ForeignKey( 'university.OnlineExamPromotionCode', on_delete=models.DO_NOTHING, null=True, blank=True) online_payment_success = models.BooleanField(default=False) need_receipt = models.BooleanField(default=False) receipt_header = models.CharField(max_length=128, blank=True, null=True) receipt_tin = models.CharField(max_length=255, blank=True, null=True) obtained_dba_certs = models.CharField(max_length=255, blank=True, null=True) exam_modified_times = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = 'online_exam_registrate' unique_together = ('user', 'online_exam') @property def exam_modification_remaining(self): return self.EXAM_MODIFY_MAX_TIMES - self.exam_modified_times @property def can_update_exam(self): return self.online_exam.start_at - timedelta(days=3) > timezone.now() @property def can_update_info_except_exam(self): return self.online_exam.start_at > timezone.now()