Esempio n. 1
0
def contact_form(request, template_name="lfs/contact/contact_form.html"):
    """Displays the contact form of LFS.
    """
    if request.method == 'POST':
        form = ContactForm(data=request.POST)
        if form.is_valid():
            send_contact_mail(request, form)
            return HttpResponseRedirect(reverse("lfs_contact_form_sent"))
    else:
        customer = lfs.customer.utils.get_customer(request)

        try:
            name = customer.address.firstname + " " + customer.address.lastname
            email = customer.address.email
        except AttributeError:
            name = ""
            email = ""

        form = ContactForm(initial={"name": name, "email": email})

    return render_to_response(template_name, RequestContext(request, {
        "form": form,
    }))
Esempio n. 2
0
def contact_form(request, template_name="lfs/contact/contact_form.html"):
    """Displays the contact form of LFS.
    """
    if request.method == 'POST':
        form = ContactForm(data=request.POST)
        if form.is_valid():
            send_contact_mail(request, form)
            return HttpResponseRedirect(reverse("lfs_contact_form_sent"))
    else:
        customer = lfs.customer.utils.get_customer(request)

        try:
            name = customer.address.firstname + " " + customer.address.lastname
            email = customer.address.email
        except AttributeError:
            name = ""
            email = ""

        form = ContactForm(initial={"name": name, "email": email})

    return render_to_response(template_name, RequestContext(request, {
        "form": form,
    }))
Esempio n. 3
0
def contact_form(request, template_name="lfs/contact/contact_form.html"):
    """Displays the contact form of LFS.
    """
    if request.method == 'POST':
        form = ContactForm(data=request.POST)
        if form.is_valid():
            send_contact_mail(request, form)
            return HttpResponseRedirect(reverse("lfs_contact_form_sent"))
    else:
        customer = lfs.customer.utils.get_customer(request)
        product_id = request.REQUEST.get('product_id', None)
        subject = ''
        try:
            name = customer.address.firstname + " " + customer.address.lastname
            email = customer.address.email
        except AttributeError:
            name = ""
            email = ""

        if product_id:
            try:
                product = Product.objects.get(pk=product_id, active=True)
            except Product.DoesNotExist:
                pass
            else:
                sku = product.get_sku()
                if sku:
                    sku = ' (%s)' % sku
                subject = _('Availability of \'%(product_name)s\'%(sku)s') % dict(product_name=product.get_name(),
                                                                                  sku=sku)

        form = ContactForm(initial={"name": name, "email": email, 'subject': subject})

    return render_to_response(template_name, RequestContext(request, {
        "form": form,
    }))
Esempio n. 4
0
def contact_form(request, contact_form=ContactForm, template_name="lfs/contact/contact_form.html"):
    """Displays the contact form of LFS.
    """
    if request.method == 'POST':
        form = contact_form(data=request.POST)
        if form.is_valid():
            send_contact_mail(request, form)
            return HttpResponseRedirect(reverse("lfs_contact_form_sent"))
    else:
        customer = lfs.customer.utils.get_customer(request)
        product_id = request.GET.get('product_id', None)
        subject = ''
        try:
            name = customer.address.firstname + " " + customer.address.lastname
            email = customer.address.email
        except AttributeError:
            name = ""
            email = ""

        if product_id:
            try:
                product = Product.objects.get(pk=product_id, active=True)
            except Product.DoesNotExist:
                pass
            else:
                sku = product.get_sku()
                if sku:
                    sku = ' (%s)' % sku
                subject = _('Availability of \'%(product_name)s\'%(sku)s') % dict(product_name=product.get_name(),
                                                                                  sku=sku)

        form = contact_form(initial={"name": name, "email": email, 'subject': subject})

    return render(request, template_name, {
        "form": form,
    })