def __init__(self, model=None, admin_site=None): partial_fields = ( PartialFormField('grid', widgets.Select(choices=self.GRID_CHOICES), label=_('Column Grid'), initial='grid_4', help_text=_("Grid in column units.")), PartialFormField( 'prefix', widgets.Select(choices=self.PREFIX_CHOICES), label=_('Prefix'), ), PartialFormField( 'suffix', widgets.Select(choices=self.SUFFIX_CHOICES), label=_('Suffix'), ), PartialFormField( 'options', widgets.CheckboxSelectMultiple(choices=self.OPTION_CHOICES), label=_('Options'), ), PartialFormField('inline_styles', MultipleInlineStylesWidget( ['min-height', 'margin-top', 'margin-bottom']), label=_('Inline Styles'), help_text=_('Minimum height for this column.')), ) super(Grid960BasePlugin, self).__init__(model, admin_site, partial_fields=partial_fields)
class SimpleWrapperPlugin(BootstrapPluginBase): name = _("Simple Wrapper") parent_classes = ['BootstrapColumnPlugin'] generic_child_classes = settings.CMS_CASCADE_LEAF_PLUGINS CLASS_CHOICES = ((('', _('Unstyled')), ) + tuple((cls, cls.title()) for cls in ( 'thumbnail', 'jumbotron', ))) partial_fields = ( PartialFormField( 'css_class', widgets.Select(choices=CLASS_CHOICES), label=_('Extra Bootstrap Classes'), help_text=_( 'Main Bootstrap CSS class to be added to this element.')), PartialFormField( 'inline_styles', MultipleInlineStylesWidget(['min-height']), label=_('Inline Styles'), help_text=_('Margins and minimum height for container.')), ) @classmethod def get_identifier(cls, obj): name = obj.context.get('css_class').title() or cls.CLASS_CHOICES[0][1] return name.title() @classmethod def get_css_classes(cls, obj): css_classes = super(SimpleWrapperPlugin, cls).get_css_classes(obj) css_class = obj.context.get('css_class') if css_class: css_classes.append(css_class) return css_classes
class MagellanArrivalElementPlugin(FoundationPluginBase): name = _("Magellan Arrival Element") parent_classes = ('MagellanArrivalPlugin', ) allow_children = False render_template = 'cms/foundation/magellan_arrival_element.html' partial_fields = [ PartialFormField( 'name', widgets.TextInput(), label="Name", help_text="Display name of this element", ), PartialFormField( 'destination_name', widgets.TextInput(), label="Name", help_text="Name of the destination where this element will jump to.\ Needs to be lowercase with only a-z and 0-9", ), ] @classmethod def get_identifier(cls, obj): if obj.context is not None: return obj.context.get('name') else: return u''
def __init__(self, model=None, admin_site=None): partial_fields = ( PartialFormField('options', widgets.CheckboxSelectMultiple(choices=(('clearfix', _('Clearfix')),)), label=_('Options'), ), PartialFormField('-num-children-', # temporary field, not stored in the database widgets.Select(choices=tuple((i, ungettext_lazy('{0} column', '{0} columns', i).format(i)) for i in self.CONTAINER_NUM_COLUMNS)), label=_('Number of Columns'), help_text=_('Number of columns to be created with this row.') ), ) super(Container960BasePlugin, self).__init__(model, admin_site, partial_fields)
class ButtonWrapperPlugin(BootstrapPluginBase): name = _("Button wrapper") parent_classes = ['BootstrapColumnPlugin'] render_template = 'cms/plugins/naked.html' generic_child_classes = ('LinkPlugin', ) tag_type = None default_css_class = 'btn' default_css_attributes = ( 'button-type', 'button-size', 'button-options', ) partial_fields = ( PartialFormField( 'button-type', widgets.RadioSelect( choices=((k, v) for k, v in ButtonTypeRenderer.BUTTON_TYPES.items()), renderer=ButtonTypeRenderer), label=_('Button Type'), initial='btn-default'), PartialFormField( 'button-size', widgets.RadioSelect( choices=((k, v) for k, v in ButtonSizeRenderer.BUTTON_SIZES.items()), renderer=ButtonSizeRenderer), label=_('Button Size'), initial=''), PartialFormField( 'button-options', widgets.CheckboxSelectMultiple(choices=( ('btn-block', _('Block level')), ('disabled', _('Disabled')), )), label=_('Button Options'), ), PartialFormField('inline_styles', MultipleInlineStylesWidget([ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ]), label=_('Inline Styles'), help_text=_('Margins for this button wrapper.')), ) @classmethod def get_identifier(cls, obj): return ButtonTypeRenderer.BUTTON_TYPES.get( obj.context.get('button-type'), '')
class BootstrapContainerPlugin(BootstrapPluginBase): name = _("Container") default_css_class = 'container' require_parent = False CONTEXT_WIDGET_CHOICES = ( ('lg', _('Large (>1200px)')), ('md', _('Medium (>992px)')), ('sm', _('Small (>768px)')), ('xs', _('Tiny (<768px)')), ) partial_fields = (PartialFormField( 'breakpoint', widgets.RadioSelect(choices=CONTEXT_WIDGET_CHOICES, renderer=ContainerRadioFieldRenderer), label=_('Display Breakpoint'), initial=settings.CMS_CASCADE_BOOTSTRAP3_BREAKPOINT, help_text=_("Narrowest display for Bootstrap's grid system.")), ) @classmethod def get_identifier(cls, obj): try: texts = [ d for c, d in cls.CONTEXT_WIDGET_CHOICES if c == obj.context.get('breakpoint') ] return _('Narrowest grid: {0}').format(texts[0].lower()) except (TypeError, KeyError, ValueError): return ''
class BootstrapRowPlugin(BootstrapPluginBase): name = _("Row") default_css_class = 'row' parent_classes = ['BootstrapContainerPlugin', 'BootstrapColumnPlugin'] ROW_NUM_COLUMNS = ( 1, 2, 3, 4, 6, 12, ) partial_fields = ( PartialFormField( '-num-children-', # temporary field, not stored in the database widgets.Select(choices=tuple( (i, ungettext_lazy('{0} column', '{0} columns', i).format(i)) for i in ROW_NUM_COLUMNS)), label=_('Number of Columns'), help_text=_('Number of columns to be created with this row.')), PartialFormField('inline_styles', MultipleInlineStylesWidget(['min-height']), label=_('Inline Styles'), help_text=_('Minimum height for this row.')), ) @classmethod def get_identifier(cls, obj): num_cols = obj.get_children().count() return ungettext_lazy('with {0} column', 'with {0} columns', num_cols).format(num_cols) def save_model(self, request, obj, form, change): wanted_children = int(obj.context['-num-children-']) super(BootstrapRowPlugin, self).save_model(request, obj, form, change) child_context = { 'xs-column-width': 'col-xs-{0}'.format(12 // wanted_children) } self.extend_children(obj, wanted_children, BootstrapColumnPlugin, child_context=child_context)
class HorizontalRulePlugin(BootstrapPluginBase): name = _("Horizontal Rule") parent_classes = ['BootstrapContainerPlugin', 'BootstrapColumnPlugin'] allow_children = False tag_type = 'hr' render_template = 'cms/plugins/single.html' partial_fields = (PartialFormField( 'inline_styles', MultipleInlineStylesWidget(['margin-top', 'margin-bottom']), label=_('Inline Styles'), help_text=_('Margins for this horizontal rule.')), )
class HorizontalRulePlugin(FoundationPluginBase): name = _("Horizontal Rule") allow_children = False require_parent = False tag_type = 'hr' render_template = 'cms/plugins/single.html' partial_fields = (PartialFormField( 'inline_styles', MultipleInlineStylesWidget(['margin-top', 'margin-bottom']), label=_('Inline Styles'), help_text=_('Margins for this horizontal rule.')), )
class CarouselPlugin(BootstrapPluginBase): name = _("Carousel") default_css_class = 'carousel' default_css_attributes = ('options', ) parent_classes = ['BootstrapColumnPlugin'] render_template = os.path.join('cms', framework, 'carousel.html') default_inline_styles = {'overflow': 'hidden'} default_data_options = {'ride': 'carousel'} partial_fields = ( PartialFormField( '-num-children-', # temporary field, not stored in the database NumberInputWidget(attrs={'size': '2'}), label=_('Number of Slides'), help_text=_('Number of slides for this carousel.')), PartialFormField( 'data_options', MultipleTextInputWidget(['interval', 'pause']), label=_('Carousel Options'), help_text=_('Adjust interval and pause for the carousel.')), PartialFormField( 'options', widgets.CheckboxSelectMultiple(choices=(('slide', _('Animate')), )), label=_('Options'), ), PartialFormField('inline_styles', MultipleInlineStylesWidget(['height']), label=_('Inline Styles'), help_text=_('Height of carousel.')), ) @classmethod def get_identifier(cls, obj): num_cols = obj.get_children().count() return ungettext_lazy('with {0} slide', 'with {0} slides', num_cols).format(num_cols) def save_model(self, request, obj, form, change): wanted_children = int(obj.context['-num-children-']) super(CarouselPlugin, self).save_model(request, obj, form, change) self.extend_children(obj, wanted_children, SlidePlugin)
class PanelPlugin(BootstrapPluginBase): name = _("Panel") default_css_class = 'panel-body' parent_classes = ['PanelGroupPlugin'] require_parent = True generic_child_classes = ('TextPlugin', ) partial_fields = (PartialFormField('panel_title', widgets.TextInput(attrs={'size': 150}), label=_('Panel Title')), ) @classmethod def get_identifier(cls, obj): value = obj.context.get('panel_title') if value: return unicode(Truncator(value).words(3, truncate=' ...')) return u''
class AccordionElementPlugin(FoundationPluginBase): name = _("Accordion element") require_parent = True parent_classes = ('AccordionWrapperPlugin', ) partial_fields = [ PartialFormField( 'heading', widgets.TextInput(), label="Heading for this element", ), ] allow_children = True render_template = 'cms/foundation/accordion_element.html' @classmethod def get_identifier(cls, obj): if obj.context is not None: return obj.context.get('heading') else: return u''
class AccordionWrapperPlugin(FoundationPluginBase): name = _("Accordion wrapper") require_parent = False render_template = 'cms/foundation/accordion_wrapper.html' generic_child_classes = ('AccordionElementPlugin', ) partial_fields = [ PartialFormField( 'name', widgets.TextInput(), label="Name for this wrapper", help_text= "This will be displayed in structure overview to easier find this element. Not displayed on page.", ), ] @classmethod def get_identifier(cls, obj): if obj.context is not None: return obj.context.get('name') else: return u''
class PanelGroupPlugin(BootstrapPluginBase): name = _("Panel Group") default_css_class = 'panel-group' parent_classes = ['BootstrapColumnPlugin'] require_parent = True render_template = 'cms/bootstrap3/collapse.html' partial_fields = ( PartialFormField('-num-children-', # temporary field, not stored in the database NumberInputWidget(attrs={ 'style': 'width: 30px;' }), label=_('Number of Panels'), help_text=_('Number of panels for this panel group.') ), ) @classmethod def get_identifier(cls, obj): num_cols = obj.get_children().count() return ungettext_lazy('with {0} panel', 'with {0} panels', num_cols).format(num_cols) def save_model(self, request, obj, form, change): wanted_children = int(obj.context['-num-children-']) super(PanelGroupPlugin, self).save_model(request, obj, form, change) self.extend_children(obj, wanted_children, PanelPlugin)
class MagellanDestinationPlugin(FoundationPluginBase): name = _("Magellan Destination") allow_children = False require_parent = False partial_fields = [ PartialFormField( 'name', widgets.TextInput(), label="Name", help_text= "Name of this destination. Needs to be lowercase with only a-z and 0-9", ), ] allow_children = True render_template = 'cms/foundation/magellan_destination.html' @classmethod def get_identifier(cls, obj): if obj.context is not None: return obj.context.get('name') else: return u''
def get_form(self, request, obj=None, **kwargs): def get_column_width(prefix): # full_context from closure column_width = full_context.get( '{0}-column-width'.format(prefix)) or '12' return int( string.replace(column_width, 'col-{0}-'.format(prefix), '')) self.partial_fields = [self.default_width_widget] if obj: full_context = obj.get_full_context() breakpoint = full_context.get('breakpoint') if breakpoint in ( 'lg', 'md', 'sm', ): xs_column_width = get_column_width('xs') choices = (('', _('Unset')), ) + tuple( ('col-sm-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, xs_column_width + 1)) self.partial_fields.append( PartialFormField( 'sm-column-width', widgets.Select(choices=choices), label=_('Width for Devices >768px'), help_text= _('Column width for all devices wider than 768 pixels, such as tablets.' ))) choices = (('', _('No offset')), ) + tuple( ('col-sm-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, xs_column_width)) self.partial_fields.append( PartialFormField( 'sm-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >768px'), help_text= _('Column offset for all devices wider than 768 pixels, such as tablets.' ))) if breakpoint in ( 'lg', 'md', ): sm_column_width = get_column_width('sm') choices = (('', _('Unset')), ) + tuple( ('col-md-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, sm_column_width + 1)) self.partial_fields.append( PartialFormField( 'md-column-width', widgets.Select(choices=choices), label=_('Width for Devices >992px'), help_text= _('Column width for all devices wider than 992 pixels, such as laptops.' ))) choices = (('', _('No offset')), ) + tuple( ('col-md-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, sm_column_width)) self.partial_fields.append( PartialFormField( 'md-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >992px'), help_text= _('Column offset for all devices wider than 992 pixels, such as laptops.' ))) if breakpoint in ('lg', ): md_column_width = get_column_width('md') choices = (('', _('Unset')), ) + tuple( ('col-lg-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, md_column_width + 1)) self.partial_fields.append( PartialFormField( 'lg-column-width', widgets.Select(choices=choices), label=_('Width for Devices >1200px'), help_text= _('Column width for all devices wider than 1200 pixels, such as large desktops.' ), )) choices = (('', _('No offset')), ) + tuple( ('col-lg-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, md_column_width)) self.partial_fields.append( PartialFormField( 'lg-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >1200px'), help_text= _('Column offset for all devices wider than 1200 pixels, such as large desktops.' ))) return super(BootstrapColumnPlugin, self).get_form(request, obj, **kwargs)
class BootstrapColumnPlugin(BootstrapPluginBase): name = _("Column") parent_classes = ['BootstrapRowPlugin'] generic_child_classes = settings.CMS_CASCADE_LEAF_PLUGINS default_width_widget = PartialFormField( 'xs-column-width', widgets.Select(choices=tuple( ('col-xs-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, 13))), label=_('Default Width'), initial='col-xs-12', help_text= _('Column width for all devices, down to phones narrower than 768 pixels.' ), ) default_css_attributes = tuple('{0}-column-width'.format(size) for size in ( 'xs', 'sm', 'md', 'lg', )) def get_form(self, request, obj=None, **kwargs): def get_column_width(prefix): # full_context from closure column_width = full_context.get( '{0}-column-width'.format(prefix)) or '12' return int( string.replace(column_width, 'col-{0}-'.format(prefix), '')) self.partial_fields = [self.default_width_widget] if obj: full_context = obj.get_full_context() breakpoint = full_context.get('breakpoint') if breakpoint in ( 'lg', 'md', 'sm', ): xs_column_width = get_column_width('xs') choices = (('', _('Unset')), ) + tuple( ('col-sm-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, xs_column_width + 1)) self.partial_fields.append( PartialFormField( 'sm-column-width', widgets.Select(choices=choices), label=_('Width for Devices >768px'), help_text= _('Column width for all devices wider than 768 pixels, such as tablets.' ))) choices = (('', _('No offset')), ) + tuple( ('col-sm-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, xs_column_width)) self.partial_fields.append( PartialFormField( 'sm-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >768px'), help_text= _('Column offset for all devices wider than 768 pixels, such as tablets.' ))) if breakpoint in ( 'lg', 'md', ): sm_column_width = get_column_width('sm') choices = (('', _('Unset')), ) + tuple( ('col-md-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, sm_column_width + 1)) self.partial_fields.append( PartialFormField( 'md-column-width', widgets.Select(choices=choices), label=_('Width for Devices >992px'), help_text= _('Column width for all devices wider than 992 pixels, such as laptops.' ))) choices = (('', _('No offset')), ) + tuple( ('col-md-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, sm_column_width)) self.partial_fields.append( PartialFormField( 'md-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >992px'), help_text= _('Column offset for all devices wider than 992 pixels, such as laptops.' ))) if breakpoint in ('lg', ): md_column_width = get_column_width('md') choices = (('', _('Unset')), ) + tuple( ('col-lg-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, md_column_width + 1)) self.partial_fields.append( PartialFormField( 'lg-column-width', widgets.Select(choices=choices), label=_('Width for Devices >1200px'), help_text= _('Column width for all devices wider than 1200 pixels, such as large desktops.' ), )) choices = (('', _('No offset')), ) + tuple( ('col-lg-offset-{0}'.format(i), ungettext_lazy('{0} unit', '{0} units', i).format(i)) for i in range(1, md_column_width)) self.partial_fields.append( PartialFormField( 'lg-column-offset', widgets.Select(choices=choices), label=_('Offset for Devices >1200px'), help_text= _('Column offset for all devices wider than 1200 pixels, such as large desktops.' ))) return super(BootstrapColumnPlugin, self).get_form(request, obj, **kwargs) @classmethod def get_identifier(cls, obj): try: width = int( string.replace(obj.context['xs-column-width'], 'col-xs-', '')) return ungettext_lazy('default width: {0} unit', 'default width: {0} units', width).format(width) except (TypeError, KeyError, ValueError): return _('unknown width')