def delete(request, commitment_id): commitment = get_object_or_404(Commitment, user=request.user, id=commitment_id) commitment.delete() response = redirect(commitment.entity) if request.is_ajax(): button = render_inclusiontag(request, "commitment_button entity", "commitment_tags", {'entity': commitment.entity}) response = json_response({'button': button}) return response
def unfollow(request, user_id): followed = get_object_or_404(User, pk=user_id) try: follow_instance = UserToUserFollow.objects.get(follower=request.user, followed=followed) follow_instance.is_following = False follow_instance.stopped_following = datetime.datetime.now() follow_instance.save() except UserToUserFollow.DoesNotExist: pass cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def follow(request, user_id): followed = get_object_or_404(User, pk=user_id) follow_instance, created = UserToUserFollow.objects.get_or_create(follower=request.user, followed=followed) if not follow_instance.is_following: follow_instance.is_following = True follow_instance.save() if created: send_notification(type=EmailTypes.FOLLOW, user=followed, entity=request.user) cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def unfollow(request, user_id): followed = get_object_or_404(User, pk=user_id) try: follow_instance = UserToUserFollow.objects.get(follower=request.user, followed=followed) follow_instance.is_following = False follow_instance.stopped_following = datetime.datetime.now() follow_instance.save() except UserToUserFollow.DoesNotExist: pass cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def follow(request, user_id): followed = get_object_or_404(User, pk=user_id) follow_instance, created = UserToUserFollow.objects.get_or_create( follower=request.user, followed=followed) if not follow_instance.is_following: follow_instance.is_following = True follow_instance.save() if created: send_notification(type=EmailTypes.FOLLOW, user=followed, entity=request.user) cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def create(request): entity_id = request.POST['object_id'] entity_type = request.POST['content_type'] content_type = ContentType.objects.get(id=entity_type) entity = content_type.get_object_for_this_type(id=entity_id) commitment = Commitment(entity=entity, user=request.user) response = redirect(entity) try: commitment.full_clean() commitment.save() if request.is_ajax(): button = render_inclusiontag(request, "commitment_button entity", "commitment_tags", {'entity': entity}) actions = render_string(request, "action/includes/action_list.html", { 'entity': entity, 'actions': entity.actions.all(), }) response = json_response({'button': button, 'actions': actions}) except ValidationError: if request.is_ajax(): response = json_error(400, "You have already committed to this issue/org.") return response