diff --git a/journal/models/shelf.py b/journal/models/shelf.py index 58d41ba1..c959c008 100644 --- a/journal/models/shelf.py +++ b/journal/models/shelf.py @@ -282,23 +282,44 @@ def get_calendar_data(self, max_visiblity: int): timezone_offset = timezone.localtime(timezone.now()).strftime("%z") timezone_offset = timezone_offset[: len(timezone_offset) - 2] calendar_data = {} - sql = "SELECT to_char(DATE(journal_shelfmember.created_time::timestamp AT TIME ZONE %s), 'YYYY-MM-DD') AS dat, django_content_type.model typ, COUNT(1) count FROM journal_shelfmember, catalog_item, django_content_type WHERE journal_shelfmember.item_id = catalog_item.id AND django_content_type.id = catalog_item.polymorphic_ctype_id AND parent_id = %s AND journal_shelfmember.created_time >= NOW() - INTERVAL '366 days' AND journal_shelfmember.visibility <= %s GROUP BY item_id, dat, typ;" - with connection.cursor() as cursor: - cursor.execute(sql, [timezone_offset, shelf_id, int(max_visiblity)]) - data = cursor.fetchall() - for line in data: - date = line[0] - typ = line[1] - if date not in calendar_data: - calendar_data[date] = {"items": []} - if typ[:2] == "tv": - typ = "movie" - elif typ == "album": - typ = "music" - elif typ == "edition": - typ = "book" - elif typ not in ["book", "movie", "music", "game"]: - typ = "other" - if typ not in calendar_data[date]["items"]: - calendar_data[date]["items"].append(typ) + queries = [ + ( + "SELECT to_char(DATE(journal_shelfmember.created_time::timestamp AT TIME ZONE %s), 'YYYY-MM-DD') AS dat, django_content_type.model typ, COUNT(1) count FROM journal_shelfmember, catalog_item, django_content_type WHERE journal_shelfmember.item_id = catalog_item.id AND django_content_type.id = catalog_item.polymorphic_ctype_id AND parent_id = %s AND journal_shelfmember.created_time >= NOW() - INTERVAL '366 days' AND journal_shelfmember.visibility <= %s GROUP BY item_id, dat, typ;", + [timezone_offset, shelf_id, int(max_visiblity)], + ), + ( + "SELECT to_char(DATE(journal_comment.created_time::timestamp AT TIME ZONE %s), 'YYYY-MM-DD') AS dat, django_content_type.model typ, COUNT(1) count FROM journal_comment, catalog_item, django_content_type WHERE journal_comment.item_id = catalog_item.id AND django_content_type.id = catalog_item.polymorphic_ctype_id AND journal_comment.created_time >= NOW() - INTERVAL '366 days' AND journal_comment.visibility <= %s GROUP BY item_id, dat, typ;", + [timezone_offset, int(max_visiblity)], + ), + ] + for sql, params in queries: + with connection.cursor() as cursor: + cursor.execute(sql, params) + data = cursor.fetchall() + for line in data: + date = line[0] + typ = line[1] + if date not in calendar_data: + calendar_data[date] = {"items": []} + if typ[:2] == "tv": + typ = "tv" + elif typ[:7] == "podcast": + typ = "podcast" + elif typ == "album": + typ = "music" + elif typ == "edition": + typ = "book" + elif typ not in [ + "book", + "movie", + "tv", + "music", + "game", + "podcast", + "performance", + ]: + print(typ) + typ = "other" + if typ not in calendar_data[date]["items"]: + calendar_data[date]["items"].append(typ) return calendar_data diff --git a/journal/static/js/calendar_yearview_blocks.js b/journal/static/js/calendar_yearview_blocks.js index 40826d1a..9656e743 100644 --- a/journal/static/js/calendar_yearview_blocks.js +++ b/journal/static/js/calendar_yearview_blocks.js @@ -105,7 +105,7 @@ var color = settings.colors[item_name]?settings.colors[item_name]:settings.colors['default']; // Fill a square for the 1st item - item_html += ''; + item_html += ''; if (items.length === 2) { // Fill a trangle for the 2nd var item_name_1 = items[1]?items[1]:false; var color_1 = settings.colors[item_name_1]?settings.colors[item_name_1]:settings.colors['default']; diff --git a/journal/templates/calendar_data.html b/journal/templates/calendar_data.html index 148b8c00..1dbb6d0a 100644 --- a/journal/templates/calendar_data.html +++ b/journal/templates/calendar_data.html @@ -10,9 +10,12 @@ 'default': getComputedStyle(document.documentElement).getPropertyValue('--pico-form-element-background-color'), 'book': '#B4D2A5', 'movie': '#7CBDFE', + 'tv': '#FDDB23', 'music': '#FEA36D', 'game': '#C5A290', - 'other': '#9D6AB0' + 'podcast': '#9D6AB0', + 'performance': '#FE7C7C', + 'other': '#FED37C' } }); diff --git a/journal/templates/profile.html b/journal/templates/profile.html index 43e79b51..b688bed7 100644 --- a/journal/templates/profile.html +++ b/journal/templates/profile.html @@ -26,7 +26,7 @@ title="{{ site_name }} - {{ identity.handler }}的评论" href="{{ request.build_absolute_uri }}feed/reviews/"> {% include "common_libs.html" with jquery=0 v2=1 %} - +