def is_valid_logo(value): """Check if the image is a valid logo: * Logos should have a wide aspect ratio, not a square icon * Logos should be no wider than 600px, and no taller than 60px """ if not value: return True filename, data = b64decode_file(value) width, height = Image.open(StringIO(data)).size if width <= height: raise Invalid(_(u'Image should have a wide aspect ratio.')) if width > 600 or height > 60: raise Invalid( _(u'Image should be no wider than 600px, and no taller than 60px.') ) return True
class IAMPSettings(model.Schema): """Schema for the control panel form.""" form.widget('publisher_logo', NamedImageFieldWidget) publisher_logo = schema.ASCII( title=_(u'Publisher Logo'), description=_( u'The logo of the publisher. Should have a wide aspect ratio, ' u'and should be no wider than 600px, and no taller than 60px.'), required=False, constraint=is_valid_logo, ) form.widget('amp_analytics', rows=15) amp_analytics = schema.Text( title=_(u'AMP Analytics'), description=_( u'The value (in JSON-LD format) of the "amp-analytics" element ' u'that will be used to measure activity on AMP documents.'), required=False, default=u'', constraint=is_json, )
class IAMPSettings(model.Schema): """Schema for the control panel form.""" form.widget('publisher_logo', NamedImageFieldWidget) publisher_logo = schema.ASCII( title=_(u'Publisher Logo'), description=_( u'The logo of the publisher. Should have a wide aspect ratio, ' u'and should be no wider than 600px, and no taller than 60px.'), required=False, constraint=is_valid_logo, ) # XXX: placeholder attribute is not working form.widget('amp_sticky_ad', rows=15, placeholder=AMP_STICKY_AD_PLACEHOLDER) amp_sticky_ad = schema.Text( title=_(u'AMP Sticky Ad'), description= _(u'Adds support for ad units that always take a fixed place in the viewport. ' u'Fill with the "amp-ad" element that will be used as a direct child of "amp-sticky-ad". ' u'See <a href="https://ampbyexample.com/components/amp-sticky-ad/">amp-sticky-ad</a> for examples on how to implement this feature.' ), required=False, default=u'', constraint=is_xml, ) form.widget('amp_analytics', rows=15) amp_analytics = schema.Text( title=_(u'AMP Analytics'), description= _(u'The "amp-analytics" elements that will be used to measure activity on AMP documents. ' u'See <a href="https://developers.google.com/analytics/devguides/collection/amp-analytics/">' u'Adding Analytics to your AMP pages</a> for examples on how to implement this feature.' ), required=False, default=u'', constraint=is_xml, )
class AMPSettingsEditForm(controlpanel.RegistryEditForm): """Control panel edit form.""" schema = IAMPSettings label = _(u'Accelerated Mobile Pages') description = _(u'Settings for AMP integration.')