summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py41
1 files changed, 12 insertions, 29 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a6cfcf697..24d88edde 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1184,7 +1184,9 @@ class ItemKey(models.Model):
def get_image_path(instance, filename):
# when using migrations instance is not a real ImageModel instance
if not hasattr(instance, '_get_image_path'):
- return "upload/{}".format(filename)
+ n = datetime.datetime.now()
+ return "upload/{}/{:02d}/{:02d}/{}".format(
+ n.year, n.month, n.day, filename)
return instance._get_image_path(filename)
@@ -1193,7 +1195,8 @@ class ImageContainerModel(object):
return "{}/{}".format(self._get_base_image_path(), filename)
def _get_base_image_path(self):
- return "upload"
+ n = datetime.datetime.now()
+ return "upload/{}/{:02d}/{:02d}".format(n.year, n.month, n.day)
class ImageModel(models.Model, ImageContainerModel):
@@ -5706,9 +5709,12 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel,
yield item._get_base_image_path()
def _get_base_image_path(self):
+ print(5637)
for path in self._get_base_image_paths():
- return path
- return "upload"
+ if path:
+ return path
+ n = datetime.datetime.now()
+ return "upload/{}/{:02d}/{:02d}".format(n.year, n.month, n.day)
def _get_available_filename(self, path, test_link=None):
"""
@@ -5756,9 +5762,8 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel,
"""
if getattr(self, "_no_move", False):
return
- reference_path = None
- initial_path = self.image.path
- filename = os.path.basename(initial_path)
+ reference_path = self.image.path
+ filename = os.path.basename(reference_path)
links = []
for related_model in self.RELATED_MODELS:
@@ -5767,28 +5772,6 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel,
item = q.all()[0]
base_path = item._get_base_image_path()
new_path = base_path + "/" + filename
- if not reference_path:
- reference_path = settings.MEDIA_ROOT + new_path
- # correct path
- if initial_path == reference_path:
- continue
- if not os.path.exists(os.path.dirname(reference_path)):
- os.makedirs(os.path.dirname(reference_path))
-
- reference_path = self._get_available_filename(
- reference_path)
- try:
- os.rename(initial_path, reference_path)
- os.rename(self.thumbnail.path,
- self._get_thumb_name(reference_path))
- self.image.name = reference_path[
- len(settings.MEDIA_ROOT):]
- self._no_move = True
- self.save(no_path_change=True)
- except OSError:
- # file probably not on HDD - will be cleaned
- pass
- continue
# create a link
new_path = settings.MEDIA_ROOT + new_path
if not os.path.exists(os.path.dirname(new_path)):