-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
92 lines (77 loc) · 3.1 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from django.db import models
from cms.models import CMSPlugin
from filer.fields.image import FilerImageField
from filer.fields.file import FilerFileField
class MediaItem(models.Model):
image = FilerImageField(
null=True, blank=True,
default=None, verbose_name='image',
related_name='image item')
video = FilerFileField(
verbose_name='movie file',
help_text='use .flv file or h264 encoded video file',
blank=True, null=True)
video_url = models.CharField(
'movie url',
max_length=255,
help_text='vimeo or youtube video url. \
Example: http://www.youtube.com/watch?v=YFa59lK-kpo',
blank=True, null=True)
image_url = models.CharField(
'image url',
max_length=255,
help_text='vimeo or youtube video url. \
Example: http://www.youtube.com/watch?v=YFa59lK-kpo',
blank=True, null=True)
width = models.IntegerField('Width', blank=True, null=True)
height = models.IntegerField('Height', blank=True, null=True)
def clean(self):
from django.core.exceptions import ValidationError
if (self.image and (self.video or self.video_url or self.image_url)) \
or (self.video and (self.image or self.video_url or self.image_url)) \
or (self.image_url and (self.image or self.video_url or self.video)) \
or (self.video_url and (self.video or self.image or self.image_url)):
raise ValidationError(
'you must choose only an image or a video or a video_url')
if not (self.image or self.video_url or self.video or self.image_url):
raise ValidationError(
'You must provide at least one media')
if self.video:
raise ValidationError(
'Video Files is not yet implemented')
class Meta:
verbose_name = "Media Item"
def __unicode__(self):
if self.image:
return u'image > %s' % self.image
if self.image_url:
return u'image > %s' % self.image_url
elif self.video_url:
return u'video > %s' % self.video_url
elif self.video:
return u'video > %s' % self.video
else:
return u'Media Item: Empty!'
class MediaViewer(CMSPlugin):
SLIDE_TYPE = (
('car', 'carousel'),
('sbox', 'shadowbox'),
)
title = models.CharField('Title', max_length=255, blank=True, null=True)
slide_type = models.CharField(
max_length=5, choices=SLIDE_TYPE, default='car')
medias = models.ManyToManyField(MediaItem)
width = models.IntegerField('Thumbnail Width', blank=True, null=True)
height = models.IntegerField('Thumbnail Height', blank=True, null=True)
def clean(self):
#from django.core.exceptions import ValidationError
#if not self.medias:
# raise ValidationError(
# 'You must provide medias')
pass
class Meta:
verbose_name = "Media Viewer"
def copy_relations(self, oldinstance):
self.medias = oldinstance.medias.all()
def __unicode__(self):
return u'Media Viewer'