Beispiel #1
0
def post(request,post_id):
  post=Image.get_image_by_id(post_id)
  posts_liked=[]
  post_comments=Image_Comment.objects.filter(image=post)
  for like in get_likes(request):
    posts_liked.append(like.post)
  following=user_views.get_following(request)

  if request.method == "POST":
        comment_form = NewCommentForm(request.POST)

        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.profile = Profile.get_profile_by_userid(request.user.id)
            comment.image = post
            comment.save()
            comment_form = NewCommentForm()
            Image.objects.filter(id=post_id).update(comments=F("comments") + 1)  
            messages.success(request, f'Comment successfully added')
            return redirect("post", post_id)
  else:
      comment_form = NewCommentForm()
  context={
    'profile':request.user.profile,
    'post':post,
    'posts_liked':posts_liked,
    'form':comment_form,
    'comments':post_comments,
    'following':following

  }
  return render(request, 'feed/post.html',context)
Beispiel #2
0
 def setUp(self):
     # Creating a new location and saving it
     self.new_user = User(username='******',
                          email='*****@*****.**',
                          password='******')
     self.new_user.save()
     self.new_profile = Profile.get_profile_by_userid(self.new_user.id)
     self.new_image = Image(image_name='Cycling',
                            image_caption='sahgsbxsahzb',
                            profile=self.new_profile)
     self.new_image.save_image()
Beispiel #3
0
def home_page(request):
  following=user_views.get_following(request)
  posts_liked=[]
  for like in get_likes(request):
    posts_liked.append(like.post)
  following_posts=[]
  all_posts=Image.get_all_images()
  for post in all_posts:
    if post.profile in following:
      following_posts.append(post)
  profile=Profile.get_profile_by_userid(request.user.id)
  my_posts=Image.filter_by_userid(request.user.id)
  context={
    'profile':profile,
    'following':following,
    'all_posts':all_posts,
    'following_posts':following_posts,
    'posts_liked':posts_liked,
    'my_posts':my_posts,
    'new_user':user_views.new_user(request)
  }
  return render(request,'feed/home.html',context)