Spaces:
Runtime error
Runtime error
An Hang
commited on
custom display of posts (#42)
Browse files- src/social/templates/social/comment_delete.html +1 -1
- src/social/templates/social/post_detail.html +21 -9
- src/social/templates/social/post_list.html +10 -3
- src/social/templates/social/profile.html +12 -5
- src/social/templates/social/search.html +31 -0
- src/social/urls.py +2 -3
- src/social/views.py +23 -3
src/social/templates/social/comment_delete.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<div class="container">
|
| 5 |
<div class="row mt-5">
|
| 6 |
<div class="col-md-5 col-sm-6">
|
| 7 |
-
<a href="{% url 'post-detail' object.pk %}" class="btn btn-light">Back To Post</a>
|
| 8 |
</div>
|
| 9 |
</div>
|
| 10 |
|
|
|
|
| 4 |
<div class="container">
|
| 5 |
<div class="row mt-5">
|
| 6 |
<div class="col-md-5 col-sm-6">
|
| 7 |
+
<a href="{% url 'post-detail' object.post.pk %}" class="btn btn-light">Back To Post</a>
|
| 8 |
</div>
|
| 9 |
</div>
|
| 10 |
|
src/social/templates/social/post_detail.html
CHANGED
|
@@ -11,20 +11,25 @@
|
|
| 11 |
|
| 12 |
<div class="row justify-content-center mt-3">
|
| 13 |
<div class="col-md-5 col-sm-12 border-bottom">
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
{% if request.user == post.author %}
|
| 17 |
-
<a href="{% url 'post-edit' post.pk %}"
|
| 18 |
-
<a href="{% url 'post-delete' post.pk %}"
|
| 19 |
{% endif %}
|
| 20 |
-
</p>
|
| 21 |
<p>{{ post.body }}</p>
|
| 22 |
|
| 23 |
<div class="d-flex flex-row">
|
| 24 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 25 |
{% csrf_token %}
|
| 26 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 27 |
-
<button
|
| 28 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 29 |
</button>
|
| 30 |
</form>
|
|
@@ -32,7 +37,7 @@
|
|
| 32 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 33 |
{% csrf_token %}
|
| 34 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 35 |
-
<button
|
| 36 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 37 |
</button>
|
| 38 |
</form>
|
|
@@ -55,9 +60,16 @@
|
|
| 55 |
<div class="row justify-content-center mt-3 mb-5">
|
| 56 |
<div class="col-md-5 col-sm-12 border-bottom">
|
| 57 |
<p>
|
| 58 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
{% if request.user == comment.author %}
|
| 60 |
-
<a href="{% url 'comment-delete' post.pk comment.pk %}"
|
| 61 |
{% endif %}
|
| 62 |
</p>
|
| 63 |
<p>{{ comment.comment }}</p>
|
|
|
|
| 11 |
|
| 12 |
<div class="row justify-content-center mt-3">
|
| 13 |
<div class="col-md-5 col-sm-12 border-bottom">
|
| 14 |
+
<div>
|
| 15 |
+
<a href="{% url 'profile' post.author.profile.pk %}">
|
| 16 |
+
<img class="round-circle post-img" height="30" width="30" src="{{ post.author.profile.picture.url }}" />
|
| 17 |
+
</a>
|
| 18 |
+
<p class="post-text">
|
| 19 |
+
<a class="text-primary post-link" href="{% url 'profile' post.author.profile.pk %}">@{{ post.author }}</a> {{ post.created_on }}
|
| 20 |
+
</p>
|
| 21 |
+
</div>
|
| 22 |
{% if request.user == post.author %}
|
| 23 |
+
<a href="{% url 'post-edit' post.pk %}" class="edit-color"><i class="far fa-edit"></i></a>
|
| 24 |
+
<a href="{% url 'post-delete' post.pk %}" class="edit-color"><i class="fas fa-trash"></i></a>
|
| 25 |
{% endif %}
|
|
|
|
| 26 |
<p>{{ post.body }}</p>
|
| 27 |
|
| 28 |
<div class="d-flex flex-row">
|
| 29 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 30 |
{% csrf_token %}
|
| 31 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 32 |
+
<button class="remove-default-btn" type="submit">
|
| 33 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 34 |
</button>
|
| 35 |
</form>
|
|
|
|
| 37 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 38 |
{% csrf_token %}
|
| 39 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 40 |
+
<button class="remove-default-btn" type="submit">
|
| 41 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 42 |
</button>
|
| 43 |
</form>
|
|
|
|
| 60 |
<div class="row justify-content-center mt-3 mb-5">
|
| 61 |
<div class="col-md-5 col-sm-12 border-bottom">
|
| 62 |
<p>
|
| 63 |
+
<div>
|
| 64 |
+
<a href="{% url 'profile' comment.author.profile.pk %}">
|
| 65 |
+
<img class="round-circle post-img" height="30" width="30" src="{{ comment.author.profile.picture.url }}" />
|
| 66 |
+
</a>
|
| 67 |
+
<p class="post-text">
|
| 68 |
+
<a class="text-primary post-link" href="{% url 'profile' comment.author.profile.pk %}">@{{ comment.author }}</a> {{ comment.created_on }}
|
| 69 |
+
</p>
|
| 70 |
+
</div>
|
| 71 |
{% if request.user == comment.author %}
|
| 72 |
+
<a href="{% url 'comment-delete' post.pk comment.pk %}" class="edit-color"><i class="fas fa-trash"></i></a>
|
| 73 |
{% endif %}
|
| 74 |
</p>
|
| 75 |
<p>{{ comment.comment }}</p>
|
src/social/templates/social/post_list.html
CHANGED
|
@@ -24,7 +24,14 @@
|
|
| 24 |
{% for post in post_list %}
|
| 25 |
<div class="row justify-content-center mt-3">
|
| 26 |
<div class="col-md-5 col-sm-12 border-bottom position-relative">
|
| 27 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
<div class="position-relative">
|
| 29 |
<p>{{ post.body }}</p>
|
| 30 |
<a href="{% url 'post-detail' post.pk %}" class="stretched-link"></a>
|
|
@@ -34,7 +41,7 @@
|
|
| 34 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 35 |
{% csrf_token %}
|
| 36 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 37 |
-
<button
|
| 38 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 39 |
</button>
|
| 40 |
</form>
|
|
@@ -42,7 +49,7 @@
|
|
| 42 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 43 |
{% csrf_token %}
|
| 44 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 45 |
-
<button
|
| 46 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 47 |
</button>
|
| 48 |
</form>
|
|
|
|
| 24 |
{% for post in post_list %}
|
| 25 |
<div class="row justify-content-center mt-3">
|
| 26 |
<div class="col-md-5 col-sm-12 border-bottom position-relative">
|
| 27 |
+
<div>
|
| 28 |
+
<a href="{% url 'profile' post.author.profile.pk %}">
|
| 29 |
+
<img class="round-circle post-img" height="30" width="30" src="{{ post.author.profile.picture.url }}" />
|
| 30 |
+
</a>
|
| 31 |
+
<p class="post-text">
|
| 32 |
+
<a class="text-primary post-link" href="{% url 'profile' post.author.profile.pk %}">@{{ post.author }}</a> {{ post.created_on }}
|
| 33 |
+
</p>
|
| 34 |
+
</div>
|
| 35 |
<div class="position-relative">
|
| 36 |
<p>{{ post.body }}</p>
|
| 37 |
<a href="{% url 'post-detail' post.pk %}" class="stretched-link"></a>
|
|
|
|
| 41 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 42 |
{% csrf_token %}
|
| 43 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 44 |
+
<button class="remove-default-btn" type="submit">
|
| 45 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 46 |
</button>
|
| 47 |
</form>
|
|
|
|
| 49 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 50 |
{% csrf_token %}
|
| 51 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 52 |
+
<button class="remove-default-btn" type="submit">
|
| 53 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 54 |
</button>
|
| 55 |
</form>
|
src/social/templates/social/profile.html
CHANGED
|
@@ -15,14 +15,14 @@
|
|
| 15 |
<h3 class="py-4">{{ profile.name }}
|
| 16 |
<span>
|
| 17 |
{% if request.user == user %}
|
| 18 |
-
<a href="{% url 'profile-edit' profile.pk %}"
|
| 19 |
{% endif %}
|
| 20 |
</span>
|
| 21 |
{% else %}
|
| 22 |
<h3 class="py-4">{{ user.username }}
|
| 23 |
<span>
|
| 24 |
{% if request.user == user %}
|
| 25 |
-
<a href="{% url 'profile-edit' profile.pk %}"
|
| 26 |
{% endif %}
|
| 27 |
</span>
|
| 28 |
</h3>
|
|
@@ -64,7 +64,14 @@
|
|
| 64 |
{% for post in posts %}
|
| 65 |
<div class="row justify-content-center mt-5">
|
| 66 |
<div class="col-md-8 col-sm-12 border-bottom">
|
| 67 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
<div class="position-relative">
|
| 69 |
<p>{{ post.body }}</p>
|
| 70 |
<a href="{% url 'post-detail' post.pk %}" class="stretched-link"></a>
|
|
@@ -74,7 +81,7 @@
|
|
| 74 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 75 |
{% csrf_token %}
|
| 76 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 77 |
-
<button
|
| 78 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 79 |
</button>
|
| 80 |
</form>
|
|
@@ -82,7 +89,7 @@
|
|
| 82 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 83 |
{% csrf_token %}
|
| 84 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 85 |
-
<button
|
| 86 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 87 |
</button>
|
| 88 |
</form>
|
|
|
|
| 15 |
<h3 class="py-4">{{ profile.name }}
|
| 16 |
<span>
|
| 17 |
{% if request.user == user %}
|
| 18 |
+
<a href="{% url 'profile-edit' profile.pk %}" class="edit-color"><i class="far fa-edit"></i></a>
|
| 19 |
{% endif %}
|
| 20 |
</span>
|
| 21 |
{% else %}
|
| 22 |
<h3 class="py-4">{{ user.username }}
|
| 23 |
<span>
|
| 24 |
{% if request.user == user %}
|
| 25 |
+
<a href="{% url 'profile-edit' profile.pk %}" class="edit-color"><i class="far fa-edit"></i></a>
|
| 26 |
{% endif %}
|
| 27 |
</span>
|
| 28 |
</h3>
|
|
|
|
| 64 |
{% for post in posts %}
|
| 65 |
<div class="row justify-content-center mt-5">
|
| 66 |
<div class="col-md-8 col-sm-12 border-bottom">
|
| 67 |
+
<div>
|
| 68 |
+
<a href="{% url 'profile' post.author.profile.pk %}">
|
| 69 |
+
<img class="round-circle post-img" height="30" width="30" src="{{ post.author.profile.picture.url }}" />
|
| 70 |
+
</a>
|
| 71 |
+
<p class="post-text">
|
| 72 |
+
<a class="text-primary post-link" href="{% url 'profile' post.author.profile.pk %}">@{{ post.author }}</a> {{ post.created_on }}
|
| 73 |
+
</p>
|
| 74 |
+
</div>
|
| 75 |
<div class="position-relative">
|
| 76 |
<p>{{ post.body }}</p>
|
| 77 |
<a href="{% url 'post-detail' post.pk %}" class="stretched-link"></a>
|
|
|
|
| 81 |
<form method="POST" action="{% url 'like' post.pk %}">
|
| 82 |
{% csrf_token %}
|
| 83 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 84 |
+
<button class="remove-default-btn" type="submit">
|
| 85 |
<i class="far fa-thumbs-up"> <span>{{ post.likes.all.count }}</span></i>
|
| 86 |
</button>
|
| 87 |
</form>
|
|
|
|
| 89 |
<form method="POST" action="{% url 'dislike' post.pk %}">
|
| 90 |
{% csrf_token %}
|
| 91 |
<input type="hidden" name="next" value="{{ request.path }}">
|
| 92 |
+
<button class="remove-default-btn" type="submit">
|
| 93 |
<i class="far fa-thumbs-down"> <span>{{ post.dislikes.all.count }}</span></i>
|
| 94 |
</button>
|
| 95 |
</form>
|
src/social/templates/social/search.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends 'landing/base.html' %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="container">
|
| 5 |
+
<div class="row mt-5">
|
| 6 |
+
<div class="col-md-5 col-sm-6">
|
| 7 |
+
<a href="{% url 'post-list' %}" class="btn btn-light">Back To Feed</a>
|
| 8 |
+
</div>
|
| 9 |
+
</div>
|
| 10 |
+
|
| 11 |
+
{% for profile in profile_list %}
|
| 12 |
+
<div class="row justify-content-center mt-3">
|
| 13 |
+
<div class="col-md-5 col-sm-12 border-bottom position-relative">
|
| 14 |
+
<div>
|
| 15 |
+
<a href="{% url 'profile' profile.pk %}">
|
| 16 |
+
<img class="round-circle post-img" height="30" width="30" src="{{ profile.picture.url }}" />
|
| 17 |
+
</a>
|
| 18 |
+
<p class="post-text">
|
| 19 |
+
<a class="text-primary post-link" href="{% url 'profile' profile.pk %}">@{{ profile.user }}</a>
|
| 20 |
+
</p>
|
| 21 |
+
</div>
|
| 22 |
+
<p><a class="text-primary post-link" href="{% url 'profile' profile.pk %}">@{{ profile.user }}</a></p>
|
| 23 |
+
{% if profile.location %}
|
| 24 |
+
<p>{{ profile.location }}</p>
|
| 25 |
+
{% endif %}
|
| 26 |
+
<p>Followers: {{ profile.followers.all.count }}</p>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
{% endfor %}
|
| 30 |
+
</div>
|
| 31 |
+
{% endblock content %}
|
src/social/urls.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from django.urls import path
|
| 2 |
-
from .views import PostListView, PostDetailView, PostEditView, PostDeleteView, CommentDeleteView, ProfileView, ProfileEditView, AddFollower, RemoveFollower, AddLike, AddDislike
|
| 3 |
|
| 4 |
urlpatterns = [
|
| 5 |
path('', PostListView.as_view(), name='post-list'),
|
|
@@ -13,6 +13,5 @@ urlpatterns = [
|
|
| 13 |
path('profile/edit/<int:pk>/', ProfileEditView.as_view(), name='profile-edit'),
|
| 14 |
path('profile/<int:pk>/followers/add', AddFollower.as_view(), name='add-follower'),
|
| 15 |
path('profile/<int:pk>/followers/remove', RemoveFollower.as_view(), name='remove-follower'),
|
| 16 |
-
|
| 17 |
-
|
| 18 |
]
|
|
|
|
| 1 |
from django.urls import path
|
| 2 |
+
from .views import PostListView, PostDetailView, PostEditView, PostDeleteView, CommentDeleteView, ProfileView, ProfileEditView, AddFollower, RemoveFollower, AddLike, AddDislike, UserSearch
|
| 3 |
|
| 4 |
urlpatterns = [
|
| 5 |
path('', PostListView.as_view(), name='post-list'),
|
|
|
|
| 13 |
path('profile/edit/<int:pk>/', ProfileEditView.as_view(), name='profile-edit'),
|
| 14 |
path('profile/<int:pk>/followers/add', AddFollower.as_view(), name='add-follower'),
|
| 15 |
path('profile/<int:pk>/followers/remove', RemoveFollower.as_view(), name='remove-follower'),
|
| 16 |
+
path('search/', UserSearch.as_view(), name='profile-search'),
|
|
|
|
| 17 |
]
|
src/social/views.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from django.shortcuts import render, redirect
|
|
|
|
| 2 |
from django.urls import reverse_lazy
|
| 3 |
from django.http import HttpResponseRedirect
|
| 4 |
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
|
@@ -10,7 +11,10 @@ from django.views.generic.edit import UpdateView, DeleteView
|
|
| 10 |
|
| 11 |
class PostListView(LoginRequiredMixin, View):
|
| 12 |
def get(self, request, *args, **kwargs):
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
form = PostForm()
|
| 15 |
|
| 16 |
context = {
|
|
@@ -21,7 +25,10 @@ class PostListView(LoginRequiredMixin, View):
|
|
| 21 |
return render(request, 'social/post_list.html', context)
|
| 22 |
|
| 23 |
def post(self, request, *args, **kwargs):
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
form = PostForm(request.POST)
|
| 26 |
|
| 27 |
if form.is_valid():
|
|
@@ -219,4 +226,17 @@ class AddDislike(LoginRequiredMixin, View):
|
|
| 219 |
post.dislikes.remove(request.user)
|
| 220 |
|
| 221 |
next = request.POST.get('next', '/')
|
| 222 |
-
return HttpResponseRedirect(next)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from django.shortcuts import render, redirect
|
| 2 |
+
from django.db.models import Q
|
| 3 |
from django.urls import reverse_lazy
|
| 4 |
from django.http import HttpResponseRedirect
|
| 5 |
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
|
|
|
| 11 |
|
| 12 |
class PostListView(LoginRequiredMixin, View):
|
| 13 |
def get(self, request, *args, **kwargs):
|
| 14 |
+
logged_in_user = request.user
|
| 15 |
+
posts = Post.objects.filter(
|
| 16 |
+
author__profile__followers__in=[logged_in_user.id]
|
| 17 |
+
).order_by('-created_on')
|
| 18 |
form = PostForm()
|
| 19 |
|
| 20 |
context = {
|
|
|
|
| 25 |
return render(request, 'social/post_list.html', context)
|
| 26 |
|
| 27 |
def post(self, request, *args, **kwargs):
|
| 28 |
+
logged_in_user = request.user
|
| 29 |
+
posts = Post.objects.filter(
|
| 30 |
+
author__profile__followers__in=[logged_in_user.id]
|
| 31 |
+
).order_by('-created_on')
|
| 32 |
form = PostForm(request.POST)
|
| 33 |
|
| 34 |
if form.is_valid():
|
|
|
|
| 226 |
post.dislikes.remove(request.user)
|
| 227 |
|
| 228 |
next = request.POST.get('next', '/')
|
| 229 |
+
return HttpResponseRedirect(next)
|
| 230 |
+
|
| 231 |
+
class UserSearch(View):
|
| 232 |
+
def get(self, request, *args, **kwargs):
|
| 233 |
+
query = self.request.GET.get('query')
|
| 234 |
+
profile_list = UserProfile.objects.filter(
|
| 235 |
+
Q(user__username__icontains=query)
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
context = {
|
| 239 |
+
'profile_list': profile_list,
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
return render(request, 'social/search.html', context)
|