Example #1
0
def order_cart(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            subject = u'Заказ с сайта'
            recipients = []
            try:
                recipients.extend(emails_list(request.settings.email))
            except:
                recipients.append(settings.ADMINS[0][1])
            cart = Cart(request, init=True)
            letter_context = form.cleaned_data
            letter_context.update({'site': request.settings.project})
            order_text = render_to_string('order_info.txt', {'cart': cart})
            letter_content = render_to_string('order_letter.txt', letter_context)
            letter_content += order_text
            send_mail(subject, letter_content, letter_context['email'] or recipients[0], recipients)
            success_message = u"""
            Благодарим за то, что Вы воспользовались услугами нашего Интернет-магазина.
            Ваша заявка принята в обработку и наш менеджер свяжется с Вами в ближайшее время для уточнения деталей.
            Мы будем благодарны Вам, если Вы оставите на нашем сайте свой отзыв о работе нашего  Интернет-магазина.
            """
            messages.add_message(request, messages.SUCCESS, success_message)
            cart.delete_all()
            return HttpResponseRedirect('')
    else:
        form = OrderForm()
    return render_to_response('cart_order.html', {'form': form},
        context_instance=RequestContext(request))   
Example #2
0
def order_cart(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            subject = u'Заказ с сайта'
            recipients = []
            try:
                recipients.extend(emails_list(request.settings.email))
            except:
                recipients.append(settings.ADMINS[0][1])
            cart = Cart(request, init=True)
            # Order insertion
            if cart.objects:
                order = Order.objects.create(
                    fio=form.cleaned_data['fio'],
                    address='',
                    phones=form.cleaned_data['phones'],
                    email=form.cleaned_data['email'],
                    comment=form.cleaned_data['comment'])
                for item in cart.objects:
                    order.items.create(label=item.label,
                                       amount=item.amount,
                                       price=item.price)
            subject = u'Поступил заказ с сайта %s' % settings.PROJECT_TITLE
            letter_context = form.cleaned_data
            letter_context.update({
                'site': settings.PROJECT_TITLE,
                'cart': cart,
                'subject': subject
            })

            text_content = render_to_string('letters/order_text.txt',
                                            letter_context)
            html_content = render_to_string('letters/order_html.html',
                                            letter_context)

            msg = EmailMultiAlternatives(subject, text_content, recipients[0],
                                         recipients)
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            cart.delete_all()
            success_message = request.infoblock.get(
                'order_send_message', u"""
            Благодарим за то, что Вы воспользовались услугами нашего Интернет-магазина.
            Ваша заявка принята в обработку, и наш менеджер свяжется с Вами в ближайшее время для уточнения деталей.
            """)
            messages.add_message(request, messages.SUCCESS, success_message)
            return redirect(reverse('message_list'))
    else:
        form = OrderForm()
    return render_to_response('cart_order.html', {'form': form},
                              context_instance=RequestContext(request))
Example #3
0
def order_cart(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            subject = u'Заказ с сайта'
            recipients = []
            try:
                recipients.extend(emails_list(request.settings.email))
            except:
                recipients.append(settings.ADMINS[0][1])
            cart = Cart(request, init=True)
            # Order insertion
            if cart.objects:
                order = Order.objects.create(fio=form.cleaned_data['fio'],
                                             address='',
                                             phones=form.cleaned_data['phones'],
                                             email=form.cleaned_data['email'],
                                             comment=form.cleaned_data['comment'])
                for item in cart.objects:
                    order.items.create(label=item.label,
                                       amount=item.amount,
                                       price=item.price)
            subject = u'Поступил заказ с сайта %s' % settings.PROJECT_TITLE
            letter_context = form.cleaned_data
            letter_context.update({'site': settings.PROJECT_TITLE,
                                   'cart': cart, 'subject': subject})
            
            text_content = render_to_string('letters/order_text.txt', letter_context)
            html_content = render_to_string('letters/order_html.html', letter_context)
            
            msg = EmailMultiAlternatives(subject, text_content,
                recipients[0], recipients)
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            cart.delete_all()
            success_message = request.infoblock.get('order_send_message', u"""
            Благодарим за то, что Вы воспользовались услугами нашего Интернет-магазина.
            Ваша заявка принята в обработку, и наш менеджер свяжется с Вами в ближайшее время для уточнения деталей.
            """)
            messages.add_message(request, messages.SUCCESS, success_message)
            return redirect(reverse('message_list'))
    else:
        form = OrderForm()
    return render_to_response('cart_order.html', {'form': form},
        context_instance=RequestContext(request))   
Example #4
0
def feedback(request):
    from website.forms import FeedbackForm
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            subject = u'Вопрос с сайта'
            recipients = []
            recipients.extend(emails_list(request.settings.email))
            letter_context = form.cleaned_data
            letter_context.update({'site': request.settings.project})
            letter_content = render_to_string('feedback_letter.txt', letter_context)
            send_mail(subject, letter_content,
                      letter_context['email'] or recipients[0], recipients)
            messages.add_message(request, messages.SUCCESS, u"Ваше письмо успешно отправлено администрации сайта.")
            return redirect('')
    else:
        form = FeedbackForm()
    return render(request, 'feedback.html', {'form': form})
Example #5
0
def feedback(request):
    from website.forms import FeedbackForm
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            subject = u'Вопрос с сайта'
            recipients = []
            recipients.extend(emails_list(request.settings.email))
            letter_context = form.cleaned_data
            letter_context.update({'site': request.settings.project})
            letter_content = render_to_string('feedback_letter.txt',
                                              letter_context)
            send_mail(subject, letter_content, letter_context['email']
                      or recipients[0], recipients)
            messages.add_message(
                request, messages.SUCCESS,
                u"Ваше письмо успешно отправлено администрации сайта.")
            return redirect('')
    else:
        form = FeedbackForm()
    return render(request, 'feedback.html', {'form': form})