From be367f94b1bc9c406079bdd868778d2ca37ab84a Mon Sep 17 00:00:00 2001 From: Bachurin Sergey Date: Mon, 27 Apr 2015 01:18:19 +0300 Subject: [PATCH] almost edit profile page --- project/customer/forms.py | 7 + project/customer/models.py | 8 +- project/customer/urls.py | 4 +- project/customer/views/profile.py | 65 ++++- project/static/css/style.css | 30 +- project/static/img/glavbuh_sign.png | Bin 0 -> 416 bytes project/static/img/upload-boss_sign.png | Bin 0 -> 416 bytes project/static/img/upload-glavbuh_sign.png | Bin 0 -> 416 bytes project/static/img/upload-logo.png | Bin 0 -> 584 bytes project/static/img/upload-stamp.png | Bin 0 -> 473 bytes project/templates/base.html | 2 +- .../customer/bank_accounts/list.html | 2 +- project/templates/customer/img_load.html | 20 ++ project/templates/customer/img_load.png | 33 +++ project/templates/customer/profile/edit.html | 271 +++++++++++------- 15 files changed, 326 insertions(+), 116 deletions(-) create mode 100644 project/static/img/glavbuh_sign.png create mode 100644 project/static/img/upload-boss_sign.png create mode 100644 project/static/img/upload-glavbuh_sign.png create mode 100644 project/static/img/upload-logo.png create mode 100644 project/static/img/upload-stamp.png create mode 100644 project/templates/customer/img_load.html create mode 100644 project/templates/customer/img_load.png 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 0000000000000000000000000000000000000000..928965178980c461d54e098b56a080e93411f09d GIT binary patch literal 416 zcmeAS@N?(olHy`uVBq!ia0vp^^MTljg9%6;yE)knNJ*BsMwA5Sr&G7>G%w$)VJUG92czlhUUY#_U10Qy-!aotCE6~( z+;TUse0OZ@^>cS?W-ZH_y!I%Pp*T-`6pg$A sQUydX&xV)01bY_bWwFc48JHOs+$*#HdDDJ3FvuA^UHx3vIVCg!0L5>_djJ3c literal 0 HcmV?d00001 diff --git a/project/static/img/upload-boss_sign.png b/project/static/img/upload-boss_sign.png new file mode 100644 index 0000000000000000000000000000000000000000..928965178980c461d54e098b56a080e93411f09d GIT binary patch literal 416 zcmeAS@N?(olHy`uVBq!ia0vp^^MTljg9%6;yE)knNJ*BsMwA5Sr&G7>G%w$)VJUG92czlhUUY#_U10Qy-!aotCE6~( z+;TUse0OZ@^>cS?W-ZH_y!I%Pp*T-`6pg$A sQUydX&xV)01bY_bWwFc48JHOs+$*#HdDDJ3FvuA^UHx3vIVCg!0L5>_djJ3c literal 0 HcmV?d00001 diff --git a/project/static/img/upload-glavbuh_sign.png b/project/static/img/upload-glavbuh_sign.png new file mode 100644 index 0000000000000000000000000000000000000000..928965178980c461d54e098b56a080e93411f09d GIT binary patch literal 416 zcmeAS@N?(olHy`uVBq!ia0vp^^MTljg9%6;yE)knNJ*BsMwA5Sr&G7>G%w$)VJUG92czlhUUY#_U10Qy-!aotCE6~( z+;TUse0OZ@^>cS?W-ZH_y!I%Pp*T-`6pg$A sQUydX&xV)01bY_bWwFc48JHOs+$*#HdDDJ3FvuA^UHx3vIVCg!0L5>_djJ3c literal 0 HcmV?d00001 diff --git a/project/static/img/upload-logo.png b/project/static/img/upload-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..70797a400bfe2e525ab21148b4547cad125e35a6 GIT binary patch literal 584 zcmeAS@N?(olHy`uVBq!ia0y~yV2lT{D>;~eq+sY)Paq{(;u=vBoS#-wo>-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B_G=e#k?a%sCFefDQU-)rR=?^GBwImj}UGF)K{U`J=5^O02G&;eF~V$=i8 zrEUjyt;@aL_c%htHF8>^%xuncd^M773t#W5oOd|A!c5>wWB%z)G4q#a8VR6iMY6tO zbJy>E=B?99-amV4;_G|)%;!HRlrm?9g-%Vq`EQnmb%DzFytuZta%MF*zU}vQeqy%V z>Vs4nP>47F`qw&zyvqVR&#vT~<9Oqbb>j^m=2r)9GAr_~V3uy2z;>mv*TDlQ;->J) zW;$D4jbTqiw!#_4bVO)8_+OD;$R#iStYI_r0=_%bRZh-d_r5&%)q%jh@iK*l^IHD5 mG0mZ67{UYML5v-%1jE{;Wou>X&%OsH4F*qFKbLh*2~7ZE0?Y~k literal 0 HcmV?d00001 diff --git a/project/static/img/upload-stamp.png b/project/static/img/upload-stamp.png new file mode 100644 index 0000000000000000000000000000000000000000..51a3e7b3dbb4312fc32717566042a11443d5e12b GIT binary patch literal 473 zcmeAS@N?(olHy`uVBq!ia0vp^l_1Q)1SBWTkdy;bk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+7^^*9978H@y}9ey-Q*zAka$;w>1MR~-~a#5L~oc<5>(hO zmbB2f>+ZClFDm&TWp=bDO1ZE2RAD3bYx+Hb4Qaa9)*PK>n!ORki0lS2&PJg!t|fs) zHj8CL8Q0dYPO80=8u{(_-v(mQTo|>8&XTLg8g0KCsiSNr<@75~%=gfP4`maSF zs@b-2GY{u0-m}^(eSG8l-U2*cCuRi~}_VR9)=|6-XExzD7O}!~H zV*Q+Zs{7WxzP5Ay!fqXZ7UnhAJBwO>yJy_*tv@fzVRgyw$t-KJk`1=^%ik4T`1tL5 z{GHox&16ah-`W0Zyf6*|g7BJ{niPI(g{V-_m8r*zmw(90^^Fo)78&qol`;+0M*** Ar2qf` literal 0 HcmV?d00001 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 @@