Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Work on third calculator.

  • Loading branch information...
commit bb3b21bd9298131bdf5609a12384891fe6656f72 1 parent 3d028bf
@Guest007 authored
Showing with 70 additions and 11 deletions.
  1. +1 −0  eurocard/urls.py
  2. +58 −0 orders/views.py
  3. +11 −11 templates/ready-form.html
View
1  eurocard/urls.py
@@ -38,6 +38,7 @@
url(r"^(?P<pk>\d+)/$", orders.edit_easy, name="edit-easy"),
url(r"^uploadfile/", orders.ajax_save, name="uploadfile"),
url(r"^save/ajax/(?P<step>\d+)/$", orders.save_order, name="ajax-save-order"),
+ url(r"^save/templ/(?P<step>\d+)/$", orders.save_order1, name="ajax-save-torder"),
url(r'^test/', views.test, name='test'),
View
58 orders/views.py
@@ -274,6 +274,64 @@ def save_order(request, step=1):
@csrf_exempt
+def save_order1(request, step=1):
+ """Save order from template with AJAX"""
+ if request.method != "POST":
+ result = {"result": "ERROR", "msg": "Wrong request method"}
+ return http.HttpResponse(json.dumps(result),
+ content_type="application/json")
+
+ try:
+ id = int(request.POST.get("id", 0)) # Если редактруем созданный заказ
+ except (TypeError, ValueError):
+ id = 0
+
+ time = datetime.datetime.now()
+
+ templ = OrderTemplate.objects.get(id=id)
+ price = templ.price
+ print price
+ templ.pk = 0
+ templ.is_template = False
+ templ.name = str(time) + " " + templ.name
+ templ.price = None
+ templ.save() # взяли шаблон по id, обрали признак шаблона и скопировали.
+
+ order = Orders(template=templ)
+ draw = request.POST.get("count", None)
+ order.draw = draw
+ order.cost = float(draw) * float(price)
+
+ order.save() # привязали заказ к шаблону, посчитали цену, записали. Теперь нужны остальные данные и всё.
+
+ print order.cost
+ print order.template.name
+
+
+ # user = request.POST.get("user", None)
+ # phone = request.POST.get("phone", None)
+ # email = request.POST.get("email", None)
+
+ if step == '1':
+ result = {"result": "OK", "id": order.id,
+ "msg": "Changes are saved",
+ "url": reverse("edit-order", args=[order.id, 3])}
+ 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-fast", args=[order.id, step])}
+ return HttpResponse(json.dumps(result),
+ content_type="application/json")
+
+
+
+@csrf_exempt
def callback(request):
name = request.POST.get('fio', False)
phone = request.POST.get('phone', False)
View
22 templates/ready-form.html
@@ -17,22 +17,22 @@
{% if item.barcode %}<li>печать штрих-кода</li>{% endif %}
{% if item.indent %}<li>индентная печать</li>{% endif %}
</ul>
- <form id="{{ item.id }}" class="jClever calc_easy" action="{% url 'ajax-save-order' step=22 %}" method="POST">
+ <form id="{{ item.id }}" class="jClever calc_easy" action="{% url 'ajax-save-torder' step=22 %}" method="POST">
{% csrf_token %}
<input type="hidden" name="id" value="{{ item.id }}">
<label>Тираж<span><i class="fa fa-question"></i></span></label>
<input type="text" name="count" class="calc"><span>x <small>{{ item.price }}</small> = <span></span></span>
<input type="submit" name="order" value="Заказать" class="next_step">
- {% if item.chip %}<input type="hidden" name="chip" value="1">{% endif %}
- {% if item.scratch %}<input type="hidden" name="scratch" value="1">{% endif %}
- {% if item.magnet %}<input type="hidden" name="magnet" value="1">{% endif %}
- {% if item.emboss %}<input type="hidden" name="emboss" value="1">{% endif %}
- {% if item.uv %}<input type="hidden" name="uv" value="1">{% endif %}
- {% if item.print_num %}<input type="hidden" name="print_num" value="1">{% endif %}
- {% if item.sign %}<input type="hidden" name="sign" value="1">{% endif %}
- {% if item.foil %}<input type="hidden" name="foil" value="1">{% endif %}
- {% if item.barcode %}<input type="hidden" name="barcode" value="1">{% endif %}
- {% if item.indent %}<input type="hidden" name="indent" value="1">{% endif %}
+{# {% if item.chip %}<input type="hidden" name="chip" value="1">{% endif %}#}
+{# {% if item.scratch %}<input type="hidden" name="scratch" value="1">{% endif %}#}
+{# {% if item.magnet %}<input type="hidden" name="magnet" value="1">{% endif %}#}
+{# {% if item.emboss %}<input type="hidden" name="emboss" value="1">{% endif %}#}
+{# {% if item.uv %}<input type="hidden" name="uv" value="1">{% endif %}#}
+{# {% if item.print_num %}<input type="hidden" name="print_num" value="1">{% endif %}#}
+{# {% if item.sign %}<input type="hidden" name="sign" value="1">{% endif %}#}
+{# {% if item.foil %}<input type="hidden" name="foil" value="1">{% endif %}#}
+{# {% if item.barcode %}<input type="hidden" name="barcode" value="1">{% endif %}#}
+{# {% if item.indent %}<input type="hidden" name="indent" value="1">{% endif %}#}
</form>
</li>
Please sign in to comment.
Something went wrong with that request. Please try again.