Exemplo n.º 1
0
def forum_subscription_response(user, subscribed_item, subscribe):
    print("forum_subscription_response")
    print("subscribe: ", subscribe)
    # this is also in EngageView
    my_response = ''
    if user.is_authenticated:
        # does this subscritpion exist already
        existing_subscription = ForumSubscription.objects.filter(
            user=user, forum=subscribed_item)
        if subscribe == "true":
            print("will attempt to subscribe..")
            if not existing_subscription:
                new_subscription = ForumSubscription()
                new_subscription.user = user
                new_subscription.forum = subscribed_item
                new_subscription.type = 1  # not going to setup subscribing to all posts for now
                new_subscription.save()
        else:
            if existing_subscription:
                existing_subscription.delete()
    else:
        print(
            "Unauthenticated user just tired to make a subscription.  They should never have been given this option."
        )
    return HttpResponse(my_response)