コード例 #1
0
def pp_subscription_form(context, nodelist, *args, **kwargs):
    
    context.push()
    namespace = get_namespace(context)

    # this tag only works if a valid pair is assigned to the 'object=' argument
    POST  = kwargs.get('POST', None)
    subscriber = kwargs.pop('subscriber', None)
    subscribee = kwargs.pop('subscribee', None)
    if subscriber is None:
        raise ValueError("pp_subscription_form tag requires that a object be passed "
                             "to it assigned to the 'subscriber=' argument")
    if subscribee is None:
        raise ValueError("pp_subscription_form tag requires that a object be passed "
                             "to it assigned to the 'subscribee=' argument")
                             
                             
    if POST and POST.get("form_id") == "pp_subscription_form":
        form = SubscriptionForm(POST)
        if form.is_valid():   
            sub = Subscription(subscriber=subscriber,subscribee=subscribee,created_dt=datetime.datetime.now())
            sub.save()
            c_type = ContentType.objects.get_for_model(subscribee)
            raise HttpRedirectException(HttpResponseRedirect("/user_profile.html?_t=" + str(c_type.pk) + "&_o=" + str(subscribee.pk)))
    else: form = SubscriptionForm()
    
    if subscriber != subscribee: namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
コード例 #2
0
ファイル: views.py プロジェクト: Alasaad/Open-Assembly
def add_support(request):
    if not request.user.is_authenticated() or not request.user.is_active:
        return HttpResponse(simplejson.dumps({'FAIL': True}),
                            mimetype='application/json')

    if request.method == 'POST':
        user_pk = request.POST[u'user']
        object_pk = request.POST[u'subscribed']

        user = User.objects.get(pk=user_pk)
        subscribed = User.objects.get(pk=object_pk)

        if request.user == user:
            try:
                old_sub = Subscription.objects.get(subscriber=user,
                                                   subscribee=subscribed)
            except:
                sub = Subscription(subscriber=user,
                                   subscribee=subscribed,
                                   created_dt=datetime.datetime.now())
                sub.save()
            results = {
                'FAIL': False,
                'redirect': subscribed.get_absolute_url()
            }
        else:
            results = {'FAIL:': True}
    else:
        results = {'FAIL': True}
    if 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        return HttpResponse(simplejson.dumps(results),
                            mimetype='application/json')
コード例 #3
0
ファイル: views.py プロジェクト: Alasaad/Open-Assembly
def add_support(request):
    if not request.user.is_authenticated() or not request.user.is_active:
        return HttpResponse(simplejson.dumps({'FAIL': True}),
                                mimetype='application/json')

    if request.method == 'POST':
        user_pk = request.POST[u'user']
        object_pk = request.POST[u'subscribed']

        user = User.objects.get(pk=user_pk)
        subscribed = User.objects.get(pk=object_pk)

        if request.user == user:
            try:
                old_sub = Subscription.objects.get(subscriber=user, subscribee=subscribed)
            except:
                sub = Subscription(subscriber=user, subscribee=subscribed,
                                    created_dt=datetime.datetime.now())
                sub.save()
            results = {'FAIL': False, 'redirect': subscribed.get_absolute_url()}
        else:
            results = {'FAIL:': True}
    else:
        results = {'FAIL': True}
    if 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        return HttpResponse(simplejson.dumps(results),
                            mimetype='application/json')
コード例 #4
0
def pp_subscription_form(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    # this tag only works if a valid pair is assigned to the 'object=' argument
    POST = kwargs.get('POST', None)
    subscriber = kwargs.pop('subscriber', None)
    subscribee = kwargs.pop('subscribee', None)
    if subscriber is None:
        raise ValueError(
            "pp_subscription_form tag requires that a object be passed "
            "to it assigned to the 'subscriber=' argument")
    if subscribee is None:
        raise ValueError(
            "pp_subscription_form tag requires that a object be passed "
            "to it assigned to the 'subscribee=' argument")

    if POST and POST.get("form_id") == "pp_subscription_form":
        form = SubscriptionForm(POST)
        if form.is_valid():
            sub = Subscription(subscriber=subscriber,
                               subscribee=subscribee,
                               created_dt=datetime.datetime.now())
            sub.save()
            c_type = ContentType.objects.get_for_model(subscribee)
            raise HttpRedirectException(
                HttpResponseRedirect("/user_profile.html?_t=" +
                                     str(c_type.pk) + "&_o=" +
                                     str(subscribee.pk)))
    else:
        form = SubscriptionForm()

    if subscriber != subscribee: namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
コード例 #5
0
ファイル: views.py プロジェクト: fragro/Open-Assembly
def add_support(request):
    if not request.user.is_authenticated() or not request.user.is_active:
        return HttpResponse(simplejson.dumps({"FAIL": True}), mimetype="application/json")

    if request.method == "POST":
        user_pk = request.POST[u"user"]
        object_pk = request.POST[u"subscribed"]

        user = User.objects.get(pk=user_pk)
        subscribed = User.objects.get(pk=object_pk)

        if request.user == user:
            try:
                old_sub = Subscription.objects.get(subscriber=user, subscribee=subscribed)
            except:
                sub = Subscription(subscriber=user, subscribee=subscribed, created_dt=datetime.datetime.now())
                sub.save()
            results = {"FAIL": False, "redirect": subscribed.get_absolute_url()}
        else:
            results = {"FAIL:": True}
    else:
        results = {"FAIL": True}
    if "application/json" in request.META.get("HTTP_ACCEPT", ""):
        return HttpResponse(simplejson.dumps(results), mimetype="application/json")