show recent posts in profile
This commit is contained in:
parent
ecc9bafb94
commit
ba479c98b5
6 changed files with 82 additions and 44 deletions
|
@ -46,46 +46,7 @@
|
|||
<article>
|
||||
<details class="auto-collapse" open>
|
||||
<summary>{% trans 'Popular Posts' %}</summary>
|
||||
<div style="font-size:80%">
|
||||
{% for post in popular_posts %}
|
||||
<section class="activity">
|
||||
<div>
|
||||
<span class="action">
|
||||
{# <span class="timestamp">{{ post.created|date }}</span> #}
|
||||
{% include "action_reply_post.html" %}
|
||||
{% include "action_like_post.html" %}
|
||||
{% include "action_boost_post.html" %}
|
||||
{% include "action_open_post.html" %}
|
||||
</span>
|
||||
<!--span class="avatar" style="margin:0.5em;">
|
||||
<img src="{{ post.author.icon_uri }}" alt="cover" />
|
||||
</span -->
|
||||
<span style="">
|
||||
<a href="{{ post.author.url }}"
|
||||
class="nickname"
|
||||
title="@{{ post.author.handle }}">{{ post.author.name }}</a>
|
||||
</span>
|
||||
<div>{{ post.summary|default:'' }}</div>
|
||||
<div {% if post.summary or post.sensitive %}class="spoiler" _="on click toggle .revealed on me"{% endif %}>
|
||||
<div>
|
||||
{% for attachment in post.attachments.all %}
|
||||
{% if attachment.is_image %}
|
||||
<img src="{{ attachment.full_url.relative }}"
|
||||
alt="attachment.file_display_name"
|
||||
style="max-height:6em;
|
||||
max-width:50%">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{{ post.content|bleach:"a,p,span,br,div,img"|default:"" }}
|
||||
</div>
|
||||
</div>
|
||||
<div id="replies_{{ post.pk }}"></div>
|
||||
</section>
|
||||
{% empty %}
|
||||
<div class="empty">{% trans "nothing so far." %}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div style="font-size:80%">{% include "posts.html" with posts=popular_posts %}</div>
|
||||
</details>
|
||||
</article>
|
||||
</section>
|
||||
|
@ -273,6 +234,16 @@
|
|||
</article>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if recent_posts is not None %}
|
||||
<section>
|
||||
<article>
|
||||
<details class="auto-collapse" open>
|
||||
<summary>{% trans 'Recent Posts' %}</summary>
|
||||
<div style="font-size:80%">{% include "posts.html" with posts=recent_posts %}</div>
|
||||
</details>
|
||||
</article>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if sidebar_template %}
|
||||
{% include sidebar_template %}
|
||||
{% endif %}
|
||||
|
|
41
journal/templates/posts.html
Normal file
41
journal/templates/posts.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
{% load bleach_tags %}
|
||||
{% load humanize %}
|
||||
{% load i18n %}
|
||||
{% for post in posts %}
|
||||
<section class="activity">
|
||||
<div>
|
||||
<span class="action">
|
||||
{# <span class="timestamp">{{ post.created|date }}</span> #}
|
||||
{% include "action_reply_post.html" %}
|
||||
{% include "action_like_post.html" %}
|
||||
{% include "action_boost_post.html" %}
|
||||
{% include "action_open_post.html" %}
|
||||
</span>
|
||||
<!--span class="avatar" style="margin:0.5em;">
|
||||
<img src="{{ post.author.icon_uri }}" alt="cover" />
|
||||
</span -->
|
||||
<span style="">
|
||||
<a href="{{ post.author.url }}"
|
||||
class="nickname"
|
||||
title="@{{ post.author.handle }}">{{ post.author.name }}</a>
|
||||
</span>
|
||||
<div>{{ post.summary|default:'' }}</div>
|
||||
<div {% if post.summary or post.sensitive %}class="spoiler" _="on click toggle .revealed on me"{% endif %}>
|
||||
<div>
|
||||
{% for attachment in post.attachments.all %}
|
||||
{% if attachment.is_image %}
|
||||
<img src="{{ attachment.full_url.relative }}"
|
||||
alt="attachment.file_display_name"
|
||||
style="max-height:6em;
|
||||
max-width:50%">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{{ post.content|bleach:"a,p,span,br,div,img"|default:"" }}
|
||||
</div>
|
||||
</div>
|
||||
<div id="replies_{{ post.pk }}"></div>
|
||||
</section>
|
||||
{% empty %}
|
||||
<div class="empty">{% trans "nothing so far." %}</div>
|
||||
{% endfor %}
|
|
@ -7,6 +7,7 @@ from django.views.decorators.http import require_http_methods
|
|||
|
||||
from catalog.models import *
|
||||
from common.utils import AuthedHttpRequest
|
||||
from takahe.utils import Takahe
|
||||
|
||||
from ..forms import *
|
||||
from ..models import *
|
||||
|
@ -17,10 +18,8 @@ from .common import profile_identity_required, target_identity_required
|
|||
@profile_identity_required
|
||||
def profile(request: AuthedHttpRequest, user_name):
|
||||
target = request.target_identity
|
||||
|
||||
if not request.user.is_authenticated and (
|
||||
not target.local or not target.anonymous_viewable
|
||||
):
|
||||
anonymous = not request.user.is_authenticated
|
||||
if anonymous and (not target.local or not target.anonymous_viewable):
|
||||
return render(
|
||||
request,
|
||||
"users/home_anonymous.html",
|
||||
|
@ -95,6 +94,10 @@ def profile(request: AuthedHttpRequest, user_name):
|
|||
year = today.year - 1
|
||||
else:
|
||||
year = None
|
||||
if anonymous:
|
||||
recent_posts = None
|
||||
else:
|
||||
recent_posts = Takahe.get_recent_posts(target.pk, request.user.identity.pk)[:10]
|
||||
return render(
|
||||
request,
|
||||
"profile.html",
|
||||
|
@ -103,6 +106,7 @@ def profile(request: AuthedHttpRequest, user_name):
|
|||
"identity": target,
|
||||
"me": me,
|
||||
"top_tags": top_tags,
|
||||
"recent_posts": recent_posts,
|
||||
"shelf_list": shelf_list,
|
||||
"collections": collections[:10],
|
||||
"collections_count": collections.count(),
|
||||
|
|
|
@ -850,6 +850,12 @@ class Migration(migrations.Migration):
|
|||
default=True, help_text="Also follow boosts from this user"
|
||||
),
|
||||
),
|
||||
(
|
||||
"notify",
|
||||
models.BooleanField(
|
||||
default=False, help_text="Notify about posts from this user"
|
||||
),
|
||||
),
|
||||
("uri", models.CharField(blank=True, max_length=500, null=True)),
|
||||
("note", models.TextField(blank=True, null=True)),
|
||||
("state", models.CharField(default="unrequested", max_length=100)),
|
||||
|
|
|
@ -751,6 +751,9 @@ class Follow(models.Model):
|
|||
boosts = models.BooleanField(
|
||||
default=True, help_text="Also follow boosts from this user"
|
||||
)
|
||||
notify = models.BooleanField(
|
||||
default=False, help_text="Notify about posts from this user"
|
||||
)
|
||||
|
||||
uri = models.CharField(blank=True, null=True, max_length=500)
|
||||
note = models.TextField(blank=True, null=True)
|
||||
|
|
|
@ -985,3 +985,16 @@ class Takahe:
|
|||
.filter(num_interactions__gt=0)
|
||||
.order_by("-num_interactions", "-published")[:limit]
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_recent_posts(author_pk: int, viewer_pk: int | None = None):
|
||||
qs = (
|
||||
Post.objects.exclude(state__in=["deleted", "deleted_fanned_out"])
|
||||
.filter(author_id=author_pk)
|
||||
.order_by("-published")
|
||||
)
|
||||
if viewer_pk and Takahe.get_is_following(viewer_pk, author_pk):
|
||||
qs = qs.exclude(visibility=3)
|
||||
else:
|
||||
qs = qs.filter(visibility__in=[0, 1, 4])
|
||||
return qs.prefetch_related("attachments", "author")
|
||||
|
|
Loading…
Add table
Reference in a new issue