Fixes linter issues
This commit is contained in:
@ -35,6 +35,7 @@ def construct_search_term(title, author):
|
||||
|
||||
|
||||
class ImportJob(models.Model):
|
||||
''' entry for a specific request for book data import '''
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(default=timezone.now)
|
||||
task_id = models.CharField(max_length=100, null=True)
|
||||
@ -42,6 +43,7 @@ class ImportJob(models.Model):
|
||||
'Status', null=True, on_delete=models.PROTECT)
|
||||
|
||||
class ImportItem(models.Model):
|
||||
''' a single line of a csv being imported '''
|
||||
job = models.ForeignKey(
|
||||
ImportJob,
|
||||
on_delete=models.CASCADE,
|
||||
@ -77,6 +79,7 @@ class ImportItem(models.Model):
|
||||
|
||||
@property
|
||||
def isbn(self):
|
||||
''' pulls out the isbn13 field from the csv line data '''
|
||||
return unquote_string(self.data['ISBN13'])
|
||||
|
||||
@property
|
||||
@ -87,24 +90,29 @@ class ImportItem(models.Model):
|
||||
|
||||
@property
|
||||
def review(self):
|
||||
''' a user-written review, to be imported with the book data '''
|
||||
return self.data['My Review']
|
||||
|
||||
@property
|
||||
def rating(self):
|
||||
''' x/5 star rating for a book '''
|
||||
return int(self.data['My Rating'])
|
||||
|
||||
@property
|
||||
def date_added(self):
|
||||
''' when the book was added to this dataset '''
|
||||
if self.data['Date Added']:
|
||||
return dateutil.parser.parse(self.data['Date Added'])
|
||||
|
||||
@property
|
||||
def date_read(self):
|
||||
''' the date a book was completed '''
|
||||
if self.data['Date Read']:
|
||||
return dateutil.parser.parse(self.data['Date Read'])
|
||||
|
||||
@property
|
||||
def reads(self):
|
||||
''' formats a read through dataset for the book in this line '''
|
||||
if (self.shelf == 'reading'
|
||||
and self.date_added and not self.date_read):
|
||||
return [ReadThrough(start_date=self.date_added)]
|
||||
|
@ -1,14 +1,15 @@
|
||||
''' the particulars for this instance of BookWyrm '''
|
||||
import base64
|
||||
|
||||
from Crypto import Random
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
import datetime
|
||||
|
||||
from bookwyrm.settings import DOMAIN
|
||||
from .user import User
|
||||
|
||||
class SiteSettings(models.Model):
|
||||
''' customized settings for this instance '''
|
||||
name = models.CharField(default=DOMAIN, max_length=100)
|
||||
instance_description = models.TextField(
|
||||
default="This instance has no description.")
|
||||
@ -18,6 +19,7 @@ class SiteSettings(models.Model):
|
||||
|
||||
@classmethod
|
||||
def get(cls):
|
||||
''' gets the site settings db entry or defaults '''
|
||||
try:
|
||||
return cls.objects.get(id=1)
|
||||
except cls.DoesNotExist:
|
||||
@ -26,9 +28,11 @@ class SiteSettings(models.Model):
|
||||
return default_settings
|
||||
|
||||
def new_invite_code():
|
||||
''' the identifier for a user invite '''
|
||||
return base64.b32encode(Random.get_random_bytes(5)).decode('ascii')
|
||||
|
||||
class SiteInvite(models.Model):
|
||||
''' gives someone access to create an account on the instance '''
|
||||
code = models.CharField(max_length=32, default=new_invite_code)
|
||||
expiry = models.DateTimeField(blank=True, null=True)
|
||||
use_limit = models.IntegerField(blank=True, null=True)
|
||||
@ -36,10 +40,12 @@ class SiteInvite(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
def valid(self):
|
||||
''' make sure it hasn't expired or been used '''
|
||||
return (
|
||||
(self.expiry is None or self.expiry > timezone.now()) and
|
||||
(self.use_limit is None or self.times_used < self.use_limit))
|
||||
|
||||
@property
|
||||
def link(self):
|
||||
''' formats the invite link '''
|
||||
return "https://{}/invite/{}".format(DOMAIN, self.code)
|
||||
|
Reference in New Issue
Block a user