summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-28 19:20:33 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-28 19:20:33 +0200
commite93ae57d3c88662a6f9ec83cfad90fb17ea4a98e (patch)
treea00e1e40596cd89bf1a488c8332a55af3a593d96 /ishtar_common
parentbe885665de124f52974dd9534a480149304650de (diff)
downloadIshtar-e93ae57d3c88662a6f9ec83cfad90fb17ea4a98e.tar.bz2
Ishtar-e93ae57d3c88662a6f9ec83cfad90fb17ea4a98e.zip
Change all upload directories
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py41
-rw-r--r--ishtar_common/models_imports.py10
2 files changed, 31 insertions, 20 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 89b35d445..0c06f0b4d 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -765,10 +765,14 @@ class ItemKey(models.Model):
return self.key
+def get_image_path(instance, filename):
+ return instance._get_image_path(filename)
+
+
class ImageModel(models.Model):
- image = models.ImageField(upload_to="upload/", blank=True, null=True,
+ image = models.ImageField(upload_to=get_image_path, blank=True, null=True,
max_length=255)
- thumbnail = models.ImageField(upload_to='upload/thumbs/', blank=True,
+ thumbnail = models.ImageField(upload_to=get_image_path, blank=True,
null=True, max_length=255)
IMAGE_MAX_SIZE = settings.IMAGE_MAX_SIZE
THUMB_MAX_SIZE = settings.THUMB_MAX_SIZE
@@ -777,15 +781,11 @@ class ImageModel(models.Model):
class Meta:
abstract = True
- def __init__(self, *args, **kwargs):
- super(ImageModel, self).__init__(*args, **kwargs)
- image = self._meta.get_field("image")
- IMAGE_PREFIX = self.IMAGE_PREFIX
- if not IMAGE_PREFIX.endswith('/'):
- IMAGE_PREFIX += u'/'
- image.upload_to = IMAGE_PREFIX
- thumbnail = self._meta.get_field("thumbnail")
- thumbnail.upload_to = IMAGE_PREFIX + "thumbs/"
+ def _get_image_path(self, filename):
+ return u"{}/{}".format(self._get_base_image_path(), filename)
+
+ def _get_base_image_path(self):
+ return u"upload"
def has_changed(self, field):
if not self.pk:
@@ -832,8 +832,12 @@ class ImageModel(models.Model):
pass
# save the thumbnail
+ splited = filename.split('.')
+ thumb_filename = u"{}-thumb.{}".format(
+ u".".join(splited[:-1]), splited[-1]
+ )
self.thumbnail.save(
- '_%s' % filename,
+ thumb_filename,
self.create_thumb(image, self.THUMB_MAX_SIZE),
save=False)
except IOError:
@@ -1570,7 +1574,8 @@ class DocumentTemplate(models.Model):
name = models.CharField(_(u"Name"), max_length=100)
slug = models.SlugField(_(u"Slug"), blank=True, null=True, max_length=100,
unique=True)
- template = models.FileField(_(u"Template"), upload_to="upload/templates/")
+ template = models.FileField(
+ _(u"Template"), upload_to="templates/%Y/")
associated_object_name = models.CharField(
_(u"Associated object"), max_length=100, choices=CLASSNAMES)
available = models.BooleanField(_(u"Available"), default=True)
@@ -1621,7 +1626,7 @@ class DocumentTemplate(models.Model):
from old.ooo_replace import ooo_replace
from archaeological_operations.models import AdministrativeAct
- old_dir = settings.MEDIA_ROOT + "/upload/templates/v1/"
+ old_dir = settings.MEDIA_ROOT + "/templates/v1/"
if not os.path.exists(old_dir):
os.makedirs(old_dir)
shutil.copy(settings.MEDIA_ROOT + self.template.name, old_dir)
@@ -2372,7 +2377,6 @@ class Source(OwnPerms, ImageModel, models.Model):
duplicate = models.BooleanField(_(u"Has a duplicate"), default=False)
TABLE_COLS = ['title', 'source_type', 'authors', 'associated_url']
COL_LINK = ['associated_url']
- IMAGE_PREFIX = 'sources'
class Meta:
abstract = True
@@ -2380,6 +2384,13 @@ class Source(OwnPerms, ImageModel, models.Model):
def __unicode__(self):
return self.title
+ def get_associated_operation(self):
+ raise NotImplementedError()
+
+ def _get_base_image_path(self):
+ base = self.owner._get_base_image_path()
+ return u"{}/sources".format(base)
+
@property
def associated_filename(self):
values = [unicode(getattr(self, attr))
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index cfc8857de..d638c76f1 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -724,21 +724,21 @@ class Import(models.Model):
blank=True, null=True)
importer_type = models.ForeignKey(ImporterType)
imported_file = models.FileField(
- _(u"Imported file"), upload_to="upload/imports/", max_length=220)
+ _(u"Imported file"), upload_to="upload/imports/%Y/%m/", max_length=220)
imported_images = models.FileField(
- _(u"Associated images (zip file)"), upload_to="upload/imports/",
+ _(u"Associated images (zip file)"), upload_to="upload/imports/%Y/%m/",
blank=True, null=True, max_length=220)
encoding = models.CharField(_(u"Encoding"), choices=ENCODINGS,
default=u'utf-8', max_length=15)
skip_lines = models.IntegerField(_(u"Skip lines"), default=1)
error_file = models.FileField(_(u"Error file"),
- upload_to="upload/imports/",
+ upload_to="upload/imports/%Y/%m/",
blank=True, null=True, max_length=255)
result_file = models.FileField(_(u"Result file"),
- upload_to="upload/imports/",
+ upload_to="upload/imports/%Y/%m/",
blank=True, null=True, max_length=255)
match_file = models.FileField(_(u"Match file"),
- upload_to="upload/imports/",
+ upload_to="upload/imports/%Y/%m/",
blank=True, null=True, max_length=255)
state = models.CharField(_(u"State"), max_length=2, choices=IMPORT_STATE,
default=u'C')