forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
25 lines (20 loc) · 759 Bytes
/
models.py
File metadata and controls
25 lines (20 loc) · 759 Bytes
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
import re
from django.db import models
from django.utils.translation import ugettext_lazy as _
from cms.models import CMSPlugin
from os.path import basename
class Flash(CMSPlugin):
file = models.FileField(_('file'), upload_to=CMSPlugin.get_media_path, help_text=_('use swf file'))
width = models.CharField(_('width'), max_length=6)
height = models.CharField(_('height'), max_length=6)
def get_height(self):
return fix_unit(self.height)
def get_width(self):
return fix_unit(self.width)
def __unicode__(self):
return u"%s" % basename(self.file.path)
def fix_unit(value):
if not re.match(r'.*[0-9]$', value):
# no unit, add px
return value + "px"
return value