Gitlab CSE Unil

Commit 8d82fff6 authored by Julien Furrer's avatar Julien Furrer
Browse files

Some preparation for migration to 1.7

parent af42d9d9
......@@ -48,7 +48,7 @@ class AOSchema(BaseSchema):
verbose_name = "Annotable Object Schema"
verbose_name_plural = "Annotable Object Schemata"
AOSchema._meta.get_field_by_name('datatype')[0]._choices += (('image', u'image file'), )
# AOSchema._meta.get_field_by_name('datatype')[0]._choices += (('image', u'image file'), )
class AOChoice(BaseChoice):
......@@ -71,6 +71,20 @@ class AOAttribute(BaseAttribute):
verbose_name_plural = "Annotable Object Attributes"
def get_image_path(instance, filename):
now = timezone.now()
instance.set_uuid()
file_ext = os.path.splitext(filename)[1]
filename = instance.uuid + file_ext
return os.path.join(
AO_IMAGES_PATH,
now.strftime("%Y"),
now.strftime("%m"),
now.strftime("%d"),
filename
)
class AnObj(BaseEntity):
"""
Annotable Object
......@@ -87,18 +101,6 @@ class AnObj(BaseEntity):
members = models.ManyToManyField(User, verbose_name=_("members"), through='AnObjMembership',
related_name='shared_anobjs', blank=True, null=True)
def get_image_path(self, filename):
now = timezone.now()
self._set_uuid()
file_ext = os.path.splitext(filename)[1]
filename = self.uuid + file_ext
return os.path.join(
AO_IMAGES_PATH,
now.strftime("%Y"),
now.strftime("%m"),
now.strftime("%d"),
filename
)
image = models.ImageField(upload_to=get_image_path, verbose_name=_("image"), blank=True, null=True)
image_url = models.CharField(max_length=512, verbose_name=_("image url"), blank=True, null=True, default="")
......@@ -122,7 +124,7 @@ class AnObj(BaseEntity):
def save(self, *args, **kwargs):
if not self.uuid:
self._set_uuid(no_save=True)
self.set_uuid(no_save=True)
super(AnObj, self).save(*args, **kwargs)
......@@ -130,7 +132,7 @@ class AnObj(BaseEntity):
# self._thumb_url = self._create_thumbnail()
# self.save()
def _set_uuid(self, no_save=False):
def set_uuid(self, no_save=False):
if not self.uuid:
# Using the random node initialized at module level
# to avoid compromising network address
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment