diff --git a/project/customer/forms.py b/project/customer/forms.py index 80045f2..dcd343f 100644 --- a/project/customer/forms.py +++ b/project/customer/forms.py @@ -40,6 +40,11 @@ class UserProfileForm(MyBaseModelForm): Форму для админки ищи ниже в классе UserProfileAdminForm. """ + tmb_logo = forms.CharField(required=False, widget=forms.HiddenInput) + tmb_boss_sign = forms.CharField(required=False, widget=forms.HiddenInput) + tmb_glavbuh_sign = forms.CharField(required=False, widget=forms.HiddenInput) + tmb_stamp = forms.CharField(required=False, widget=forms.HiddenInput) + class Meta: model = models.UserProfile @@ -91,6 +96,7 @@ class IpUserProfileForm(UserProfileForm): 'address', 'real_address', 'phone_code', 'phone', 'fax_code', 'fax', 'email', 'site', # подписи, печать и логотип 'boss_sign', 'glavbuh_sign', 'stamp', 'logo', + 'tmb_logo', 'tmb_boss_sign', 'tmb_glavbuh_sign', 'tmb_stamp', ) @@ -113,6 +119,7 @@ class OrgUserProfileForm(UserProfileForm): 'address', 'jur_address', 'real_address', 'phone_code', 'phone', 'fax_code', 'fax', 'email', 'site', # подписи, печать и логотип 'boss_sign', 'glavbuh_sign', 'stamp', 'logo', + 'tmb_logo', 'tmb_boss_sign', 'tmb_glavbuh_sign', 'tmb_stamp', ) diff --git a/project/customer/models.py b/project/customer/models.py index 543d00f..0dbb5b2 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -16,10 +16,10 @@ from project.myauth.models import DokUser PROFILE_IMAGES_UPLOAD_DIR = 'customer/profile/' # куда сохранять загруженные изображения -BOSS_SIGN_IMG_SIZE = (100, 75) -GLAVBUH_SIGN_IMG_SIZE = (100, 75) -STAMP_IMG_SIZE = (180, 180) -LOGO_SIZE = (100, 50) +BOSS_SIGN_IMG_SIZE = (159, 65) +GLAVBUH_SIGN_IMG_SIZE = (159, 65) +STAMP_IMG_SIZE = (121, 121) +LOGO_SIZE = (351, 121) def get_profile(user): diff --git a/project/customer/urls.py b/project/customer/urls.py index 691e037..66d5178 100644 --- a/project/customer/urls.py +++ b/project/customer/urls.py @@ -16,7 +16,7 @@ urlpatterns = patterns('', url(r'^profile/edit/$', profile.profile_edit, name='customer_profile_edit'), url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'), url(r'^license/$', license.order_license, name='customer_order_license'), - url(r'^delete_license/(?P\d+)/$', license.delete_license, name='customer_order_license'), + url(r'^delete_license/(?P\d+)/$', license.delete_license, name='customer_delete_license'), url(r'^get_doc/(?P\d+)/$', docs.get_doc, name='customer_license_get_doc'), url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'), url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'), @@ -57,4 +57,6 @@ urlpatterns = patterns('', url(r'^clients/add/ajax/$', clients_ajax.clients_add_ajax, name='customer_clients_add_ajax'), url(r'^clients/(?P\d+)/edit/ajax/$', clients_ajax.clients_edit_ajax, name='customer_clients_edit_ajax'), url(r'^clients/(?P\d+)/delete/ajax/$', clients_ajax.clients_delete_ajax, name='customer_clients_delete_ajax'), + + url(r'^tmp_upload/ajax/$', profile.tmp_upload, name='upload_tmp_file'), ) diff --git a/project/customer/views/profile.py b/project/customer/views/profile.py index de2e35a..3281cb9 100644 --- a/project/customer/views/profile.py +++ b/project/customer/views/profile.py @@ -1,20 +1,26 @@ # -*- coding: utf-8 -*- +import os +import json +import tempfile from email.header import Header from django.shortcuts import render, redirect, get_object_or_404 +from django.core.files import File from django.views.decorators.csrf import csrf_protect from django.contrib.auth.decorators import login_required from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.utils.encoding import smart_str from django.conf import settings -from django.http import Http404 +from django.http import Http404, HttpResponse + +from sorl.thumbnail import get_thumbnail from project.commons.pdf_tools import render_pdf_to_string, pdf_to_response from .. import models, forms -from ..decorators import license_required - +from ..decorators import license_required + PDF_PROFILE_NAME = u'Реквизиты.pdf' SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') @@ -83,7 +89,20 @@ def profile_edit(request): if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES, instance=profile) if form.is_valid(): - form.save() + 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]: + chg_file = open(settings.MEDIA_ROOT + '/cache/imgs/' + \ + form.cleaned_data[img_url]) + print chg_file + 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() return redirect(success_url) else: form = form_class(instance=profile) @@ -97,6 +116,42 @@ def profile_edit(request): return render(request, template_name, dictionary) +def tmp_upload(request): + SIZES = {'id_boss_sign': '159x65', 'id_glavbuh_sign': '159x65', 'id_stamp': '121x121', 'id_logo': '351x121'} + elm_id = request.REQUEST['elm_id'] + file_ = request.FILES.values()[0] + 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/') + os.chmod(tmp_dir, 0755) + open(tmp_dir + '/' + file_.name, "w").write(file_.read()) + tmp_url_partial = os.path.basename(tmp_dir) + '/' + file_.name + im = get_thumbnail(tmp_dir + '/' + file_.name, SIZES[elm_id], quality=75) + data = {'res': 'ok', 'pic': im.url, 'full_pic': tmp_url_partial} + print data + data.update(request.REQUEST) + return HttpResponse(json.dumps(data), mimetype='application/json') + + +def del_tmp_photo(request, article_pk): + # wedding, wedding_guests = get_wedding_n_guests(request) + try: + pass + # article = WedPage.objects.get(pk=article_pk) + # article.main_photo.delete() + except: + return {'res': 'bad'} + + return {'res': 'ok'} + + @login_required def _profile_get_pdf(request, profile=None, account=None, filters=None): """Создать профиль пользователя в PDF и вернуть как строку.""" @@ -119,7 +174,7 @@ def profile_as_pdf(request, profile=None, account=None, filters=None): def _send_profile_email(subject, to, body, pdf_content): """Отправка письма.""" template_name = 'customer/profile/profile_email.txt' - dict_context = {'body': body, 'support_email': SUPPORT_EMAIL,} + dict_context = {'body': body, 'support_email': SUPPORT_EMAIL} email_body = render_to_string(template_name, dict_context) email = EmailMessage( subject=subject, diff --git a/project/static/css/style.css b/project/static/css/style.css index ec76217..bdc4651 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -67,8 +67,8 @@ body { .content-white {width:1200px;background:#fff;box-shadow: 0 0 5px #ddd;padding:15px 15px 0 15px;box-sizing:border-box;margin-bottom:70px;} #header {height:100px;width:100%;position:relative;} -#logo {font-family:"MyriadProRegular";display:block;overflow:hidden;margin-top:18px;} -#logo .logo-bigfont {font-size:30px;line-height:30px;margin-top:12px;text-transform:uppercase;} +#site_logo {font-family:"MyriadProRegular";display:block;overflow:hidden;margin-top:18px;} +#site_logo .logo-bigfont {font-size:30px;line-height:30px;margin-top:12px;text-transform:uppercase;} .logo-text {margin-left:10px; font-size:18px;color:#3e454c;line-height:18px;} .auth_block {margin-top:30px;} .login, .register {display:block;padding-left:34px;margin: 0 3px;height:36px;text-decoration:none;font-family:Arial,Helvetica,sans-serif;color:#36393f; line-height:36px;} @@ -350,7 +350,6 @@ ul { clear: both; list-style: none; margin: 0; padding: 0; } .has-datepicker { background: url(../img/icon-calendar.png) no-repeat scroll right 5px center #f8f8f8; } -.profile-form input#id_ip_reg_date { background: url(../img/icon-calendar.png) no-repeat scroll right center transparent; } #id_phone_code, #id_fax_code { width: 60px; } #accounts .account-delete a { text-decoration: none; } @@ -569,3 +568,28 @@ tr.doc-row:hover {cursor:pointer;} #req-avail-form {display:none;} .close-message {display:inline-block;float:right;} +.profile_title {font-size:16px;height:33px;width:790px;border-bottom:solid 1px #fed13e;margin: 10px 0 25px 0;} +.profile_label {float:left;width:285px;font-size:14px;height:36px;line-height:36px;} +.profile_field {float:left;width:500px;} +.profile_field input[type=text], .profile_field input[type=email], .profile_field input[type=number], .profile_field input[type=password], .profile_field textarea, .profile_field option {padding-left:2px;margin-left:0;height:36px;font-size:14px;} +.profile_field.long-input input { width: 100%; } +.profile_field input { width: 300px; } +.profile-form .field {margin: 0 0 15px 0;} +.profile-form .help-text {margin: 0; padding:0 0 0 5px;color:#c5c5c5;} + +#id_boss_surname, #id_boss_name, #id_boss_midname, #id_glavbuh_surname, #id_glavbuh_name, #id_glavbuh_midname{width:157px;} +#boss_sign, #glavbuh_sign {width:159px;height:65px;float:left;overflow:hidden;} +#glavbuh_sign {margin-left:30px;} +#stamp .profile_field {width:121px;height:121px;} +#logo .profile_field {width:351px;height:121px;} +.del_image {display:block;width:27px;height:20px;background:url(../img/icon-delete.png)7px center no-repeat;position:absolute;top:0;right:0;} +.rel {position:relative;} +.img_field {border:1px solid #f2f2f2;} +.profile_btns {margin: 10px; padding:10px;} +.profile_btns input {display:inline;font-family:"Arial Narrow", Arial, sans-serif;font-size:22px;text-transform:uppercase;font-weight:bold;padding:25px;border:none;} +.profile_btns .yellow-btn.save {background:#fed13e url(../img/save.png) no-repeat 25px center;padding:25px 15px 25px 60px;} +#blackbox {width:350px;position:absolute;top:60px;right:20px;} +#blackbox .bb-text {width:320px;background:#272b31;padding:20px;color:#fff;font-style:italic;line-height:1.7;} +#blackbox .bb-triangle {background: url(../img/triangle2.png) no-repeat center center;width:11px;height:25px;position:absolute;left:-8px;top:16px;} +#blackbox p {margin:0;padding:0;} +#blackbox a {color:#fff;font-weight:bold;margin: 10px 0 0 0; display:block;} diff --git a/project/static/img/glavbuh_sign.png b/project/static/img/glavbuh_sign.png new file mode 100644 index 0000000..9289651 Binary files /dev/null and b/project/static/img/glavbuh_sign.png differ diff --git a/project/static/img/upload-boss_sign.png b/project/static/img/upload-boss_sign.png new file mode 100644 index 0000000..9289651 Binary files /dev/null and b/project/static/img/upload-boss_sign.png differ diff --git a/project/static/img/upload-glavbuh_sign.png b/project/static/img/upload-glavbuh_sign.png new file mode 100644 index 0000000..9289651 Binary files /dev/null and b/project/static/img/upload-glavbuh_sign.png differ diff --git a/project/static/img/upload-logo.png b/project/static/img/upload-logo.png new file mode 100644 index 0000000..70797a4 Binary files /dev/null and b/project/static/img/upload-logo.png differ diff --git a/project/static/img/upload-stamp.png b/project/static/img/upload-stamp.png new file mode 100644 index 0000000..51a3e7b Binary files /dev/null and b/project/static/img/upload-stamp.png differ diff --git a/project/templates/base.html b/project/templates/base.html index f540aa1..27ac732 100644 --- a/project/templates/base.html +++ b/project/templates/base.html @@ -37,7 +37,7 @@