Permalink
Browse files

Первые 2 калькулятора в основном работают.

  • Loading branch information...
1 parent e6eee00 commit 081ddd5f97e59536f92d5c7f11672bf818c4d849 @Guest007 committed Feb 20, 2014
Showing with 802 additions and 961 deletions.
  1. +2 −1 articles/views.py
  2. +4 −1 eurocard/urls.py
  3. +62 −29 orders/views.py
  4. +1 −0 templates/base.html
  5. +22 −298 templates/easy-form.html
  6. +119 −63 templates/fast-form.html
  7. +3 −20 templates/helpers.html
  8. +3 −101 templates/home1.html
  9. +27 −18 templates/ready-form.html
  10. +85 −42 theme/css/template.css
  11. +209 −214 theme/css/template.less
  12. +265 −174 theme/js/init.js
View
@@ -61,4 +61,5 @@ def contacts(request):
def test(request):
# production = Article.objects.get(category__slug='prod')
# context = {'prod': production}
- return render(request, 'home1.html')
+ return render(request, 'home1.html')
+
View
@@ -9,6 +9,7 @@
import grappelli
from filebrowser.sites import site
from orders.views import save_order
+# from django.views.generic.simple import direct_to_template
admin.autodiscover()
@@ -32,6 +33,7 @@
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"^uploadfile/", orders.ajax_save, name="uploadfile"),
url(r"^save/ajax/(?P<step>\d+)/$", orders.save_order, name="ajax-save-order"),
url(r'^test/', views.test, name='test'),
@@ -46,4 +48,5 @@
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
- ) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+ ) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+
View
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
+import os
from annoying.functions import get_object_or_None
from annoying.decorators import render_to
+import datetime, time
+from django.core.files.base import ContentFile
+from django.core.files.storage import default_storage
from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404
from django.shortcuts import render_to_response
@@ -101,7 +105,45 @@ def nextstep_order(request, pk):
'color_front': templ.color_front,
'color_back': templ.color_back}
return render_to_response('helpers.html', result,
- content_type="text/html; charset=utf-8")
+ content_type="text/html; charset=utf-8",
+ context_instance=RequestContext(request))
+
+
+@csrf_exempt
+def ajax_save(request):
+ # print request.FILES
+ result = []
+ if len(request.FILES) == 1:
+ upload = request.FILES.values()[0]
+ else:
+ raise http.Http404("Bad upload")
+ filename = upload.name
+ # print filename
+ ffile = save_uploaded_file_new(upload, filename)
+ if ffile is not None and ffile is not False:
+ result.append(ffile)
+ else:
+ result.append({"error": "Error save file"})
+ response = http.HttpResponse('<input type="hidden" id="fd" name="maket" value="' + ffile + '"></input>',
+ content_type="text/html; charset=utf-8")
+ return response
+
+
+def save_uploaded_file_new(uploaded, fname):
+ """Just save uploaded file"""
+ ufile = None
+ try:
+ split = fname.rsplit('.', 1)
+ file = uploaded
+ dt = datetime.datetime.now()
+ name = '%s-%s' % (split[0], (int(time.mktime(dt.timetuple()))))
+ name = 'maket/' + name + '.' + split[1]
+ path = default_storage.save(name, ContentFile(file.read()))
+ except Exception as e:
+ print e
+ if os.path.exists(name.decode('utf-8')):
+ os.unlink(name.decode('utf-8'))
+ return path
@csrf_protect
@@ -134,19 +176,16 @@ def save_order(request, step=1):
if templ is None:
templ = OrderTemplate(name=(user if user else '')) # Создаем тело заказа. Название - имя заказчика
- if step > 20:
+ if int(step) > 20:
print request.POST
print request.POST.get("id", False)
- print request.POST.get("emboss", False)
- elif step > 10:
- # print "STEP more than 10"
- print request.POST
+ # print request.POST.get("emboss", False)
+ elif int(step) > 10:
+ # print request.POST
templ.color_back = None # Color(id=request.POST.get("color_back", None))
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)
@@ -158,33 +197,26 @@ def save_order(request, step=1):
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:
+ # print request.POST
templ.color_back = Color(id=request.POST.get("color_back", None))
templ.color_front = Color(id=request.POST.get("color_front", None))
templ.material = Material(id=request.POST.get("materials", None))
templ.lamination = Lamination(id=request.POST.get("lamination", None))
- templ.chip = request.POST.get("chip", False)
- templ.uv = request.POST.get("uv", False)
- templ.magnet = request.POST.get("magnet", False)
- templ.emboss = request.POST.get("emboss", False)
- templ.scratch = request.POST.get("scratch", False)
- templ.print_num = request.POST.get("print_num", False)
- templ.sign = request.POST.get("sign", False)
- templ.indent = request.POST.get("indent", False)
- 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
+ templ.chip = (True if float(request.POST.get("chip", False)) > 0 else False)
+ templ.uv = (True if float(request.POST.get("uv", False)) > 0 else 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)
draw = request.POST.get("count", 500) # количество в заказ
- # print "DRAW: ", draw
- # print templ
+
templ.save() # Сохраняем тело заказа для того, чтобы потом создать сам заказ
if templ is None: # Если тело заказа не сохранилось - возвращаем ошибку?
result = {"result": "ERROR", "msg": "Please, correct the property type to get access to other tabs."}
@@ -215,13 +247,14 @@ def save_order(request, step=1):
order.phone = phone
# print order.phone
order.maket = maket
+ print maket
order.save()
# 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!",
+ "msg": "Changes are saved",
"url": reverse("edit-order", args=[order.id, 3])}
return HttpResponse(json.dumps(result),
content_type="application/json")
View
@@ -12,6 +12,7 @@
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
[endif]-->
<script src='{{ STATIC_URL }}libs/jquery-1.10.2.min.js'></script>
+ <script src="http://malsup.github.com/jquery.form.js"></script>
<script src='{{ STATIC_URL }}libs/helper/jquery.jscrollpane.min.js'></script>
<script src='{{ STATIC_URL }}libs/helper/jquery.mousewheel.min.js'></script>
<script src='{{ STATIC_URL }}libs/helper/jquery.transit.min.js'></script>
Oops, something went wrong.

0 comments on commit 081ddd5

Please sign in to comment.