2013-08-26 03:35:27 +00:00
|
|
|
from datetime import timedelta, datetime
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
class Boox(models.Model):
|
|
|
|
"""
|
|
|
|
keeps a record of a file that's been watermarked
|
|
|
|
"""
|
|
|
|
download_link_epub = models.URLField(null=True)
|
|
|
|
download_link_mobi = models.URLField(null=True)
|
|
|
|
referenceid = models.CharField(max_length=32)
|
|
|
|
downloads_remaining = models.PositiveSmallIntegerField(default = 0)
|
|
|
|
expirydays = models.PositiveSmallIntegerField()
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def expired(self):
|
|
|
|
return self.created+timedelta(days=self.expirydays) < datetime.now()
|
|
|
|
|
2013-11-15 04:16:55 +00:00
|
|
|
def download_link(self, format):
|
|
|
|
if format == 'epub':
|
|
|
|
return self.download_link_epub
|
|
|
|
elif format == 'mobi':
|
|
|
|
return self.download_link_mobi
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|