def ajax_item_selected(request, item_id): try: item = Item.objects.get(id=item_id) size_list = item.quantity.order_by("id") jsonDict = { "item":item.json(), "size_list": size_list, "quantity_list": range(1,11), "paypal_debug" : settings.PAYPAL_DEBUG, } jsonDict.update(csrf(request)) logger.debug(jsonDict) return render_to_response("website/ajax_item_form.html", jsonDict) except Exception, e: logger.error(e) return HttpResponseRedirect("/shop/")
def ajax_item_selected(request, item_id): try: item = Item.objects.get(id=item_id) size_list = item.quantity.order_by("id") jsonDict = { "item": item.json(), "size_list": size_list, "quantity_list": range(1, 11), "paypal_debug": settings.PAYPAL_DEBUG, } jsonDict.update(csrf(request)) logger.debug(jsonDict) return render_to_response("website/ajax_item_form.html", jsonDict) except Exception, e: logger.error(e) return HttpResponseRedirect("/shop/")
def update_cart(request): cart = get_cart_session(request) (item_id, name, size, quantity) = test_post_item(request) try: item = Item.objects.get(id=item_id) logger.debug(cart) for cart_item in cart: #If item in cart matches ID and size if cart_item["id"] == item_id and cart_item["size"] == size: cart_item["quantity"] = quantity cart = [item for item in cart if item["quantity"] != "0"] request.session["cart"] = cart logger.debug(cart) return HttpResponse(status=200, content=json.dumps(cart)) except Exception, e: logger.error(e) return HttpResponse(status=500, content="Internal Server Failure, Check the logs!")
def update_cart(request): cart = get_cart_session(request) (item_id, name, size, quantity) = test_post_item(request) try: item = Item.objects.get(id=item_id) logger.debug(cart) for cart_item in cart: #If item in cart matches ID and size if cart_item["id"] == item_id and cart_item["size"] == size: cart_item["quantity"] = quantity cart = [item for item in cart if item["quantity"] != "0"] request.session["cart"] = cart logger.debug(cart) return HttpResponse(status=200, content=json.dumps(cart)) except Exception, e: logger.error(e) return HttpResponse(status=500, content="Internal Server Failure, Check the logs!")
def send_email(subject, message, sent_by=None): from email.mime.text import MIMEText from subprocess import Popen, PIPE import smtplib adminemail = settings.ADMINS[0][1] toemail = settings.ADMINS[0][1] fromemail = adminemail # Can no longer 'send as the user' email = MIMEText(message) email['Subject'] = subject email['From'] = fromemail email['To'] = toemail if sent_by: email['cc'] = sent_by logger.debug(email.as_string()) from revelation_ink.secrets import SMTP_USERNAME, SMTP_PASSWORD s = smtplib.SMTP('mail.rev-ink.com') s.login(SMTP_USERNAME, SMTP_PASSWORD) s.sendmail(fromemail, toemail, email.as_string()) s.quit() return True