summaryrefslogtreecommitdiffstats
path: root/src/authentic2_cut/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/authentic2_cut/models.py')
-rw-r--r--src/authentic2_cut/models.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/authentic2_cut/models.py b/src/authentic2_cut/models.py
index 53763ac..1cb4835 100644
--- a/src/authentic2_cut/models.py
+++ b/src/authentic2_cut/models.py
@@ -7,9 +7,13 @@ from django.db import models
from django.conf import settings
from django.db.models.query import Q
from django.utils.timezone import now
+from django.core.urlresolvers import reverse
+from django.core.files.storage import default_storage
from django.contrib.contenttypes.fields import GenericForeignKey
+from sorl.thumbnail import get_thumbnail
+
class Journal(models.Model):
timestamp = models.DateTimeField(
@@ -190,6 +194,52 @@ class ValidationRequestAttachment(models.Model):
image = models.ImageField(
verbose_name='contenu')
+ @property
+ def extension(self):
+ return self.image.name.rsplit('.', 1)[-1]
+
+ @property
+ def url(self):
+ return reverse(
+ 'cut-manager-user-validation-attachment',
+ kwargs={
+ 'pk': self.pk,
+ 'filename': self.image.name.rsplit('/', 1)[-1]
+ })
+
+ @property
+ def thumbnail(self):
+ try:
+ thumbnail = get_thumbnail(self.image, '200x200')
+ except Exception:
+ raise
+ return None
+ try:
+ # check file exists and is readable
+ with default_storage.open(thumbnail.name):
+ pass
+ return thumbnail
+ except IOError:
+ pass
+ return None
+
+ @property
+ def thumbnail_image(self):
+ thumbnail = self.thumbnail
+ if thumbnail:
+ return {
+ 'src': reverse(
+ 'cut-manager-user-validation-attachment-thumbnail',
+ kwargs={
+ 'pk': self.pk,
+ 'filename': self.image.name.rsplit('/', 1)[-1]
+ }
+ ),
+ 'height': thumbnail.height,
+ 'width': thumbnail.width,
+ }
+ return {}
+
class Meta:
ordering = ('pk',)
verbose_name = u'Pi├Ęce jointe'