Skip to content

Commit

Permalink
refactor: refactoring post_view and show_post_view
Browse files Browse the repository at this point in the history
adding verified_email_required decorator because Only authenticated users can use this section
  • Loading branch information
rzashakeri committed Jul 26, 2022
1 parent 2533fc1 commit 9e3f827
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions post/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import json

from allauth.account.decorators import verified_email_required
from django.http import HttpResponse
from django.shortcuts import redirect, render

from post.models import PostLike, Post


@verified_email_required
def post_view(request, post_id):
if request.user.is_authenticated:
post = Post.objects.get(pk=post_id)
is_liked = PostLike.objects.filter(post=post, user=request.user).exists()
context = {"post": post, "is_liked": is_liked}
return render(request, "post/post.html", context)
else:
return redirect("account_login")
post = Post.objects.get(pk=post_id)
is_liked = PostLike.objects.filter(post=post, user=request.user).exists()
context = {"post": post, "is_liked": is_liked}
return render(request, "post/post.html", context)


def like_view(request, post_id):
Expand All @@ -38,10 +37,8 @@ def like_view(request, post_id):
)


@verified_email_required
def show_post_view(request, slug):
if request.user.is_authenticated:
post = Post.objects.get(slug=slug)
context = {"post": post}
return render(request, "post/post_layout.html", context)
else:
return redirect("account_login")
post = Post.objects.get(slug=slug)
context = {"post": post}
return render(request, "post/post_layout.html", context)

0 comments on commit 9e3f827

Please sign in to comment.