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.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c536b64ae..087e772e7 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -331,6 +331,8 @@ class GeneralType(Cached, models.Model):
@classmethod
def _get_initial_types(cls, initial, type_pks):
new_vals = []
+ if not initial:
+ return []
for value in initial:
try:
pk = int(value)
@@ -580,10 +582,21 @@ class ImageModel(models.Model):
null=True)
IMAGE_MAX_SIZE = settings.IMAGE_MAX_SIZE
THUMB_MAX_SIZE = settings.THUMB_MAX_SIZE
+ IMAGE_PREFIX = '/'
class Meta:
abstract = True
+ def __init__(self, *args, **kwargs):
+ super(ImageModel, self).__init__(*args, **kwargs)
+ image = self._meta.get_field_by_name("image")[0]
+ IMAGE_PREFIX = self.IMAGE_PREFIX
+ if not IMAGE_PREFIX.endswith('/'):
+ IMAGE_PREFIX += u'/'
+ image.upload_to = IMAGE_PREFIX
+ thumbnail = self._meta.get_field_by_name("thumbnail")[0]
+ thumbnail.upload_to = IMAGE_PREFIX + "thumbs/"
+
def has_changed(self, field):
if not self.pk:
return True
@@ -941,7 +954,8 @@ class IshtarSiteProfile(models.Model, Cached):
homepage = models.TextField(
_(u"Home page"), null=True, blank=True,
help_text=_(u"Homepage of Ishtar - if not defined a default homepage "
- u"will appear. Use the markdown syntax."))
+ u"will appear. Use the markdown syntax. {random_image} "
+ u"can be used to display a random image."))
file_external_id = models.TextField(
_(u"File external id"),
default="{settings__ISHTAR_LOCAL_PREFIX}{year}-{numeric_reference}",
@@ -2200,6 +2214,7 @@ pre_delete.connect(pre_delete_import, sender=Import)
class Organization(Address, Merge, OwnPerms, ValueGetter):
TABLE_COLS = ('name', 'organization_type',)
+ SHOW_URL = 'show-organization'
name = models.CharField(_(u"Name"), max_length=500)
organization_type = models.ForeignKey(OrganizationType,
verbose_name=_(u"Type"))
@@ -2540,7 +2555,7 @@ class Format(GeneralType):
verbose_name_plural = _(u"Formats")
-class Source(models.Model):
+class Source(ImageModel, models.Model):
title = models.CharField(_(u"Title"), max_length=300)
external_id = models.CharField(_(u"External ID"), max_length=12, null=True,
blank=True)
@@ -2575,6 +2590,7 @@ class Source(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