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.
59 lines
2.1 KiB
59 lines
2.1 KiB
from django.db import models
|
|
from core.models import CalgaryAddress, QuoteUser
|
|
from .validators import RestrictedFileField
|
|
|
|
# Create your models here.
|
|
class Address(models.Model):
|
|
address = models.CharField(max_length=128)
|
|
# TODO: add validation columns in relation to city
|
|
city = models.CharField(max_length=32)
|
|
def toDict(self):
|
|
return {
|
|
'address': self.address,
|
|
'id': self.id
|
|
}
|
|
|
|
def __str__(self):
|
|
return self.address
|
|
|
|
class PDF(models.Model):
|
|
path = models.CharField(max_length=64)
|
|
code = models.CharField(max_length=8)
|
|
upload_file = RestrictedFileField(max_upload_size=1024*1024*50, content_types=['pdf', 'application/pdf'], upload_to='uploads/%Y/%m/%d/')
|
|
address = models.ForeignKey(Address, on_delete=models.CASCADE, related_name='uploads')
|
|
upload_date = models.DateTimeField(auto_now_add=True, editable=False, null=False, blank=False)
|
|
valid = models.BooleanField()
|
|
|
|
def __str__(self):
|
|
return self.address.address
|
|
|
|
class EmailSent(models.Model):
|
|
timestamp = models.DateTimeField(auto_now_add=True, editable=False, null=False, blank=False)
|
|
user = models.ForeignKey(QuoteUser, on_delete=models.CASCADE)
|
|
pdf = models.ForeignKey(PDF, on_delete=models.CASCADE)
|
|
ref_code = models.CharField(max_length=256)
|
|
|
|
class DownloadAttempt(models.Model):
|
|
timestamp = models.DateTimeField(auto_now_add=True, editable=False, null=False, blank=False)
|
|
user = models.ForeignKey(QuoteUser, on_delete=models.CASCADE, related_name='attempts')
|
|
email_sent = models.BooleanField(default=False)
|
|
code_correct = models.BooleanField(default=False)
|
|
pdf = models.ForeignKey(PDF, on_delete=models.CASCADE, related_name='attempts')
|
|
ip = models.GenericIPAddressField()
|
|
geolocation = models.CharField(max_length=64)
|
|
|
|
class AbstractEmail(models.Model):
|
|
email = models.CharField(max_length=64)
|
|
active = models.BooleanField(default=False)
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def __str__(self):
|
|
return self.email
|
|
|
|
class CCEmail(AbstractEmail):
|
|
pass
|
|
|
|
class BCCEmail(AbstractEmail):
|
|
pass
|