fix typing issue when videos have no votes and their vote count is None not 0 in metadata, resolves #50

This commit is contained in:
meeb 2021-02-17 22:14:29 +11:00
parent 5348e25303
commit 3567e20600
1 changed files with 4 additions and 0 deletions

View File

@ -984,8 +984,12 @@ class Media(models.Model):
def votes(self): def votes(self):
field = self.get_metadata_field('upvotes') field = self.get_metadata_field('upvotes')
upvotes = self.loaded_metadata.get(field, 0) upvotes = self.loaded_metadata.get(field, 0)
if not isinstance(upvotes, int):
upvotes = 0
field = self.get_metadata_field('downvotes') field = self.get_metadata_field('downvotes')
downvotes = self.loaded_metadata.get(field, 0) downvotes = self.loaded_metadata.get(field, 0)
if not isinstance(downvotes, int):
downvotes = 0
return upvotes + downvotes return upvotes + downvotes
@property @property