|
|
|
@ -14,7 +14,8 @@ from django.utils.encoding import smart_str |
|
|
|
from django.conf import settings |
|
|
|
from django.conf import settings |
|
|
|
from django.http import Http404, HttpResponse |
|
|
|
from django.http import Http404, HttpResponse |
|
|
|
|
|
|
|
|
|
|
|
from sorl.thumbnail import get_thumbnail |
|
|
|
# from sorl.thumbnail import get_thumbnail |
|
|
|
|
|
|
|
from easy_thumbnails.files import get_thumbnailer |
|
|
|
|
|
|
|
|
|
|
|
from project.commons.pdf_tools import render_pdf_to_string, pdf_to_response |
|
|
|
from project.commons.pdf_tools import render_pdf_to_string, pdf_to_response |
|
|
|
|
|
|
|
|
|
|
|
@ -117,7 +118,7 @@ def profile_edit(request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tmp_upload(request): |
|
|
|
def tmp_upload(request): |
|
|
|
SIZES = {'id_boss_sign': '159x65', 'id_glavbuh_sign': '159x65', 'id_stamp': '180x180', 'id_logo': '351x121'} |
|
|
|
SIZES = {'id_boss_sign': (159, 65), 'id_glavbuh_sign': (159, 65), 'id_stamp': (180, 180), 'id_logo': (351, 121)} |
|
|
|
elm_id = request.REQUEST['elm_id'] |
|
|
|
elm_id = request.REQUEST['elm_id'] |
|
|
|
file_ = request.FILES.values()[0] |
|
|
|
file_ = request.FILES.values()[0] |
|
|
|
if not file_.content_type.startswith('image'): |
|
|
|
if not file_.content_type.startswith('image'): |
|
|
|
@ -133,9 +134,12 @@ def tmp_upload(request): |
|
|
|
os.chmod(tmp_dir, 0755) |
|
|
|
os.chmod(tmp_dir, 0755) |
|
|
|
open(tmp_dir + '/' + file_.name, "w").write(file_.read()) |
|
|
|
open(tmp_dir + '/' + file_.name, "w").write(file_.read()) |
|
|
|
tmp_url_partial = os.path.basename(tmp_dir) + '/' + file_.name |
|
|
|
tmp_url_partial = os.path.basename(tmp_dir) + '/' + file_.name |
|
|
|
im = get_thumbnail(tmp_dir + '/' + file_.name, SIZES[elm_id], quality=75) |
|
|
|
thumbnailer = get_thumbnailer(tmp_dir + '/' + file_.name) |
|
|
|
data = {'res': 'ok', 'pic': im.url, 'full_pic': tmp_url_partial} |
|
|
|
# im = get_thumbnail(tmp_dir + '/' + file_.name, SIZES[elm_id], quality=75) |
|
|
|
print data |
|
|
|
thumbnail_options = {'size': SIZES[elm_id]} |
|
|
|
|
|
|
|
im = thumbnailer.get_thumbnail(thumbnail_options) # Возвращает в url полный путь, поэтому придётся резать |
|
|
|
|
|
|
|
im_url = os.path.join(settings.MEDIA_URL, os.path.relpath(im.url, settings.MEDIA_ROOT)) |
|
|
|
|
|
|
|
data = {'res': 'ok', 'pic': im_url, 'full_pic': tmp_url_partial} |
|
|
|
data.update(request.REQUEST) |
|
|
|
data.update(request.REQUEST) |
|
|
|
return HttpResponse(json.dumps(data), mimetype='application/json') |
|
|
|
return HttpResponse(json.dumps(data), mimetype='application/json') |
|
|
|
|
|
|
|
|
|
|
|
|