From 2215e0a894967142edc7408b918acfad4854489c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 9 Mar 2020 17:03:59 -0700 Subject: [PATCH] Threaded-view on status pages It's hideous though, sorry --- fedireads/static/format.css | 24 ++++++++++++++++ fedireads/templates/book.html | 4 +-- fedireads/templates/feed.html | 2 +- fedireads/templates/snippets/activity.html | 28 ------------------- .../templates/snippets/activity_banner.html | 10 +++++++ fedireads/templates/snippets/interaction.html | 2 +- fedireads/templates/snippets/status.html | 20 +++++++++++++ fedireads/templates/snippets/thread.html | 18 ++++++++++++ fedireads/templates/status.html | 12 ++------ fedireads/templatetags/fr_display.py | 10 +++++++ fedireads/views.py | 8 ++---- 11 files changed, 91 insertions(+), 47 deletions(-) delete mode 100644 fedireads/templates/snippets/activity.html create mode 100644 fedireads/templates/snippets/activity_banner.html create mode 100644 fedireads/templates/snippets/status.html create mode 100644 fedireads/templates/snippets/thread.html diff --git a/fedireads/static/format.css b/fedireads/static/format.css index 94e01dbd1..6cd3ba08c 100644 --- a/fedireads/static/format.css +++ b/fedireads/static/format.css @@ -197,3 +197,27 @@ th, td { font-size: 0.8em; color: #FF1654; } + +.comment-thread .reply h2 { + background: none; +} +.post.main { + background-color: #F3FFBD; +} +.post { + margin-left: 4em; + border-left: 2px solid #247BA0; +} +.post.depth-1 { + margin-left: 0; + border: none; +} +.post.depth-2 { + margin-left: 1em; +} +.post.depth-3 { + margin-left: 2em; +} +.post.depth-4 { + margin-left: 3em; +} diff --git a/fedireads/templates/book.html b/fedireads/templates/book.html index 73e3c12d2..f5f55f533 100644 --- a/fedireads/templates/book.html +++ b/fedireads/templates/book.html @@ -20,7 +20,7 @@ {% for review in user_reviews %} - {% include 'snippets/review.html' with review=review %} + {% include 'snippets/status.html' with status=review hide_book=True main=True depth=1 %} {% endfor %} @@ -62,7 +62,7 @@

Average rating: {{ rating | stars }}

{% for review in reviews %} - {% include 'snippets/review.html' with review=review %} + {% include 'snippets/status.html' with status=review hide_book=True main=True depth=1 %} {% endfor %} diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index 9fbb066b3..314abc02d 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -38,7 +38,7 @@ {% include 'snippets/tabs.html' with tabs=feed_tabs active_tab=active_tab %} {% for activity in activities %} - {% include 'snippets/activity.html' with activity=activity %} + {% include 'snippets/status.html' with status=activity depth=1 %} {% endfor %} diff --git a/fedireads/templates/snippets/activity.html b/fedireads/templates/snippets/activity.html deleted file mode 100644 index 405bcd0e2..000000000 --- a/fedireads/templates/snippets/activity.html +++ /dev/null @@ -1,28 +0,0 @@ -{% load fr_display %} -
- {% if activity.status_type == 'Review' %} - {% include 'snippets/activity_banner.html' with content="reviewed "|add:activity.book.title|add:"" %} -
- {% include 'snippets/book.html' with book=activity.book size=large %} - -

{{ activity.name }}

-

{{ activity.rating | stars }}

-

{{ activity.content | safe }}

-
- {% include 'snippets/interaction.html' with activity=activity %} - {% elif activity.status_type == 'Note' %} - {% include 'snippets/activity_banner.html' %} - {{ activity.content | safe }} - {% for book in activity.mention_books.all %} -
- {% include 'snippets/book.html' with book=book size=large description=True %} -
- {% endfor %} - {% include 'snippets/interaction.html' with activity=activity %} - {% else %} - {# generic handling for a misc activity, which perhaps should not be displayed at all #} - did {{ activity.activity_type }} - - {% endif %} -
- diff --git a/fedireads/templates/snippets/activity_banner.html b/fedireads/templates/snippets/activity_banner.html new file mode 100644 index 000000000..f0e997209 --- /dev/null +++ b/fedireads/templates/snippets/activity_banner.html @@ -0,0 +1,10 @@ +{% load humanize %} +

+ {% include 'snippets/avatar.html' with user=activity.user %} + {% include 'snippets/username.html' with user=activity.user %} + {{ content | safe }} + + {{ activity.published_date | naturaltime }} + +

+ diff --git a/fedireads/templates/snippets/interaction.html b/fedireads/templates/snippets/interaction.html index b01f91cc0..13ad6d684 100644 --- a/fedireads/templates/snippets/interaction.html +++ b/fedireads/templates/snippets/interaction.html @@ -11,7 +11,7 @@
{% csrf_token %} - {{ comment_form.content }} +
diff --git a/fedireads/templates/snippets/status.html b/fedireads/templates/snippets/status.html new file mode 100644 index 000000000..19f04b239 --- /dev/null +++ b/fedireads/templates/snippets/status.html @@ -0,0 +1,20 @@ +{% load fr_display %} +
+ {% include 'snippets/activity_banner.html' with activity=status %} + {% if not hide_book and status.mention_books.count %} +
+ {% include 'snippets/book.html' with book=status.mention_books.first %} +
+ {% endif %} + {% if not hide_book and status.book%} +
+ {% include 'snippets/book.html' with book=status.book %} +
+ {% endif %} + {% if status.status_type == 'Review' %}

{{ status.name }} + {{ status.rating | stars }} stars, by {% include 'snippets/username.html' with user=status.user %} +

{% endif %} +
{{ status.content }}
+ {% include 'snippets/interaction.html' with activity=status %} +
+ diff --git a/fedireads/templates/snippets/thread.html b/fedireads/templates/snippets/thread.html new file mode 100644 index 000000000..34da43df9 --- /dev/null +++ b/fedireads/templates/snippets/thread.html @@ -0,0 +1,18 @@ +{% load fr_display %} +{% with depth=depth|add:1 %} + {% if depth <= max_depth and status.reply_parent and direction <= 0 %} + {% with direction=-1 %} + {% include 'snippets/thread.html' with status=status|parent is_root=False %} + {% endwith %} + {% endif %} + +{% include 'snippets/status.html' with status=status main=is_root %} + +{% if depth <= max_depth and direction >= 0 %} + {% for reply in status|replies %} + {% with direction=1 %} + {% include 'snippets/thread.html' with status=reply is_root=False %} + {% endwith %} + {% endfor %} +{% endif %} +{% endwith %} diff --git a/fedireads/templates/status.html b/fedireads/templates/status.html index d3811cf9e..3221b5cd1 100644 --- a/fedireads/templates/status.html +++ b/fedireads/templates/status.html @@ -2,15 +2,9 @@ {% block content %}
- {% if status.reply_parent %} - {% include 'snippets/status.html' with status=status.reply_parent %} - {% endif %} - - {% include 'snippets/status.html' with status=status main=True %} - - {% for reply in replies %} - {% include 'snippets/status.html' with status=reply %} - {% endfor %} +
+ {% include 'snippets/thread.html' with status=status depth=0 max_depth=6 is_root=True direction=0 %} +
{% endblock %} diff --git a/fedireads/templatetags/fr_display.py b/fedireads/templatetags/fr_display.py index 62d861750..ac249c9c9 100644 --- a/fedireads/templatetags/fr_display.py +++ b/fedireads/templatetags/fr_display.py @@ -55,6 +55,16 @@ def get_notification_count(user): return user.notification_set.filter(read=False).count() +@register.filter(name='replies') +def get_replies(status): + return models.Status.objects.filter(reply_parent=status).select_subclasses().all()[:10] + + +@register.filter(name='parent') +def get_parent(status): + return models.Status.objects.filter(id=status.reply_parent_id).select_subclasses().get() + + @register.simple_tag(takes_context=True) def shelve_button_identifier(context, book): ''' check what shelf a user has a book on, if any ''' diff --git a/fedireads/views.py b/fedireads/views.py index 17f183fae..e1d23f2e0 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -56,9 +56,9 @@ def home_tab(request, tab): Q(followers=request.user) | Q(id=request.user.id) ) - activities = models.Status.objects.select_subclasses().order_by( + activities = models.Status.objects.order_by( '-created_date' - ) + ).select_subclasses() if tab == 'home': # people you follow and direct mentions @@ -75,7 +75,6 @@ def home_tab(request, tab): activities = activities[:10] - comment_form = forms.CommentForm() data = { 'user': request.user, 'shelves': shelves, @@ -84,7 +83,6 @@ def home_tab(request, tab): 'activities': activities, 'feed_tabs': ['home', 'local', 'federated'], 'active_tab': tab, - 'comment_form': comment_form, } return TemplateResponse(request, 'feed.html', data) @@ -195,10 +193,8 @@ def status_page(request, username, status_id): if user != status.user: return HttpResponseNotFound() - replies = models.Status.objects.filter(reply_parent=status).select_subclasses().all() data = { 'status': status, - 'replies': replies, } return TemplateResponse(request, 'status.html', data)