diff options
-rw-r--r-- | archaeological_finds/tests.py | 12 | ||||
-rw-r--r-- | archaeological_warehouse/templates/ishtar/sheet_container.html | 5 | ||||
-rw-r--r-- | ishtar_common/models.py | 41 |
3 files changed, 24 insertions, 34 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 2360d4ca6..2e3026f6e 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -1202,11 +1202,15 @@ class FindSearchTest(FindInit, TestCase, SearchText): self.assertEqual(res['recordsTotal'], 0) # add an image to the first find - image = Document.objects.create(title="Image!") - img = settings.ROOT_PATH + \ + document = Document.objects.create(title="Image!") + image_path = settings.ROOT_PATH + \ '../ishtar_common/static/media/images/ishtar-bg.jpg' - image.image.save('ishtar-bg.jpg', File(open(img))) - self.finds[0].documents.add(image) + document.image = SimpleUploadedFile( + name='ishtar-bg.jpg', content=open(image_path, 'rb').read(), + content_type='image/jpeg') + document.save() + + self.finds[0].documents.add(document) self.finds[0].save() response = c.get(reverse('get-find'), search) self.assertEqual(response.status_code, 200) diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index a7aa3a512..5116820f0 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -117,7 +117,10 @@ {% endif %} {% else %} - <em>{% trans "Empty" %}</em> + <div class="alert alert-info"> + <i class="fa fa-exclamation-triangle"></i> + <em>{% trans "Empty" %}</em> + </div> {% endif %} </div> 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)): |