calender renders podcast and tv episode comments

This commit is contained in:
Her Email 2023-11-22 22:06:19 -05:00 committed by Henri Dickson
parent 3d9cf5a853
commit a10e7ffc0a
4 changed files with 46 additions and 22 deletions

View file

@ -282,23 +282,44 @@ class ShelfManager:
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

View file

@ -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 += '<rect class="day" width="11" height="11" y="' + y + '" fill="' + color + match_today + '" data-items="' + items_str + '" data-legend="' + legend + '" data-date="' + data_date + '"/>';
item_html += '<rect class="day" ' + (items.length<2 ? 'rx="2" ry="2"' : '') + ' width="11" height="11" y="' + y + '" fill="' + color + match_today + '" data-items="' + items_str + '" data-legend="' + legend + '" data-date="' + data_date + '"/>';
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'];

View file

@ -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'
}
});
</script>

View file

@ -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 %}
<script src="{% static 'js/calendar_yearview_blocks.js' %}" defer></script>
<script src="{% static 'js/calendar_yearview_blocks.js' %}?xxxxdd" defer></script>
<link href="{% static 'css/calendar_yearview_blocks.css' %}"
media="all"
rel="stylesheet" />