def like_it(request): if request.is_ajax() and 'which_post' in request.POST: x = "" try: x = Status.objects.get(id=request.POST['which_post']) like = Like.objects.get(on_which_status=x, of_which_user=request.user) like.delete() return render_to_response( "single_post.html", {'post': Status.objects.get(id=request.POST['which_post'])}, RequestContext(request)) except Like.DoesNotExist: new_like = Like() new_like.of_which_user = request.user new_like.on_which_status = x new_like.save() if x.of_whom != request.user: new_notification = Notifications() new_notification.of_whom = x.of_whom new_notification.type = "liked" new_notification.description = '<a style="color:#525252;" href="/logged-in-view/#cc' + request.POST['which_post'] + 'cc' +\ '"><b>' + request.user.get_full_name() + '</b><i> has liked your post</i></a>' new_notification.save() return render_to_response( "single_post.html", {'post': Status.objects.get(id=request.POST['which_post'])}, RequestContext(request))
def accept_or_ignore(request): if request.method == "POST": query = request.POST['query'] invite_no = request.POST['invite_no'] try: invitation = Invitations.objects.get(id=invite_no) except Invitations.DoesNotExist: invitation = None response_data = {} if invitation and invitation.receiver_id.id == request.user.id: if query == "accept": new_connection_1 = Connection() new_connection_1.of_whom = request.user new_connection_1.with_whom = invitation.sender_id new_connection_1.related_how = invitation.relationship_type new_connection_1.save() new_connection_2 = Connection() new_connection_2.of_whom = invitation.sender_id new_connection_2.with_whom = request.user new_connection_2.related_how = invitation.relationship_type new_connection_2.save() response_data['message'] = invitation.sender_id.get_full_name( ) + " is added in you connections" notification = Notifications() notification.of_whom = invitation.sender_id notification.type = "invite accepted" notification.description = "<a href='/user/" + str( invitation.receiver_id.id ) + "'>" + invitation.receiver_id.get_full_name( ) + "</a>" + " <i style='color:#525252;'>has accepted your invitation</i>" notification.save() invitation.delete() response_data['notificationid'] = notification.id print notification.id elif query == "ignore": response_data[ 'message'] = "Invitation request from " + invitation.sender_id.get_full_name( ) + " has been ignored" invitation.delete() else: response_data['message'] = "bad data !" else: response_data['message'] = "bad data !" return HttpResponse(json.dumps(response_data), content_type='application/json') return HttpResponseRedirect('/logged-in-view/')
def post_comment(request): if 'which-post' and 'comment-text' in request.POST: if request.POST['comment-text'] == "": return new_comment = Comment() new_comment.of_whom = request.user x = Status.objects.filter(id=request.POST['which-post'])[0] new_comment.comment_of = x new_comment.comment_text = request.POST['comment-text'] new_comment.save() if x.of_whom != request.user: new_notification = Notifications() new_notification.of_whom = x.of_whom new_notification.type = "comment" new_notification.description = '<a style="color:#525252;" href="/logged-in-view/#cc' + request.POST['which-post'] + 'cc' +\ '"><b>' + request.user.get_full_name() + '</b> <i>has commented on your post</i></a>' new_notification.save() return render_to_response('ComentContainer.html', {'comment': new_comment}, RequestContext(request)) else: return HttpResponse("<p>null</p>")
def accept_or_ignore(request): if request.method == "POST": query = request.POST['query'] invite_no = request.POST['invite_no'] try: invitation = Invitations.objects.get(id=invite_no) except Invitations.DoesNotExist: invitation = None response_data = {} if invitation and invitation.receiver_id.id == request.user.id: if query == "accept": new_connection_1 = Connection() new_connection_1.of_whom = request.user new_connection_1.with_whom = invitation.sender_id new_connection_1.related_how = invitation.relationship_type new_connection_1.save() new_connection_2 = Connection() new_connection_2.of_whom = invitation.sender_id new_connection_2.with_whom = request.user new_connection_2.related_how = invitation.relationship_type new_connection_2.save() response_data['message'] = invitation.sender_id.get_full_name() + " is added in you connections" notification = Notifications() notification.of_whom = invitation.sender_id notification.type = "invite accepted" notification.description = "<a href='/user/" + str(invitation.receiver_id.id) + "'>" +invitation.receiver_id.get_full_name()+"</a>" + " <i style='color:#525252;'>has accepted your invitation</i>" notification.save() invitation.delete() response_data['notificationid'] = notification.id print notification.id elif query == "ignore": response_data['message'] = "Invitation request from " + invitation.sender_id.get_full_name() + " has been ignored" invitation.delete() else: response_data['message'] = "bad data !" else: response_data['message'] = "bad data !" return HttpResponse(json.dumps(response_data), content_type='application/json') return HttpResponseRedirect('/logged-in-view/')
def like_it(request): if request.is_ajax() and 'which_post' in request.POST: x = "" try: x = Status.objects.get(id=request.POST['which_post']) like = Like.objects.get(on_which_status=x, of_which_user=request.user) like.delete() return render_to_response("single_post.html", {'post':Status.objects.get(id=request.POST['which_post'])}, RequestContext(request)) except Like.DoesNotExist: new_like = Like() new_like.of_which_user = request.user new_like.on_which_status = x new_like.save() if x.of_whom != request.user: new_notification = Notifications() new_notification.of_whom = x.of_whom new_notification.type = "liked" new_notification.description = '<a style="color:#525252;" href="/logged-in-view/#cc' + request.POST['which_post'] + 'cc' +\ '"><b>' + request.user.get_full_name() + '</b><i> has liked your post</i></a>' new_notification.save() return render_to_response("single_post.html", {'post':Status.objects.get(id=request.POST['which_post'])}, RequestContext(request))