Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calender renders podcast and tv episode comments #393

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions journal/models/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion journal/static/js/calendar_yearview_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
5 changes: 4 additions & 1 deletion journal/templates/calendar_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion journal/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down