<s> from __future__ import unicode_literals <EOL> from django . forms import widgets , ModelChoiceField , CharField <EOL> from django . forms . models import ModelForm <EOL> from django . db . models . fields . related import ManyToOneRel <EOL> from django . contrib . admin import StackedInline <EOL> from django . contrib . admin . sites import site <EOL> from django . utils . html import format_html <EOL> from django . utils . translation import ungettext_lazy , ugettext_lazy as _ <EOL> from filer . fields . image import AdminFileWidget , FilerImageField <EOL> from filer . models . imagemodels import Image <EOL> from cms . plugin_pool import plugin_pool <EOL> from cms . utils . compat . dj import is_installed <EOL> from cmsplugin_cascade . fields import PartialFormField <EOL> from cmsplugin_cascade . models import SortableInlineCascadeElement <EOL> from cmsplugin_cascade . mixins import ImagePropertyMixin <EOL> from cmsplugin_cascade . utils import resolve_dependencies <EOL> from cmsplugin_cascade . plugin_base import CascadePluginBase , create_proxy_model <EOL> from cmsplugin_cascade . widgets import CascadingSizeWidget <EOL> from . import utils <EOL> if is_installed ( '<STR_LIT>' ) : <EOL> from adminsortable2 . admin import SortableInlineAdminMixin <EOL> else : <EOL> SortableInlineAdminMixin = type ( str ( '<STR_LIT>' ) , ( object , ) , { } ) <EOL> class GalleryImageForm ( ModelForm ) : <EOL> image_file = ModelChoiceField ( queryset = Image . objects . all ( ) , label = _ ( "<STR_LIT>" ) , required = False ) <EOL> image_title = CharField ( label = _ ( "<STR_LIT>" ) , required = False , <EOL> widget = widgets . TextInput ( attrs = { '<STR_LIT:size>' : <NUM_LIT> } ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> alt_tag = CharField ( label = _ ( "<STR_LIT>" ) , required = False , <EOL> widget = widgets . TextInput ( attrs = { '<STR_LIT:size>' : <NUM_LIT> } ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> glossary_fields = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> class Meta : <EOL> exclude = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> try : <EOL> initial = dict ( kwargs [ '<STR_LIT>' ] . glossary ) <EOL> except ( KeyError , AttributeError ) : <EOL> initial = { } <EOL> initial . update ( kwargs . pop ( '<STR_LIT>' , { } ) ) <EOL> for key in self . glossary_fields : <EOL> self . base_fields [ key ] . initial = initial . get ( key ) <EOL> try : <EOL> self . base_fields [ '<STR_LIT>' ] . initial = initial [ '<STR_LIT:image>' ] [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> self . base_fields [ '<STR_LIT>' ] . initial = None <EOL> self . base_fields [ '<STR_LIT>' ] . widget = AdminFileWidget ( ManyToOneRel ( FilerImageField , Image , '<STR_LIT>' ) , site ) <EOL> if not is_installed ( '<STR_LIT>' ) : <EOL> self . base_fields [ '<STR_LIT>' ] . widget = widgets . HiddenInput ( ) <EOL> self . base_fields [ '<STR_LIT>' ] . initial = <NUM_LIT:0> <EOL> super ( GalleryImageForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def clean ( self ) : <EOL> cleaned_data = super ( GalleryImageForm , self ) . clean ( ) <EOL> if self . is_valid ( ) : <EOL> image_file = self . cleaned_data . pop ( '<STR_LIT>' , None ) <EOL> if image_file : <EOL> image_data = { '<STR_LIT>' : image_file . pk , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . instance . glossary . update ( image = image_data ) <EOL> else : <EOL> self . instance . glossary . pop ( '<STR_LIT:image>' , None ) <EOL> for key in self . glossary_fields : <EOL> self . instance . glossary . update ( { key : cleaned_data . pop ( key , '<STR_LIT>' ) } ) <EOL> return cleaned_data <EOL> class GalleryPluginInline ( SortableInlineAdminMixin , StackedInline ) : <EOL> model = SortableInlineCascadeElement <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> form = GalleryImageForm <EOL> extra = <NUM_LIT:1> <EOL> ordering = ( '<STR_LIT>' , ) <EOL> class BootstrapGalleryPlugin ( CascadePluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> module = '<STR_LIT>' <EOL> parent_classes = [ '<STR_LIT>' ] <EOL> require_parent = True <EOL> allow_children = False <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> text_enabled = True <EOL> admin_preview = False <EOL> render_template = '<STR_LIT>' <EOL> default_css_attributes = ( '<STR_LIT>' , ) <EOL> html_tag_attributes = { '<STR_LIT>' : '<STR_LIT:title>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> inlines = ( GalleryPluginInline , ) <EOL> SHAPE_CHOICES = ( ( '<STR_LIT>' , _ ( "<STR_LIT>" ) ) , ) <EOL> RESIZE_OPTIONS = ( ( '<STR_LIT>' , _ ( "<STR_LIT>" ) ) , ( '<STR_LIT>' , _ ( "<STR_LIT>" ) ) , <EOL> ( '<STR_LIT>' , _ ( "<STR_LIT>" ) ) , <EOL> ( '<STR_LIT>' , _ ( "<STR_LIT>" ) ) , ) <EOL> glossary_fields = ( <EOL> PartialFormField ( '<STR_LIT>' , <EOL> widgets . CheckboxSelectMultiple ( choices = SHAPE_CHOICES ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> initial = [ '<STR_LIT>' ] <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> CascadingSizeWidget ( allowed_units = [ '<STR_LIT:%>' ] , required = False ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> initial = '<STR_LIT>' , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> CascadingSizeWidget ( allowed_units = [ '<STR_LIT>' ] , required = False ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> CascadingSizeWidget ( allowed_units = [ '<STR_LIT>' , '<STR_LIT:%>' ] , required = False ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> CascadingSizeWidget ( allowed_units = [ '<STR_LIT>' ] ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> CascadingSizeWidget ( allowed_units = [ '<STR_LIT>' , '<STR_LIT:%>' ] ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> PartialFormField ( '<STR_LIT>' , <EOL> widgets . CheckboxSelectMultiple ( choices = RESIZE_OPTIONS ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> initial = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) , <EOL> ) <EOL> class Media : <EOL> js = resolve_dependencies ( '<STR_LIT>' ) <EOL> def get_form ( self , request , obj = None , ** kwargs ) : <EOL> utils . reduce_breakpoints ( self , '<STR_LIT>' ) <EOL> form = super ( BootstrapGalleryPlugin , self ) . get_form ( request , obj , ** kwargs ) <EOL> return form <EOL> def render ( self , context , instance , placeholder ) : <EOL> gallery_instances = [ ] <EOL> options = dict ( instance . get_complete_glossary ( ) ) <EOL> for inline_element in instance . sortinline_elements . all ( ) : <EOL> try : <EOL> ProxyModel = create_proxy_model ( '<STR_LIT>' , ( ImagePropertyMixin , ) , <EOL> SortableInlineCascadeElement , module = __name__ ) <EOL> inline_element . __class__ = ProxyModel <EOL> options . update ( inline_element . glossary , ** { <EOL> '<STR_LIT>' : options [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : options [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : False , <EOL> } ) <EOL> thumbnail_tags = utils . get_image_tags ( context , inline_element , options ) <EOL> for key , val in thumbnail_tags . items ( ) : <EOL> setattr ( inline_element , key , val ) <EOL> gallery_instances . append ( inline_element ) <EOL> except ( KeyError , AttributeError ) : <EOL> pass <EOL> inline_styles = instance . glossary . get ( '<STR_LIT>' , { } ) <EOL> inline_styles . update ( width = options [ '<STR_LIT>' ] ) <EOL> instance . glossary [ '<STR_LIT>' ] = inline_styles <EOL> context . update ( dict ( instance = instance , placeholder = placeholder , gallery_instances = gallery_instances ) ) <EOL> return context <EOL> @ classmethod <EOL> def get_css_classes ( cls , obj ) : <EOL> css_classes = super ( BootstrapGalleryPlugin , cls ) . get_css_classes ( obj ) <EOL> css_class = obj . glossary . get ( '<STR_LIT>' ) <EOL> if css_class : <EOL> css_classes . append ( css_class ) <EOL> return css_classes <EOL> @ classmethod <EOL> def get_identifier ( cls , obj ) : <EOL> identifier = super ( BootstrapGalleryPlugin , cls ) . get_identifier ( obj ) <EOL> num_elems = obj . sortinline_elements . count ( ) <EOL> content = ungettext_lazy ( "<STR_LIT>" , "<STR_LIT>" , num_elems ) . format ( num_elems ) <EOL> return format_html ( '<STR_LIT>' , identifier , content ) <EOL> plugin_pool . register_plugin ( BootstrapGalleryPlugin ) </s>
