fix tags in marks export

This commit is contained in:
Your Name 2022-05-01 18:13:09 -04:00
parent 50754f2686
commit fb632dc28c
6 changed files with 34 additions and 4 deletions

View file

@ -122,6 +122,11 @@ class Book(Entity):
def mark_class(self):
return BookMark
@property
def tag_class(self):
return BookTag
class BookMark(Mark):
book = models.ForeignKey(
Book, on_delete=models.CASCADE, related_name='book_marks', null=True)

View file

@ -192,6 +192,10 @@ class Entity(models.Model):
def mark_class(self):
raise NotImplementedError("Subclass should implement this.")
@property
def tag_class(self):
raise NotImplementedError("Subclass should implement this.")
class UserOwnedEntity(models.Model):
is_private = models.BooleanField(default=False, null=True) # first set allow null, then migration, finally (in a few days) remove for good
@ -281,6 +285,11 @@ class Mark(UserOwnedEntity):
def translated_status(self):
raise NotImplementedError("Subclass should implement this.")
@property
def tags(self):
tags = self.item.tag_class.objects.filter(mark_id=self.id)
return tags
class Meta:
abstract = True
constraints = [

View file

@ -108,6 +108,10 @@ class Game(Entity):
def mark_class(self):
return GameMark
@property
def tag_class(self):
return GameTag
class GameMark(Mark):
game = models.ForeignKey(

View file

@ -235,6 +235,10 @@ class Movie(Entity):
def mark_class(self):
return MovieMark
@property
def tag_class(self):
return MovieTag
class MovieMark(Mark):
movie = models.ForeignKey(Movie, on_delete=models.CASCADE, related_name='movie_marks', null=True)

View file

@ -87,6 +87,10 @@ class Album(Entity):
def mark_class(self):
return AlbumMark
@property
def tag_class(self):
return AlbumTag
class Song(Entity):
'''
@ -142,6 +146,10 @@ class Song(Entity):
def mark_class(self):
return SongMark
@property
def tag_class(self):
return SongTag
class SongMark(Mark):
song = models.ForeignKey(

View file

@ -48,7 +48,7 @@ def export_marks_task(user):
movie = mark.movie
title = movie.title
summary = str(movie.year) + ' / ' + ','.join(movie.area) + ' / ' + ','.join(map(lambda x: str(MovieGenreTranslator[x]), movie.genre)) + ' / ' + ','.join(movie.director) + ' / ' + ','.join(movie.actor)
tags = ','.join(list(set(map(lambda t: t['content'], movie.get_tags_manager().values()))))
tags = ','.join(list(map(lambda m: m.content, mark.tags)))
world_rating = (movie.rating / 2) if movie.rating else None
timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S')
my_rating = (mark.rating / 2) if mark.rating else None
@ -66,7 +66,7 @@ def export_marks_task(user):
album = mark.album
title = album.title
summary = ','.join(album.artist) + ' / ' + (album.release_date.strftime('%Y') if album.release_date else '')
tags = ','.join(list(set(map(lambda t: t['content'], album.get_tags_manager().values()))))
tags = ','.join(list(map(lambda m: m.content, mark.tags)))
world_rating = (album.rating / 2) if album.rating else None
timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S')
my_rating = (mark.rating / 2) if mark.rating else None
@ -84,7 +84,7 @@ def export_marks_task(user):
book = mark.book
title = book.title
summary = ','.join(book.author) + ' / ' + str(book.pub_year) + ' / ' + book.pub_house
tags = ','.join(list(set(map(lambda t: t['content'], book.get_tags_manager().values()))))
tags = ','.join(list(map(lambda m: m.content, mark.tags)))
world_rating = (book.rating / 2) if book.rating else None
timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S')
my_rating = (mark.rating / 2) if mark.rating else None
@ -102,7 +102,7 @@ def export_marks_task(user):
game = mark.game
title = game.title
summary = ','.join(game.genre) + ' / ' + ','.join(game.platform) + ' / ' + (game.release_date.strftime('%Y-%m-%d') if game.release_date else '')
tags = ','.join(list(set(map(lambda t: t['content'], game.get_tags_manager().values()))))
tags = ','.join(list(map(lambda m: m.content, mark.tags)))
world_rating = (game.rating / 2) if game.rating else None
timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S')
my_rating = (mark.rating / 2) if mark.rating else None