PEP Cleanup

This commit is contained in:
Tris Forster 2024-08-05 12:53:58 +10:00
parent 78789c02ed
commit 1bcec919cf

View File

@ -44,13 +44,13 @@ class Orchestration(models.Model):
def as_list(self): def as_list(self):
tags = [ t.strip() for t in self.instruments.split(' ') ] tags = [ t.strip() for t in self.instruments.split(' ') ]
return [ (t, MusicTag.from_tag(t)) for t in tags if t ] return [ (t, MusicTag.from_tag(t)) for t in tags if t ]
def tag_order(self): def tag_order(self):
tags = [ t.strip() for t in self.instruments.split(' ') if t ] tags = [ t.strip() for t in self.instruments.split(' ') if t ]
order = {'score': 0} order = {'score': 0}
for i, t in enumerate(tags): for i, t in enumerate(tags):
order.setdefault(t.strip('-0123456789'), i*2+1) order.setdefault(t.strip('-0123456789'), i*2+1)
return order return order
def sorter(self): def sorter(self):
@ -79,14 +79,13 @@ class ProjectItem(models.Model):
approved_by = models.ForeignKey('auth.User', on_delete=models.CASCADE) approved_by = models.ForeignKey('auth.User', on_delete=models.CASCADE)
order = models.SmallIntegerField(default=0) order = models.SmallIntegerField(default=0)
section = models.CharField(max_length=100, blank=True) section = models.CharField(max_length=100, blank=True)
class Meta: class Meta:
ordering = ['order', 'work'] ordering = ['order', 'work']
def __str__(self): def __str__(self):
return f"<{self.project_id}:{slugify(self.work.name)}>" return f"<{self.project_id}:{slugify(self.work.name)}>"
class Collection(models.Model): class Collection(models.Model):
""" """
A logical collection of works, typically owned by an organisation or person (physical or virtual) A logical collection of works, typically owned by an organisation or person (physical or virtual)
@ -95,13 +94,13 @@ class Collection(models.Model):
help_text="Name of the collection") help_text="Name of the collection")
prefix = models.CharField(max_length=255, default="default", prefix = models.CharField(max_length=255, default="default",
help_text="Folder to store works in") help_text="Folder to store works in")
administrators = models.ManyToManyField('auth.User', related_name="collections", administrators = models.ManyToManyField('auth.User', related_name="collections",
help_text="Administrators for this collection") help_text="Administrators for this collection")
location = models.CharField(max_length=100, location = models.CharField(max_length=100,
help_text="Physical location (institution, town...)", blank=True) help_text="Physical location (institution, town...)", blank=True)
storage = models.ForeignKey('byostorage.UserStorage', on_delete=models.CASCADE, null=True, blank=True, storage = models.ForeignKey('byostorage.UserStorage', on_delete=models.CASCADE, null=True, blank=True,
help_text="User storage for documents") help_text="User storage for documents")
notes = models.TextField(blank=True, notes = models.TextField(blank=True,
help_text="Publicly visible notes about collection and loans policy (markdown format)") help_text="Publicly visible notes about collection and loans policy (markdown format)")
settings = models.JSONField(default=dict, blank=True, settings = models.JSONField(default=dict, blank=True,
help_text="Storage specific settings") help_text="Storage specific settings")
@ -118,8 +117,8 @@ class Collection(models.Model):
@property @property
def genres(self): def genres(self):
return self.meta('genre') return self.meta('genre')
def has_administrator(self, user): def has_administrator(self, user):
if not user.is_authenticated: if not user.is_authenticated:
return False return False
@ -132,7 +131,7 @@ class Collection(models.Model):
def auth(self): def auth(self):
return sign_data(f'{self.pk}-{self.nonce}', 12) return sign_data(f'{self.pk}-{self.nonce}', 12)
def __str__(self): def __str__(self):
return self.name return self.name
@ -176,7 +175,7 @@ class Work(models.Model):
(LICENCE_PERUSAL, 'Perusal Licence'), (LICENCE_PERUSAL, 'Perusal Licence'),
(LICENCE_NONE, 'Internal use only'), (LICENCE_NONE, 'Internal use only'),
) )
name = models.CharField(max_length=255, help_text="Original name of the work") name = models.CharField(max_length=255, help_text="Original name of the work")
edition = models.CharField(max_length=255, blank=True, edition = models.CharField(max_length=255, blank=True,
help_text="Edition details to distinguish multiple versions") help_text="Edition details to distinguish multiple versions")
@ -193,7 +192,7 @@ class Work(models.Model):
code = models.CharField(max_length=100, blank=True, help_text="Collection specific code or number. Will be auto-generated if not supplied") code = models.CharField(max_length=100, blank=True, help_text="Collection specific code or number. Will be auto-generated if not supplied")
licence = models.PositiveSmallIntegerField(choices=LICENCE_TYPES, default=6, help_text="Copyright status") licence = models.PositiveSmallIntegerField(choices=LICENCE_TYPES, default=6, help_text="Copyright status")
max_projects = models.IntegerField(default=1, help_text="How many active projects can this work be attached to") max_projects = models.IntegerField(default=1, help_text="How many active projects can this work be attached to")
# Extra info # Extra info
running_time = models.DurationField(null=True, blank=True, help_text="Running time in mm:ss format") running_time = models.DurationField(null=True, blank=True, help_text="Running time in mm:ss format")
notes = models.TextField(blank=True) notes = models.TextField(blank=True)
@ -221,7 +220,7 @@ class Work(models.Model):
#return [ s[1] for s in sections ] #return [ s[1] for s in sections ]
sections = list(dict(sections).items()) # primitive unique() sections = list(dict(sections).items()) # primitive unique()
return sections return sections
def pdfs(self): def pdfs(self):
return self.docs.filter(doctype=Document.DOCTYPE_PDF) return self.docs.filter(doctype=Document.DOCTYPE_PDF)
@ -306,7 +305,7 @@ class WorkMeta(models.Model):
('style', 'Style'), ('style', 'Style'),
('orchestration', 'Orchestration'), ('orchestration', 'Orchestration'),
) )
work = models.ForeignKey(Work, on_delete=models.CASCADE, related_name='meta_info') work = models.ForeignKey(Work, on_delete=models.CASCADE, related_name='meta_info')
name = models.SlugField(max_length=20, choices=META_CHOICES) name = models.SlugField(max_length=20, choices=META_CHOICES)
value = models.CharField(max_length=255) value = models.CharField(max_length=255)
@ -350,7 +349,7 @@ class Document(models.Model):
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
self.upload.delete(save=False) self.upload.delete(save=False)
return super().delete(*args, **kwargs) return super().delete(*args, **kwargs)
def filename(self): def filename(self):
return os.path.basename(self.upload.name) return os.path.basename(self.upload.name)
@ -361,7 +360,7 @@ class Section(models.Model):
""" """
Section is a tagged portion of a Document Section is a tagged portion of a Document
""" """
PAGE_AUTO = 0 PAGE_AUTO = 0
PAGE_LEFT = 1 PAGE_LEFT = 1
PAGE_RIGHT = 2 PAGE_RIGHT = 2
@ -398,7 +397,7 @@ class Section(models.Model):
def filename(self): def filename(self):
return slugify(f'{self.doc.work.name} - {self.name}').title() + '.pdf' return slugify(f'{self.doc.work.name} - {self.name}').title() + '.pdf'
@property @property
def pagerange(self): def pagerange(self):
if self.start: if self.start:
if self.end: if self.end:
@ -408,3 +407,4 @@ class Section(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name