Пример #1
0
def new(request):
    if request.method == "POST":
        if request.POST["action"] == "create":
            offer_form = OfferForm(request.POST)
            if offer_form.is_valid():
                offer = offer_form.save(commit=False)
                offer.offerer = request.user
                offer.save()
                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()
    else:
        offer_form = OfferForm()
    
    return render_to_response("swaps/new_offer.html", {
        "offer_form": offer_form
    }, context_instance=RequestContext(request))
Пример #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.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(reverse(return_to))
        else:
            offer_form = OfferForm(instance=offer)
    else:
        offer_form = OfferForm(instance=offer)
    
    return render_to_response("swaps/edit_offer.html", {
        "offer_form": offer_form,
        "offer": offer,
    }, context_instance=RequestContext(request))