From 8d9acf8d494a312cf9063b0495d0235b2d7fa858 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 3 Mar 2016 16:24:50 +0100 Subject: [PATCH] Reduce methods. --- base_multi_image/models/image.py | 12 ------------ base_multi_image/models/owner.py | 11 ++++------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/base_multi_image/models/image.py b/base_multi_image/models/image.py index 9a24cdf24..f402ad38f 100644 --- a/base_multi_image/models/image.py +++ b/base_multi_image/models/image.py @@ -127,18 +127,6 @@ class Image(models.Model): "image_small": False} s.update(vals) - @api.multi - def _check_filestore(self): - """check if the filestore is created, and do it otherwise.""" - for s in self: - dir_path = os.path.dirname(s.path) - try: - if not os.path.exists(dir_path): - os.makedirs(dir_path) - except OSError as e: - raise exceptions.Warning( - _('The image filestore cannot be created, %s') % e) - @api.model def _make_name_pretty(self, name): return name.replace('_', ' ').capitalize() diff --git a/base_multi_image/models/owner.py b/base_multi_image/models/owner.py index 883eb6d4d..1f85bc03c 100644 --- a/base_multi_image/models/owner.py +++ b/base_multi_image/models/owner.py @@ -41,13 +41,10 @@ class Owner(models.AbstractModel): had one image per record. """ for s in self: - s.image_main = False - s.image_main_medium = False - s.image_main_small = False - if s.image_ids: - s.image_main = s.image_ids[0].image_main - s.image_main_medium = s.image_ids[0].image_medium - s.image_main_small = s.image_ids[0].image_small + first = s.image_ids[:1] + s.image_main = first.image_main + s.image_main_medium = first.image_medium + s.image_main_small = first.image_small @api.multi def _set_multi_image(self, image=False, name=False):