Skip to content

Commit

Permalink
[Google Maps] Prevents height from being a percent.
Browse files Browse the repository at this point in the history
Allowing it to be a percent was definitely a bad idea.
  • Loading branch information
BertrandBordage committed Aug 14, 2012
1 parent 9c221c7 commit a8e70ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions cms/plugins/googlemap/forms.py
@@ -1,9 +1,12 @@
# coding: utf-8

import re
from django.forms.models import ModelForm
from .models import GoogleMap
from django.utils.translation import ugettext_lazy as _

CSS_LENGTH_RE = re.compile(r'^\d+(?:px|%)$')
CSS_WIDTH_RE = re.compile(r'^\d+(?:px|%)$')
CSS_HEIGHT_RE = re.compile(r'^\d+px$')


class GoogleMapForm(ModelForm):
Expand All @@ -15,10 +18,10 @@ def clean(self):
width = cleaned_data.get('width', '')
height = cleaned_data.get('height', '')
if width or height:
error = self.error_class([_('Must be a positive integer '
'followed by px or %.')])
if width and not CSS_LENGTH_RE.match(width):
self._errors['width'] = error
if height and not CSS_LENGTH_RE.match(height):
self._errors['height'] = error
if width and not CSS_WIDTH_RE.match(width):
self._errors['width'] = self.error_class([
_(u'Must be a positive integer followed by “px” or “%”.')])
if height and not CSS_HEIGHT_RE.match(height):
self._errors['height'] = self.error_class([
_(u'Must be a positive integer followed by “px”.')])
return cleaned_data
2 changes: 1 addition & 1 deletion cms/plugins/googlemap/models.py
Expand Up @@ -36,7 +36,7 @@ class GoogleMap(CMSPlugin):
width = models.CharField(_('width'), max_length=6, default='100%',
help_text=_('Plugin width (in pixels or percent).'))
height = models.CharField(_('height'), max_length=6, default='400px',
help_text=_('Plugin height (in pixels or percent).'))
help_text=_('Plugin height (in pixels).'))

def __unicode__(self):
return u"%s (%s, %s %s)" % (self.get_title(), self.address,
Expand Down

0 comments on commit a8e70ff

Please sign in to comment.