Skip to content

Commit

Permalink
Work on third calculator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guest007 committed Feb 23, 2014
1 parent 3d028bf commit bb3b21b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions eurocard/urls.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
url(r"^(?P<pk>\d+)/$", orders.edit_easy, name="edit-easy"), url(r"^(?P<pk>\d+)/$", orders.edit_easy, name="edit-easy"),
url(r"^uploadfile/", orders.ajax_save, name="uploadfile"), 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/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'), url(r'^test/', views.test, name='test'),


Expand Down
58 changes: 58 additions & 0 deletions orders/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -273,6 +273,64 @@ def save_order(request, step=1):
content_type="application/json") content_type="application/json")




@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 @csrf_exempt
def callback(request): def callback(request):
name = request.POST.get('fio', False) name = request.POST.get('fio', False)
Expand Down
22 changes: 11 additions & 11 deletions templates/ready-form.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
{% if item.barcode %}<li>печать штрих-кода</li>{% endif %} {% if item.barcode %}<li>печать штрих-кода</li>{% endif %}
{% if item.indent %}<li>индентная печать</li>{% endif %} {% if item.indent %}<li>индентная печать</li>{% endif %}
</ul> </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 %} {% csrf_token %}
<input type="hidden" name="id" value="{{ item.id }}"> <input type="hidden" name="id" value="{{ item.id }}">
<label>Тираж<span><i class="fa fa-question"></i></span></label> <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="text" name="count" class="calc"><span>x <small>{{ item.price }}</small> = <span></span></span>
<input type="submit" name="order" value="Заказать" class="next_step"> <input type="submit" name="order" value="Заказать" class="next_step">
{% if item.chip %}<input type="hidden" name="chip" 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.scratch %}<input type="hidden" name="scratch" value="1">{% endif %}#}
{% if item.magnet %}<input type="hidden" name="magnet" 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.emboss %}<input type="hidden" name="emboss" value="1">{% endif %}#}
{% if item.uv %}<input type="hidden" name="uv" 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.print_num %}<input type="hidden" name="print_num" value="1">{% endif %}#}
{% if item.sign %}<input type="hidden" name="sign" 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.foil %}<input type="hidden" name="foil" value="1">{% endif %}#}
{% if item.barcode %}<input type="hidden" name="barcode" 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.indent %}<input type="hidden" name="indent" value="1">{% endif %}#}
</form> </form>
</li> </li>


Expand Down

0 comments on commit bb3b21b

Please sign in to comment.