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

Add Following tab to the user profile view #1463

Merged
merged 8 commits into from
Nov 11, 2022
34 changes: 34 additions & 0 deletions project/accounts/templates/accounts/profile_following.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="following-total">
<div>
{% blocktranslate %}
{{ profile.following.count }} following
{% endblocktranslate %}
</div>
</div>
{% for following in profile.following.all %}
<div class="col s12 m6">
<div class="user-chip chip white">
<div class="user-chip-contents">
<a href="/profile/{{ following.user.username }}/">
<img src="{{ following.profile_image_url }}" alt="{{ following.user.username }}">
</a>
</div>
</div>
</div>
{% empty %}
<div class="section no-state">
<div class="container">
<div class="section">
<div class="center title-lato grey-text">
{% translate "Not following any users" %}
</div>
</div>
</div>
</div>
{% endfor %}

{% endblock content %}
6 changes: 6 additions & 0 deletions project/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ProfileUnfollow,
RegisterView,
SettingsView,
ProfileFollowing,
UserProfileView,
expunge_user,
)
Expand Down Expand Up @@ -37,6 +38,11 @@
ProfileUnfollow.as_view(),
name="profile-unfollow",
),
path(
"profile/<str:username>/following",
ProfileFollowing.as_view(),
name="profile-following",
),
path(
"accounts/password_reset/",
PasswordResetView.as_view(),
Expand Down
18 changes: 18 additions & 0 deletions project/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ def get(self, request, username=None):
)


class ProfileFollowing(LoginRequiredMixin, View):
"""
A view that shows list of profiles
that profile with given username is following
"""

def get(self, request, username=None):
profile = get_object_or_404(Profile, user__username=username)

return TemplateResponse(
request,
"profile_following.html",
{
"profile": profile,
},
)


@login_required
def expunge_user(request):
"""
Expand Down