Ejemplo n.º 1
0
def orderAddBillContact(request):
    form = AddContactForm()
    cart = requestCurCart(request)
    if int(cart.get_item_count()) > 0:
        #form = None

        if request.method == 'POST':
            contact = None
            try:
                addrID = request.POST['addressID']
            except (KeyError):
                addrID = None
            if addrID:
                contact = Contact.objects.get(user=request.user,id=addrID)
            else:
                form = AddContactForm(request.POST)
                if form.is_valid():
                    contact = form.save(request)
            if contact:
                try:
                    orderid = request.session['order_id']
                    order = Order.objects.get(id=orderid,order_date__isnull=True)
                except:
                    order = Order()
                order.user = request.user
                order.cart = cart
                order.billing_addr = contact
                try:
                    if not order.delivery_addr:
                        order.delivery_addr = contact
                except:
                    order.delivery_addr = contact
                order.save()
                request.session['order_id'] = order.id
                return HttpResponseRedirect(reverse('shoppy_order_deliverycontact'))

        
        contact_list = Contact.objects.all().filter(user=request.user,isActive=True)

        return render_to_response('shop/bill_contact_form.html', {
                    'form': form,
                    'contact_list': contact_list,
                    'hideRightNavi':True,
                    'hideLeftNavi':True
                },context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect(reverse('shoppy_cart'))
Ejemplo n.º 2
0
def contact(request, contact_id=0):
    """
    Shows a form to add a new or edit an existing contact.
    """
    template = None

    if request.method == 'POST':
        template = request.POST['next']
        form = AddContactForm(request.POST)
        if form.is_valid():
            if int(contact_id) > 0:
                c = Contact.objects.get(id=contact_id,user=request.user,isActive=True)
                c.isActive = False
                c.save()

            contact = form.save(request)
            
            return HttpResponseRedirect(template)
    else:
        form = AddContactForm()
        if int(contact_id) > 0:
            try:
                c = Contact.objects.get(id=contact_id,user=request.user,isActive=True)
                init_data = {}
                init_data['title'] = c.form.id
                init_data['name'] = c.name
                init_data['streetandnr'] = c.streetandnr
                init_data['zip'] = c.zip
                init_data['city'] = c.city
                init_data['country'] = c.country.id
                init_data['phone'] = c.phone
                form = AddContactForm(initial=init_data)
            except:
                pass

    try:
        template = request.GET['next']
    except:
        pass
    if not template:
        template = reverse('shoppy_contact_list')

    return render_to_response('contact/contact_form.html', {
                'form': form,
                'next': template,
            },context_instance=RequestContext(request))