Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

in /test/ url easy-form is working

Some missings in html coding by Alexey
  • Loading branch information...
commit 7ebe5eb3e3a67b8e506baaa445e16bc0a8f313f5 1 parent 578120b
@Guest007 authored
View
1  eurocard/settings.py
@@ -103,6 +103,7 @@
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
'django.core.context_processors.request',
+ 'django.core.context_processors.csrf',
)
# Static files (CSS, JavaScript, Images)
View
2  eurocard/urls.py
@@ -28,6 +28,8 @@
url(r"^second/(?P<pk>\d+)/$", orders.nextstep_order, name="ajax-nextstep-order"),
url(r"^(?P<pk>\d+)/(?P<step>\d+)/$", orders.edit_fast, name="edit-fast"),
url(r"^(?P<pk>\d+)/$", orders.edit_fast, name="edit-fast"),
+ url(r"^(?P<pk>\d+)/(?P<step>\d+)/$", orders.edit_easy, name="edit-easy"),
+ url(r"^(?P<pk>\d+)/$", orders.edit_easy, name="edit-easy"),
url(r"^save/ajax/(?P<step>\d+)/$", orders.save_order, name="ajax-save-order"),
url(r'^test/', views.test, name='test'),
View
4 orders/admin.py
@@ -37,14 +37,14 @@ class ColorAdmin(admin.ModelAdmin):
class OrdersAdmin(admin.ModelAdmin):
- list_display = ['FIO', 'phone', 'email', 'draw']
+ list_display = ['FIO', 'id', 'phone', 'email', 'draw']
# ordering = ["category", 'published_at']
list_filter = ['FIO', 'draw']
class OrderTemplateAdmin(admin.ModelAdmin):
model = OrderTemplate
- list_display = ['name', 'is_template', 'price']
+ list_display = ['name', 'id', 'is_template', 'price']
ordering = ["name", 'is_template', 'price']
list_filter = ['name', 'is_template']
View
120 orders/views.py
@@ -7,12 +7,14 @@
from django.template import RequestContext
from orders.models import OrderTemplate, Orders, Material, Lamination, Color, Modificators, Coefficient
import json
-from django.views.decorators.csrf import csrf_exempt, csrf_protect
+from django.views.decorators.csrf import csrf_exempt, csrf_protect, ensure_csrf_cookie, requires_csrf_token
from django import http
+from django.http import HttpResponse
__author__ = 'guest007'
+@csrf_protect
def fastform(request):
price = Modificators.objects.all()
coeff = Coefficient.objects.all()
@@ -27,6 +29,7 @@ def fastform(request):
context_instance=RequestContext(request))
+@csrf_protect
def easyform(request):
price = Modificators.objects.all()
coeff = Coefficient.objects.all()
@@ -56,11 +59,27 @@ def edit_fast(request, pk, step=0):
'color_back': Color.objects.all().order_by('-id')}
-@csrf_exempt
+@render_to()
+def edit_easy(request, pk, step=0):
+ """Edit selected Order"""
+ if step == 0:
+ return http.HttpResponseRedirect('1/')
+ order = get_object_or_404(Orders, pk=int(pk))
+ templ = OrderTemplate.objects.get(id=order.template.id)
+ return {"TEMPLATE": 'easy-form.html',
+ "object": order,
+ "templ": templ,
+ 'materials': Material.objects.all(),
+ 'color_front': Color.objects.all().order_by('-id'),
+ 'color_back': Color.objects.all().order_by('-id')}
+
+
+@csrf_protect
def nextstep_order(request, pk):
"""Final confirm of Order"""
- print "pk: ", pk
+ # print "pk: ", pk
order = get_object_or_404(Orders, pk=int(pk))
+ # print "And what??? ", order.template.id
templ = OrderTemplate.objects.get(id=order.template.id)
result = {"object": order,
"templ": templ,
@@ -69,60 +88,58 @@ def nextstep_order(request, pk):
'color_front': templ.color_front,
'color_back': templ.color_back}
return render_to_response('helpers.html', result,
- mimetype="text/html; charset=utf-8")
+ content_type="text/html; charset=utf-8")
-# @csrf_protect
-@csrf_exempt
+@csrf_protect
def save_order(request, step=1):
"""Save order with AJAX"""
if request.method != "POST":
result = {"result": "ERROR", "msg": "Wrong request method"}
return http.HttpResponse(json.dumps(result),
content_type="application/json")
- else:
- post_values = request.body
try:
- templ_id = int(request.POST.get("templ_id", 0)) # Если редактруем созданный заказ
+ id = int(request.POST.get("id", 0)) # Если редактруем созданный заказ
except (TypeError, ValueError):
- templ_id = 0
+ id = 0
user = request.POST.get("user", None)
phone = request.POST.get("phone", None)
email = request.POST.get("email", None)
- templ = get_object_or_None(OrderTemplate, pk=templ_id) # Или получаем тело заказа или создаём новое (новый заказ)
+ if id != 0:
+ templ_id = Orders.objects.get(id=id).template.id
+ # print "templ_id: ", templ_id
+ else:
+ templ_id = 0
+ templ = get_object_or_None(OrderTemplate, pk=templ_id) # Или получаем тело заказа или создаём новое (новый заказ)
+ # if templ:
+ # print "TEMPLATE IS PRESENT! ", templ.id
if templ is None:
templ = OrderTemplate(name=(user if user else '')) # Создаем тело заказа. Название - имя заказчика
if step > 10:
- print "STEP more than 10"
-
+ # print "STEP more than 10"
+ print request.POST
templ.color_back = None # Color(id=request.POST.get("color_back", None))
- templ.color_front = Color(id=(request.POST.get("color", None)[0]
- if len(request.POST.get("color", None)) > 1
- else request.POST.get("color", None)))
- print "RAW color^ ", request.POST.get("color", None)
- print "COLOR: ", templ.color_front
- templ.material = Material(id=(request.POST.get("materials", None)[0]
- if len(request.POST.get("materials", None)) > 1
- else request.POST.get("materials", None)))
- print "MATERIAL: ", templ.material
- templ.lamination = Lamination(id=(request.POST.get("lamination", None)[0]
- if len(request.POST.get("lamination", None)) > 1
- else request.POST.get("lamination", None)))
- templ.chip = None # request.POST.get("chip", False)
- templ.uv = None # request.POST.get("uv", False)
- templ.magnet = (True if request.POST.get("magnet", False) > 0 else False)
- templ.emboss = (True if request.POST.get("emboss", False) > 0 else False)
- templ.scratch = (True if request.POST.get("scratch", False) > 0 else False)
- templ.print_num = (True if request.POST.get("print_num", False) > 0 else False)
- templ.sign = (True if request.POST.get("sign", False) > 0 else False)
- templ.indent = (True if request.POST.get("indent", False) > 0 else False)
- templ.barcode = (True if request.POST.get("barcode", False) > 0 else False)
- templ.foil = (True if request.POST.get("foil", False) > 0 else False)
+ templ.color_front = Color(id=(request.POST.get("colors", None)))
+ # print "RAW color^ ", request.POST.get("colors", None)
+ # print "COLOR: ", templ.color_front
+ templ.material = Material(id=(request.POST.get("materials", None)))
+ # print "MATERIAL: ", templ.material
+
+ templ.chip = False # request.POST.get("chip", False)
+ templ.uv = False # request.POST.get("uv", False)
+ templ.magnet = (True if float(request.POST.get("magnet", False)) > 0 else False)
+ templ.emboss = (True if float(request.POST.get("emboss", False)) > 0 else False)
+ templ.scratch = (True if float(request.POST.get("scratch", False)) > 0 else False)
+ templ.print_num = (True if float(request.POST.get("print_num", False)) > 0 else False)
+ templ.sign = (True if float(request.POST.get("sign", False)) > 0 else False)
+ templ.indent = (True if float(request.POST.get("indent", False)) > 0 else False)
+ templ.barcode = (True if float(request.POST.get("barcode", False)) > 0 else False)
+ templ.foil = (True if float(request.POST.get("foil", False)) > 0 else False)
else:
templ.color_back = Color(id=request.POST.get("color_back", None))
@@ -141,11 +158,11 @@ def save_order(request, step=1):
templ.barcode = request.POST.get("barcode", False)
templ.foil = request.POST.get("foil", False)
- print "material", templ.material
- print "lamination", templ.lamination
- print "chip", templ.chip
- print "barcode", templ.barcode
- print "foil", templ.foil
+ # print "material", templ.material
+ # print "lamination", templ.lamination
+ # print "chip", templ.chip
+ # print "barcode", templ.barcode
+ # print "foil", templ.foil
draw = request.POST.get("count", 500) # количество в заказ
# print "DRAW: ", draw
@@ -171,28 +188,33 @@ def save_order(request, step=1):
order.template = OrderTemplate(id=templ.id)
order.FIO = user
- print order.FIO
+ # print order.FIO
order.draw = draw # Количество
- print order.draw
+ # print order.draw
order.cost = request.POST.get("sum", False)
order.email = email
- print order.email
+ # print order.email
order.phone = phone
- print order.phone
- # order.maket = '' # TODO: Пока ничего не пишем. ИСПРАВИТЬ!!!
+ # print order.phone
+ order.maket = '' # TODO: Пока ничего не пишем. ИСПРАВИТЬ!!!
order.save()
- print "ID of Order (order.id): ", order.id
+ # print "ID of Order (order.id): ", order.id
if step == '1':
result = {"result": "OK", "id": order.id,
"msg": "Changes are saved. Don't forget to publish your advertisement!",
"url": reverse("edit-order", args=[order.id, 3])}
- return http.HttpResponse(json.dumps(result),
+ return HttpResponse(json.dumps(result),
+ content_type="application/json")
+ elif step > 10:
+ result = {"result": "OK", "id": order.id, "msg": "This case 'elif step > 10'",
+ "url": reverse("edit-easy", args=[order.id, step])}
+ return HttpResponse(json.dumps(result),
content_type="application/json")
else:
result = {"result": "OK", "id": order.id, "msg": "This case 'else'",
- "url": reverse("edit-order", args=[order.id, step])}
- return http.HttpResponse(json.dumps(result),
+ "url": reverse("edit-fast", args=[order.id, step])}
+ return HttpResponse(json.dumps(result),
content_type="application/json")
View
114 templates/easy-form.html
@@ -2,7 +2,6 @@
<form id="easy_form" class="jClever filter calc" action="{% url 'ajax-save-order' step=12 %}" method="POST">
{% csrf_token %}
<input type="hidden" id="id" name="id" class="common" value="{{ object.id }}">
- <input type="hidden" id="templ" class="common" value="{{ object.templ }}">
<ul class="visual_first">
<li>
<span id="foil" data-price="
@@ -152,6 +151,26 @@
<label for="count">Тираж:</label>
<input type="text" class="edition" id="count" name="count" placeholder="500" value="{{ object.draw }}">
</li>
+
+ <input type="hidden" name="foil" class="flag" value="">
+ <input type="hidden" name="emboss" class="flag" value="">
+ <input type="hidden" name="sign" class="flag" value="">
+ <input type="hidden" name="indent" class="flag" value="">
+ <input type="hidden" name="print_num" class="flag" value="">
+ <input type="hidden" name="magnet" class="flag" value="">
+ <input type="hidden" name="barcode" class="flag" value="">
+ <input type="hidden" name="scratch" class="flag" value="">
+ <input type="hidden" name="uv" class="flag" value="">
+ <input type="hidden" name="chip" class="flag" value="">
+
+ <input type="hidden" name="count_hidden" value="">
+ <input type="hidden" name="sum" value="">
+ <input type="hidden" name="colors" value="">
+ <input type="hidden" name="materials" value="">
+ {% for it in coeff %}
+ <input type="hidden" name="{{ it.numb }}" value="{{ it.coeff }}" class="ratio">
+ {% endfor %}
+
<li>
<label for="color">Цвет:</label>
<div class="select color">
@@ -189,35 +208,15 @@
<input type="email" name="email" value="{{ object.email }}">
</li>
<li>
-
+<!--
<a href="#" class="next_step">Заказать</a>
-
- <!--
+-->
+
<input type="submit" name="order" value="Заказать" class="next_step">
- -->
+
</li>
</ul>
- <input type="hidden" name="foil" class="flag" value="">
- <input type="hidden" name="emboss" class="flag" value="">
- <input type="hidden" name="sign" class="flag" value="">
- <input type="hidden" name="indent" class="flag" value="">
- <input type="hidden" name="print_num" class="flag" value="">
- <input type="hidden" name="magnet" class="flag" value="">
- <input type="hidden" name="barcode" class="flag" value="">
- <input type="hidden" name="scratch" class="flag" value="">
- <input type="hidden" name="uv" class="flag" value="">
- <input type="hidden" name="chip" class="flag" value="">
-
- <input type="hidden" name="count_hidden" value="">
- <input type="hidden" name="sum" value="">
- <input type="hidden" name="colors" value="">
- <input type="hidden" name="materials" value="">
- <input type="hidden" name="1000" value="0.7" class="ratio">
- <input type="hidden" name="4000" value="0.6" class="ratio">
- <input type="hidden" name="7000" value="0.5" class="ratio">
- <input type="hidden" name="11000" value="0.4" class="ratio">
- <input type="hidden" name="15000" value="0.3" class="ratio">
</form>
@@ -301,7 +300,7 @@
range_array =[];
$('input.ratio').each(function() {
- var this_val = parseFloat($(this).val());
+ var this_val = parseFloat($(this).val().replace(',','.'));
this_name = parseFloat($(this).attr('name')),
q = count_val-this_name;
if(q > 0){
@@ -333,11 +332,12 @@
$('#easy_form a.next_step').click(function(){
//var data = $('#easy_form input').not('.flag, .ratio').serialize();
var flags = {};
-
$('input[type="hidden"]').not('.ratio').each(function() {
var this_val = parseFloat($(this).val());
+
this_name = $(this).attr('name'),
flags[this_name] = this_val;
+
});
function add_marker(){
$.each(flags, function(key, value){
@@ -361,6 +361,7 @@
console.log(flags);
//$('input#id').val(result.id);
+ /*
$('body').addClass('under_overlay')
.append('<div class="overlay"></div><div class="data_checking check_easy"><form class="jClever"></form></div>');
$('.check_easy > form').load('/static/include/helpers.html'
@@ -373,28 +374,73 @@
//console.log(data);
//console.log(data_flag);
return false;
+ */
});
- })
- /*
+ });
+
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ };
+ var csrftoken = getCookie('csrftoken');
+
+ function csrfSafeMethod(method) {
+ return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
+ };
+ function sameOrigin(url) {
+ var host = document.location.host; // host + port
+ var protocol = document.location.protocol;
+ var sr_origin = '//' + host;
+ var origin = protocol + sr_origin;
+ // Allow absolute or scheme relative URLs to same origin
+ return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
+ (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
+ // or any other URL that isn't scheme relative or absolute i.e relative.
+ !(/^(\/\/|http:|https:).*/.test(url));
+ };
+ $.ajaxSetup({
+ beforeSend: function(xhr, settings) {
+ console.log("Before SENT")
+ if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) {
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
+ }
+ }
+ });
+
$('#easy_form').submit(function(){
- //console.log("Call AJAX");
+ console.log("Call AJAX", csrftoken);
+ $('input[name="csrfmiddlewaretoken"]').val(csrftoken);
var action = $(this).attr('action');
var that = $(this);
- console.log(that);
$.ajax({
url: action,
type: 'POST',
data: that.serialize(),
+ beforeSend: function(xhr, settings) {
+ if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) {
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
+ }
+ },
success: function(result){
confirmOrder(result);
}
});
- console.log(data)
return false;
});
- */
+
/*
$('#easy_form a.next_step').click(function(){
var data = $('#easy_form input').not('.flag, .ratio').serialize();
@@ -403,7 +449,7 @@
$('body').addClass('under_overlay')
.append('<div class="overlay"></div><div class="data_checking check_easy"><form class="jClever"></form></div>');
$('.check_easy > form').load('/static/include/helpers.html'
- /*, function(){
+ , function(){
$('.jClever').jClever({
selfClass: "alice",
applyTo: {
View
2  templates/fast-form.html
@@ -1,6 +1,6 @@
<form id='fast_form' class="jClever" action="{% url 'ajax-save-order' step=2 %}" method="POST" enctype="multipart/form-data">
- {% csrf_token %}
+{# {% csrf_token %}#}
<input type="hidden" id="id" name="id" class="common" value="{{ object.id }}">
<input type="hidden" id="templ" class="common" value="{{ object.templ }}">
{{ coeff }}+ {% for it in coeff %}
View
21 templates/helpers.html
@@ -3,19 +3,22 @@
<span>Ваш заказ<small class="close_order"><i class="fa fa-times"></i></small></span>
<ul class="info">
<li>
- <span><i class="fa {% if templ.foil %}fa-check{% else %}fa-times{% endif %}"></i>Тиснение фольгой</span>
- <span><i class="fa {% if templ.emboss %}fa-check{% else %}fa-times{% endif %}"></i>Эмбоссирование</span>
- <span><i class="fa {% if templ.sign %}fa-check{% else %}fa-times{% endif %}"></i>Полоса для подписи</span>
- <span><i class="fa {% if templ.indent %}fa-check{% else %}fa-times{% endif %}"></i>Индент печать</span>
- <span><i class="fa {% if templ.print_num %}fa-check{% else %}fa-times{% endif %}"></i>Печатный номер</span>
- <span><i class="fa {% if templ.magnet %}fa-check{% else %}fa-times{% endif %}"></i>Магнитная полоса</span>
- <span><i class="fa {% if templ.barcode %}fa-check{% else %}fa-times{% endif %}"></i>Штрих код</span>
- <span><i class="fa {% if templ.scratch %}fa-check{% else %}fa-times{% endif %}"></i>Скрейтч панель</span>
+ <span class="foil"><i class="fa {% if templ.foil %}fa-check{% else %}fa-times{% endif %}"></i>Тиснение фольгой</span>
+ <span class="emboss"><i class="fa {% if templ.emboss %}fa-check{% else %}fa-times{% endif %}"></i>Эмбоссирование</span>
+ <span class="sign"><i class="fa {% if templ.sign %}fa-check{% else %}fa-times{% endif %}"></i>Полоса для подписи</span>
+ <span class="indent"><i class="fa {% if templ.indent %}fa-check{% else %}fa-times{% endif %}"></i>Индент печать</span>
+ <span class="print_num"><i class="fa {% if templ.print_num %}fa-check{% else %}fa-times{% endif %}"></i>Печатный номер</span>
+ <span class="magnet"><i class="fa {% if templ.magnet %}fa-check{% else %}fa-times{% endif %}"></i>Магнитная полоса</span>
+ <span class="barcode"><i class="fa {% if templ.barcode %}fa-check{% else %}fa-times{% endif %}"></i>Штрих код</span>
+ <span class="scratch"><i class="fa {% if templ.scratch %}fa-check{% else %}fa-times{% endif %}"></i>Скрейтч панель</span>
+ <span class="chip"><i class="fa {% if templ.chip %}fa-check{% else %}fa-times{% endif %}"></i>Карта с чипом</span>
+ <span class="uv"><i class="fa {% if templ.uv %}fa-check{% else %}fa-times{% endif %}"></i>Печать УФ краской</span>
</li>
<li>
<span><span>Тираж</span>{{ object.draw }}</span>
- <span><span>Цвета</span>{{ color_front }}+{{ color_back }}</span>
+ <span><span>Цвета</span>{{ color_front }}{% if color_back %}+{{ color_back }}{% else %}{% endif %}</span>
<span><span>Материал</span>{{ material }}</span>
+ <span><span>Ламинция</span>{% if lamination %}{{ lamination }}{% else %}Нет{% endif %}</span>
<span><span>ФИО</span>{{ object.FIO }}</span>
<span><span>Телефон</span>{{ object.phone }}</span>
<span><span>Email</span>{{ object.email }}</span>
View
29 theme/include/helpers.html
@@ -1,24 +1,29 @@
<div class="order">
<span>Ваш заказ<small class="close_order"><i class="fa fa-times"></i></small></span>
<ul class="info">
+
<li>
- <span><i class="fa fa-check"></i>Тиснение фольгой</span>
- <span><i class="fa fa-times"></i>Эмбоссирование</span>
- <span><i class="fa fa-times"></i>Полоса для подписи</span>
- <span><i class="fa fa-check"></i>Индент печать</span>
- <span><i class="fa fa-times"></i>Печатный номер</span>
- <span><i class="fa fa-check"></i>Магнитная полоса</span>
- <span><i class="fa fa-times"></i>Штрих код</span>
- <span><i class="fa fa-times"></i>Скрейтч панель</span>
+ <span class="foil"><i class="fa fa-check"></i>Тиснение фольгой</span>
+ <span class="emboss"><i class="fa fa-times"></i>Эмбоссирование</span>
+ <span class="sign"><i class="fa fa-times"></i>Полоса для подписи</span>
+ <span class="indent"><i class="fa fa-check"></i>Индент печать</span>
+ <span class="print_num"><i class="fa fa-times"></i>Печатный номер</span>
+ <span class="magnet"><i class="fa fa-check"></i>Магнитная полоса</span>
+ <span class="barcode"><i class="fa fa-times"></i>Штрих код</span>
+ <span class="scratch"><i class="fa fa-times"></i>Скрейтч панель</span>
+ <span class="uv"><i class="fa fa-times"></i>Печать УФ краской</span>
+ <span class="chip"><i class="fa fa-times"></i>Карта с чипом</span>
+
+
</li>
<li>
- <span><span>Тираж</span>10000</span>
- <span><span>Цвета</span>4+4</span>
- <span><span>Материал</span>Пластик</span>
+ <span class="count_hidden"><span>Тираж</span><small></small></span>
+ <span class="colors"><span>Цвета</span><small></small></span>
+ <span class="materials"><span>Материал</span><small></small></span>
<span><span>ФИО</span>Балаев Дмитрий Алексеевич</span>
<span><span>Телефон</span>+7(982) 000 00 00</span>
<span><span>Email</span>superman_23_2014@googlemail.com</span>
- <span class="full_price"><span>Сумма заказа</span>1000000 руб.</span>
+ <span class="full_price sum"><span>Сумма заказа</span><small></small> руб.</span>
</li>
</ul>
<ul>
Please sign in to comment.
Something went wrong with that request. Please try again.