Esempio n. 1
0
def new(request):
    if request.method == "POST":
        if request.POST["action"] == "create":
            offer_form = OfferForm(request.user, request.POST)
            if offer_form.is_valid():
                offer = offer_form.save(commit=False)
                offer.offerer = request.user
                offer.save()
                offer_form.save_m2m()

                # for circle in offer_form.cleaned_data['circles']:

                # request.user.message_set.create(message=_("Successfully saved offer '%s'") % offer.short_description)
                # if notification:
                #     if friends: # @@@ might be worth having a shortcut for sending to all friends
                #         notification.send((x['friend'] for x in Friendship.objects.friends_for_user(offer.offerer)), "offer_friend_post", {"post": blog})

                return HttpResponseRedirect(reverse("offer_list_yours"))
        else:
            offer_form = OfferForm(request.user)
    else:
        offer_form = OfferForm(request.user)

    return render_to_response(
        "swaps/new_offer.html", {"offer_form": offer_form}, context_instance=RequestContext(request)
    )
Esempio n. 2
0
def edit_offer(request, offer_id):
    offer = get_object_or_404(Offer, id=offer_id)
    if offer.offerer != request.user:
        request.user.message_set.create(message="You cannot edit offers that are not yours")
        return HttpResponseRedirect(reverse("offer_list_yours"))
    # return_to = request.GET['returnto']
    if request.method == "POST":
        if request.POST["action"] == "update":
            offer_form = OfferForm(request.user, request.POST, instance=offer)
            if offer_form.is_valid():
                offer = offer_form.save(commit=False)
                offer.save()
                if notification:
                    for swap in offer.proposed_swaps.filter(state=1):
                        notification.send(
                            [swap.responding_offer.offerer],
                            "swaps_proposing_offer_changed",
                            {
                                "creator": request.user,
                                "swap": swap,
                                "proposing_offer": swap.proposing_offer,
                                "responding_offer": swap.responding_offer,
                            },
                        )
                    for swap in offer.responding_swaps.filter(state=1):
                        notification.send(
                            [swap.proposing_offer.offerer],
                            "swaps_responding_offer_changed",
                            {
                                "creator": request.user,
                                "swap": swap,
                                "proposing_offer": swap.proposing_offer,
                                "responding_offer": swap.responding_offer,
                            },
                        )

                # request.user.message_set.create(message=_("Successfully updated offer '%s'") % offer.short_description)
                # return HttpResponseRedirect(offer_copy(request, offer_id))

                return render_to_response(
                    "swaps/offer.html",
                    {
                        "offer": offer,
                        # "deletable": deletable,
                    },
                    context_instance=RequestContext(request),
                )

        else:
            offer_form = OfferForm(request.user, instance=offer)
    else:
        offer_form = OfferForm(request.user, instance=offer)
    print "oferrer: ", offer.offerer
    print "user ", request.user
    return render_to_response(
        "swaps/edit_offer.html", {"offer_form": offer_form, "offer": offer}, context_instance=RequestContext(request)
    )