From 5dd9c5b9b9af7cb30622cbbbf536d65bb91e181a Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Sat, 4 Nov 2017 15:40:07 +0300 Subject: [PATCH] add decorator for check active profile for edit docs, some fixes in save profile model with checking existing file img --- Makefile | 22 +++++++++++++++++++++- src/customer/models.py | 8 ++++---- src/customer/utils.py | 2 +- src/docs/views/base_views.py | 1 + templates/docs/parts/doc_actions2nd.html | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f5cddea..bc3e12d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,24 @@ -.PHONY: all help build virtualenv requirements-local loaddata run migrate shell collectstatic clean worker qa flush update-develop upgrade-develop update-develop upgrade-develop update-stage upgrade-stage +.PHONY: + all + help + build + virtualenv + requirements-local + loaddata + run + migrate + shell + collectstatic + clean + worker + qa + flush + update-develop + upgrade-develop + update-develop + upgrade-develop + update-stage + upgrade-stage # target: all - Default target. Does nothing. all: diff --git a/src/customer/models.py b/src/customer/models.py index 3df4c3c..cb14194 100644 --- a/src/customer/models.py +++ b/src/customer/models.py @@ -222,16 +222,16 @@ class UserProfile(models.Model): super(UserProfile, self).save(*args, **kwargs) - if self.boss_sign: + if self.boss_sign and os.path.exists(self.boss_sign.path): process_img(self.boss_sign, size=BOSS_SIGN_IMG_SIZE) - if self.glavbuh_sign: + if self.glavbuh_sign and os.path.exists(self.glavbuh_sign.path): process_img(self.glavbuh_sign, size=GLAVBUH_SIGN_IMG_SIZE) - if self.stamp: + if self.stamp and os.path.exists(self.stamp.path): process_img(self.stamp, size=STAMP_IMG_SIZE) - if self.logo: + if self.logo and os.path.exists(self.logo.path): process_img(self.logo, size=LOGO_SIZE) def is_ip(self): diff --git a/src/customer/utils.py b/src/customer/utils.py index ed6e0ec..df13279 100644 --- a/src/customer/utils.py +++ b/src/customer/utils.py @@ -28,7 +28,7 @@ def check_one_profile(profile, now, manual=False): profile.active = True else: profile.active = False - profile.save() + profile.save(update_fields=['active']) user_email = profile.users.get().email diff --git a/src/docs/views/base_views.py b/src/docs/views/base_views.py index 6ab0f49..76e0677 100644 --- a/src/docs/views/base_views.py +++ b/src/docs/views/base_views.py @@ -772,6 +772,7 @@ class BaseItemsViews(BaseViews): self.set_item_formset_class(extra_count=len(kwargs['initial_items'])) return self.add(self.request, *args, **kwargs) + @method_decorator(license_required) @method_decorator(csrf_protect) def edit(self, *args, **kwargs): """Редактировать документ.""" diff --git a/templates/docs/parts/doc_actions2nd.html b/templates/docs/parts/doc_actions2nd.html index 7fb90e0..1874b41 100644 --- a/templates/docs/parts/doc_actions2nd.html +++ b/templates/docs/parts/doc_actions2nd.html @@ -6,6 +6,7 @@ Отправить по e-mail + Редактировать документ Удалить документ