|
|
|
|
@ -23,7 +23,6 @@ from customer import models, forms |
|
|
|
|
from customer.decorators import license_required |
|
|
|
|
from customer.utils import raise_if_no_profile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PDF_PROFILE_NAME = u'Реквизиты.pdf' |
|
|
|
|
SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') |
|
|
|
|
|
|
|
|
|
@ -51,7 +50,7 @@ def profile_view(request): |
|
|
|
|
filters = filters_form.save() |
|
|
|
|
|
|
|
|
|
if 'download-pdf' in request.POST: |
|
|
|
|
#return _profile_get_pdf(request, profile, filters.bank_account, filters) # для отладки |
|
|
|
|
# return _profile_get_pdf(request, profile, filters.bank_account, filters) # для отладки |
|
|
|
|
return profile_as_pdf(request, profile, filters.bank_account, filters) |
|
|
|
|
elif 'email-pdf' in request.POST: |
|
|
|
|
return redirect('customer_profile_email') |
|
|
|
|
@ -91,17 +90,22 @@ def profile_edit(request): |
|
|
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
|
form = form_class(data=request.POST, files=request.FILES, instance=profile) |
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
item = form.save(commit=False) |
|
|
|
|
|
|
|
|
|
for img_url in ('tmb_logo', 'tmb_boss_sign', 'tmb_glavbuh_sign', 'tmb_stamp'): |
|
|
|
|
if form.cleaned_data[img_url]: |
|
|
|
|
# TODO ? |
|
|
|
|
chg_file = open(settings.MEDIA_ROOT + '/cache/imgs/' + \ |
|
|
|
|
form.cleaned_data[img_url]) |
|
|
|
|
form.cleaned_data[img_url], mode='rb+') |
|
|
|
|
item_attr = img_url[4:] |
|
|
|
|
|
|
|
|
|
getattr(item, item_attr).save('%s.%s' % \ |
|
|
|
|
(item_attr, form.cleaned_data[img_url].split('.')[-1]), |
|
|
|
|
File(chg_file)) |
|
|
|
|
chg_file.close() |
|
|
|
|
# |
|
|
|
|
elif form.cleaned_data: |
|
|
|
|
pass |
|
|
|
|
item.save() |
|
|
|
|
@ -120,21 +124,22 @@ def profile_edit(request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tmp_upload(request): |
|
|
|
|
SIZES = {'id_boss_sign': (170, 65), 'id_glavbuh_sign': (170, 65), 'id_stamp': (170, 170), 'id_logo': (170, 170)} |
|
|
|
|
key = '' |
|
|
|
|
SIZES = {'id_boss_sign': (170, 65), |
|
|
|
|
'id_glavbuh_sign': (170, 65), |
|
|
|
|
'id_stamp': (170, 170), |
|
|
|
|
'id_logo': (170, 170)} |
|
|
|
|
elm_id = request.REQUEST['elm_id'] |
|
|
|
|
file_ = request.FILES.values()[0] |
|
|
|
|
for k in request.FILES.keys(): |
|
|
|
|
key = k |
|
|
|
|
file_ = request.FILES.get(key) |
|
|
|
|
if not file_.content_type.startswith('image'): |
|
|
|
|
return {'res': 'bad'} |
|
|
|
|
|
|
|
|
|
if not os.path.exists(settings.MEDIA_ROOT + |
|
|
|
|
'/cache/imgs/'): |
|
|
|
|
os.makedirs(settings.MEDIA_ROOT + |
|
|
|
|
'/cache/imgs/') |
|
|
|
|
|
|
|
|
|
tmp_dir = tempfile.mkdtemp('img_tmp', settings.MEDIA_ROOT + |
|
|
|
|
'/cache/imgs/') |
|
|
|
|
if not os.path.exists(settings.MEDIA_ROOT + '/cache/imgs/'): |
|
|
|
|
os.makedirs(settings.MEDIA_ROOT + '/cache/imgs/') |
|
|
|
|
tmp_dir = tempfile.mkdtemp('img_tmp', settings.MEDIA_ROOT + '/cache/imgs/') |
|
|
|
|
os.chmod(tmp_dir, 755) |
|
|
|
|
open(tmp_dir + '/' + file_.name, "w").write(file_.read()) |
|
|
|
|
open(tmp_dir + '/' + file_.name, "wb+").write(file_.read()) |
|
|
|
|
tmp_url_partial = os.path.basename(tmp_dir) + '/' + file_.name |
|
|
|
|
thumbnailer = get_thumbnailer(tmp_dir + '/' + file_.name) |
|
|
|
|
# im = get_thumbnail(tmp_dir + '/' + file_.name, SIZES[elm_id], quality=75) |
|
|
|
|
@ -146,6 +151,7 @@ def tmp_upload(request): |
|
|
|
|
return HttpResponse(json.dumps(data), content_type='application/json') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO ? |
|
|
|
|
def del_tmp_photo(request, article_pk): |
|
|
|
|
# wedding, wedding_guests = get_wedding_n_guests(request) |
|
|
|
|
try: |
|
|
|
|
@ -156,6 +162,7 @@ def del_tmp_photo(request, article_pk): |
|
|
|
|
return {'res': 'bad'} |
|
|
|
|
|
|
|
|
|
return {'res': 'ok'} |
|
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@ -186,7 +193,7 @@ def _send_profile_email(subject, to, body, pdf_content): |
|
|
|
|
subject=subject, |
|
|
|
|
to=(to,), |
|
|
|
|
body=email_body, |
|
|
|
|
attachments = [(smart_str(Header(PDF_PROFILE_NAME, 'cp1251')), pdf_content, 'application/pdf'),] |
|
|
|
|
attachments=[(smart_str(Header(PDF_PROFILE_NAME, 'cp1251')), pdf_content, 'application/pdf'), ] |
|
|
|
|
) |
|
|
|
|
return email.send() |
|
|
|
|
|
|
|
|
|
@ -214,21 +221,20 @@ def profile_email(request): |
|
|
|
|
form = form_class(data=request.POST) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
_send_profile_email( |
|
|
|
|
subject = u'Реквизиты %s' % profile.get_company_name(), |
|
|
|
|
to = form.cleaned_data['to'], |
|
|
|
|
body = form.cleaned_data['body'], |
|
|
|
|
pdf_content = _profile_get_pdf(request, profile, filters.bank_account, filters) |
|
|
|
|
subject=u'Реквизиты %s' % profile.get_company_name(), |
|
|
|
|
to=form.cleaned_data['to'], |
|
|
|
|
body=form.cleaned_data['body'], |
|
|
|
|
pdf_content=_profile_get_pdf(request, profile, filters.bank_account, filters) |
|
|
|
|
) |
|
|
|
|
return redirect(success_url) |
|
|
|
|
else: |
|
|
|
|
form = form_class() |
|
|
|
|
|
|
|
|
|
return render(request, template_name, {'form': form, 'profile': profile,}) |
|
|
|
|
|
|
|
|
|
return render(request, template_name, {'form': form, 'profile': profile, }) |
|
|
|
|
|
|
|
|
|
#@login_required |
|
|
|
|
#@csrf_protect |
|
|
|
|
#def profile_settings(request): |
|
|
|
|
# @login_required |
|
|
|
|
# @csrf_protect |
|
|
|
|
# def profile_settings(request): |
|
|
|
|
# """Редактировать настройки пользователя.""" |
|
|
|
|
# template_name='customer/profile/settings.html' |
|
|
|
|
# |
|
|
|
|
|