diff options
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/chimere/models.py b/chimere/models.py index f33772c..5282fca 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -30,6 +30,7 @@ from django.contrib.gis.db import models from django.contrib.gis.gdal import SpatialReference from django.contrib import admin from django.core.files import File +from django.core.exceptions import ValidationError from django import forms from django.utils.translation import ugettext_lazy as _ @@ -351,18 +352,54 @@ class Marker(GeographicItem): self.default_category.pk) return settings.BASE_URL + 'ty/' + TinyUrl.getUrnByParameters(parameters) +class MultimediaType(models.Model): + MEDIA_TYPES = (('A', _(u"Audio")), + ('V', _(u"Video")), + ('I', _(u"Image"))) + media_type = models.CharField(_(u"Media type"), max_length=1, + choices=MEDIA_TYPES) + name = models.CharField(_(u"Name"), max_length=150) + mime_type = models.CharField(_(u"Mime type"), max_length=50) + available = models.BooleanField(_(u"Available"), default=True) + + def __unicode__(self): + return self.name + class MultimediaFile(models.Model): name = models.CharField(_(u"Name"), max_length=150, blank=True, null=True) - url = models.CharField(_(u"Url"), max_length=200) - file_type = models.CharField(_(u"File type"), max_length=6) + url = models.CharField(_(u"Url"), max_length=200, blank=True, null=True) + iframe = models.CharField(_(u"Iframe"), max_length=1000, blank=True, + null=True) + order = models.IntegerField(_(u"Order"), default=1) + multimedia_type = models.ForeignKey(MultimediaType, blank=True, + null=True) + + def __unicode__(self): + return self.name + + def clean(self): + if self.url and not self.multimedia_type: + raise ValidationError(_(u"Multimedia type is mandatory if you "\ + u"provide an url.")) + if not self.url and not self.iframe: + raise ValidationError(_(u"You must provide at least provide an "\ + u" url or an iframe.")) + if self.url and self.iframe: + raise ValidationError(_(u"You must provide an url OR an"\ + u"iframe.")) + class PictureFile(models.Model): - miniature = models.BooleanField(u"Miniature") + miniature = models.BooleanField(_(u"Miniature")) name = models.CharField(_(u"Name"), max_length=150, blank=True, null=True) picture = models.ImageField(_(u"Image"), upload_to='upload', height_field='height', width_field='width') height = models.IntegerField(_(u"Height")) width = models.IntegerField(_(u"Width")) + order = models.IntegerField(_(u"Order"), default=1) + + def __unicode__(self): + return self.name class RouteFile(models.Model): name = models.CharField(_(u"Name"), max_length=150) |