Skip to content

Commit

Permalink
comment like done
Browse files Browse the repository at this point in the history
  • Loading branch information
XuantongMa committed Dec 9, 2022
1 parent 22c8ec5 commit 63788bd
Show file tree
Hide file tree
Showing 62 changed files with 54 additions and 53 deletions.
Binary file modified SocialDistribution/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified SocialDistribution/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file modified SocialDistribution/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified SocialDistribution/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified authors/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified authors/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified authors/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified inbox/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/templatetags/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified inbox/templatetags/__pycache__/posts_markdown.cpython-38.pyc
Binary file not shown.
35 changes: 21 additions & 14 deletions inbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@ def my_inbox(request,userId):
currentAuthor=single_author.objects.filter(uuid=userId).first()
currentAuthorInbox = Inbox.objects.filter(author=currentAuthor).first()

# inbox followers new post message
# inbox followers new post messages
Inbox_new_post = currentAuthorInbox.items

# inbox like message
my_posts_id_list = Post.objects.filter(author=currentAuthor).values_list('id')
likeds = Liked.objects.all()

# my_posts_id_list = Post.objects.filter(author=currentAuthor).values_list('id')
# likeds = Liked.objects.all()
# likeds = Liked.objects.filter(type="liked")
# for liked in likeds:
# for like in liked.items.all():
# if Post.objects.filter(id=like.object,author=currentAuthor).exists():
# postTitle = Post.objects.get(uuid = like.postId).title
# #print(like.summary)
# message = f"{like.author.username}{like.summary} | Post: {postTitle}"
# text.append(message)

# inbox like messages
text = []
likeds = Liked.objects.filter(type="liked")
likeds = currentAuthorInbox.likes.all()
for liked in likeds:
for like in liked.items.all():
if Post.objects.filter(id=like.object,author=currentAuthor).exists():
postTitle = Post.objects.get(uuid = like.postId).title
#print(like.summary)
message = f"{like.author.username}{like.summary} | Post: {postTitle}"
text.append(message)
likes = liked.items.all()
for like in likes:
text.append(like.summary)

# inbox Comment message
# inbox Comment messages
comments = Comment.objects.all()
comment_msg = []
author_posts = Post.objects.filter(author=currentAuthor)
Expand All @@ -42,10 +49,10 @@ def my_inbox(request,userId):
post_title = author_post.title
comment_msg.append(name + " comments your post: " + post_title + ", with comment " + '"' + com.comment + '"' )

# inbox Request message
# inbox Request messages
re = currentAuthorInbox.followRequests.all()

# accept the follow request
# accept the follow requests
if request.method == 'POST' and 'delete' in request.POST:
deleted_request_actor_id = request.POST['delete']
deleted_request_actor = single_author.objects.get(id= deleted_request_actor_id)
Expand Down
Binary file modified login/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified login/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified login/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified me/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified me/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/post_forms.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified post/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified post/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified post/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion post/templates/post/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
</br>
<li>comment: </li>
{% for each_comment in comment %}
<li>{{ each_comment.comment}}</li>
<li>{{ each_comment.comment}}
<a href={% url "like-comment-page" userId post.uuid each_comment.uuid %} class="btn btn-danger">LIKE</a>
</li>

{% endfor %}
<br/>
<hr style="height:1px;border-width:0;color:rgba(24, 23, 22, 0.812);background-color:black;width:90%">
Expand Down
Binary file modified post/templatetags/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified post/templatetags/__pycache__/posts_markdown.cpython-38.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions post/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
path("authors/<str:userId>/like/<str:postId>", views.create_like,name="like-page"),
path("authors/<str:userId>/share/<str:postId>",views.share_post,name="share-page"),
path("authors/<str:userId>/node",views.get_node,name='get-node-page'),

path("authors/<str:userId>/posts/<str:postId>/comments/<str:commentId>/likes",views.create_like_comment,name="like-comment-page"),

]
65 changes: 27 additions & 38 deletions post/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
@login_required(login_url='/login/')
def home_page(request,userId):
booleanOfalert = False
#这里要加判定
# print(f"11111111111111111111{request.user}")
# all_posts = Post.objects.all()
all_posts = Post.objects.filter(unlisted=False, visibility="PUBLIC")
post_comments_dict = {}
userSelectionForm = UserSelectionForm(userId=userId)
Expand Down Expand Up @@ -78,10 +75,7 @@ def home_page(request,userId):
"userSelectionForm":userSelectionForm,
})

# def posts(request):
# return render(request, 'post/post_in_div.html', {
# 'posts': Post.objects.all()
# })


@login_required(login_url='/login/')
def create_post(request,userId):
Expand Down Expand Up @@ -177,7 +171,6 @@ def create_like(request,userId,postId):
like = Like.objects.create(author=currentAuthor, summary=summary, object=po, postId = po_uuid)
like.save()
if not Liked.objects.filter(postId=po).exists():
print("fffffffffffffffffff")
receiver_liked = Liked.objects.create(postId=po)
receiver_liked = Liked.objects.get(postId=po)
receiver_liked.items.add(like)
Expand All @@ -187,8 +180,6 @@ def create_like(request,userId,postId):
post_author_inbox = Inbox.objects.get(author=post_author)
post_author_inbox.likes.add(receiver_liked)

# count like might be done in part 3
#like_count = Like.objects.filter(object=object).count()
return HttpResponseRedirect(reverse("home-page",args=[userId]))


Expand All @@ -204,34 +195,7 @@ def share_post(request,userId,postId):

inbox.items.add(selectedPost)


return HttpResponseRedirect(reverse("home-page",args=[userId]))


# my own post cannot shared by myself, but can share same post many times *
# if old_post.author.uuid != currentAuthor.uuid:
# new_title = old_post.title
# new_postId = uuid.uuid4()
# new_id = f"{request.build_absolute_uri('/')}service/authors/{str(userId)}/posts/{str(new_postId)}"
# new_source = id
# new_origin = id
# new_description = old_post.description
# new_content_type = old_post.contentType
# new_content = old_post.content

# new_author = currentAuthor
# new_categories = old_post.Categories
# new_count = 0
# new_visibility = old_post.visibility
# new_unlisted = old_post.unlisted
# new_textType = old_post.textType
# new_post_image = old_post.post_image
# shared_post = Post.objects.create(title=new_title, uuid=new_postId, id=new_id, source=new_source, origin=new_origin,
# description=new_description, contentType=new_content_type,
# content=new_content, author=new_author, Categories=new_categories,
# count=new_count, visibility=new_visibility, unlisted=new_unlisted,
# textType=new_textType, post_image=new_post_image)
# shared_post.save()

else:
userSelectionForm = UserSelectionForm(userId = userId)
Expand Down Expand Up @@ -380,4 +344,29 @@ def get_node(request,userId):
'userId':userId,
'all_posts':all_posts,
'ExternalForm':form,
})
})



def create_like_comment(request,userId,postId,commentId):
comment = Comment.objects.get(uuid=commentId)
comment_author = comment.author
currentAuthor = single_author.objects.get(uuid = userId)

sum = currentAuthor.display_name + " likes your comment"
obj = commentId
commId = comment.id

if not Like.objects.filter(author=currentAuthor, summary=sum, object=obj, postId = commId).exists():
like = Like.objects.create(author=currentAuthor, summary=sum, object=obj, postId = commId)
like.save()
if not Liked.objects.filter(postId=commId).exists():
receiver_liked = Liked.objects.create(postId=commId)
receiver_liked = Liked.objects.get(postId=commId)
receiver_liked.items.add(like)

# Liked added to inbox
post_author_inbox = Inbox.objects.get(author=comment_author)
post_author_inbox.likes.add(receiver_liked)

return HttpResponseRedirect(reverse("home-page",args=[userId]))
Binary file modified service/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/serializers.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified service/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified service/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.

0 comments on commit 63788bd

Please sign in to comment.