<s> from __future__ import unicode_literals <EOL> from django . forms import widgets <EOL> from django . forms . fields import CharField <EOL> from django . forms . models import ModelForm <EOL> from django . utils . translation import ungettext_lazy , ugettext_lazy as _ <EOL> from django . utils . text import Truncator <EOL> from django . utils . html import format_html <EOL> from django . forms . fields import IntegerField <EOL> from django . template . loader import select_template <EOL> from cms . plugin_pool import plugin_pool <EOL> from cmsplugin_cascade . forms import ManageChildrenFormMixin <EOL> from cmsplugin_cascade . fields import PartialFormField <EOL> from cmsplugin_cascade . link . forms import TextLinkFormMixin <EOL> from cmsplugin_cascade . link . plugin_base import LinkElementMixin <EOL> from cmsplugin_cascade . widgets import NumberInputWidget <EOL> from cmsplugin_cascade . bootstrap3 . buttons import BootstrapButtonMixin <EOL> from cmsplugin_cascade . mixins import TransparentMixin <EOL> from shop . cascade . plugin_base import ShopPluginBase <EOL> from shop import settings as shop_settings <EOL> class ProcessBarForm ( ManageChildrenFormMixin , ModelForm ) : <EOL> num_children = IntegerField ( min_value = <NUM_LIT:1> , initial = <NUM_LIT:1> , <EOL> widget = NumberInputWidget ( attrs = { '<STR_LIT:size>' : '<STR_LIT:3>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> class ProcessBarPlugin ( TransparentMixin , ShopPluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> form = ProcessBarForm <EOL> parent_classes = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> require_parent = True <EOL> allow_children = True <EOL> @ classmethod <EOL> def get_identifier ( cls , instance ) : <EOL> identifier = super ( ProcessBarPlugin , cls ) . get_identifier ( instance ) <EOL> num_cols = instance . get_children ( ) . count ( ) <EOL> content = ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' , num_cols ) . format ( num_cols ) <EOL> return format_html ( '<STR_LIT>' , identifier , content ) <EOL> def get_render_template ( self , context , instance , placeholder ) : <EOL> template_names = [ <EOL> '<STR_LIT>' . format ( shop_settings . APP_LABEL ) , <EOL> '<STR_LIT>' , <EOL> ] <EOL> return select_template ( template_names ) <EOL> def render ( self , context , instance , placeholder ) : <EOL> super ( ProcessBarPlugin , self ) . render ( context , instance , placeholder ) <EOL> num_children = instance . get_children ( ) . count ( ) <EOL> if num_children > <NUM_LIT:0> : <EOL> context [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <NUM_LIT> / num_children ) <EOL> return context <EOL> def save_model ( self , request , obj , form , change ) : <EOL> wanted_children = int ( form . cleaned_data . get ( '<STR_LIT>' ) ) <EOL> super ( ProcessBarPlugin , self ) . save_model ( request , obj , form , change ) <EOL> self . extend_children ( obj , wanted_children , ProcessStepPlugin ) <EOL> plugin_pool . register_plugin ( ProcessBarPlugin ) <EOL> class ProcessStepPlugin ( TransparentMixin , ShopPluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> parent_classes = ( '<STR_LIT>' , ) <EOL> require_parent = True <EOL> allow_children = True <EOL> alien_child_classes = True <EOL> render_template = '<STR_LIT>' <EOL> glossary_fields = ( <EOL> PartialFormField ( '<STR_LIT>' , <EOL> widgets . TextInput ( attrs = { '<STR_LIT:size>' : <NUM_LIT> } ) , <EOL> label = _ ( "<STR_LIT>" ) <EOL> ) , <EOL> ) <EOL> @ classmethod <EOL> def get_identifier ( cls , obj ) : <EOL> identifier = super ( ProcessStepPlugin , cls ) . get_identifier ( obj ) <EOL> content = obj . glossary . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if content : <EOL> content = unicode ( Truncator ( content ) . words ( <NUM_LIT:3> , truncate = '<STR_LIT>' ) ) <EOL> else : <EOL> content = obj . get_position_in_placeholder ( ) <EOL> return format_html ( '<STR_LIT>' , identifier , content ) <EOL> plugin_pool . register_plugin ( ProcessStepPlugin ) <EOL> class ProcessNextStepForm ( TextLinkFormMixin , ModelForm ) : <EOL> link_content = CharField ( required = False , label = _ ( "<STR_LIT>" ) , <EOL> widget = widgets . TextInput ( attrs = { '<STR_LIT:id>' : '<STR_LIT>' } ) ) <EOL> def __init__ ( self , raw_data = None , * args , ** kwargs ) : <EOL> instance = kwargs . get ( '<STR_LIT>' ) <EOL> initial = instance and dict ( instance . glossary ) or { } <EOL> initial . update ( kwargs . pop ( '<STR_LIT>' , { } ) ) <EOL> kwargs . update ( initial = initial ) <EOL> super ( ProcessNextStepForm , self ) . __init__ ( raw_data , * args , ** kwargs ) <EOL> class ProcessNextStepPlugin ( BootstrapButtonMixin , ShopPluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> parent_classes = ( '<STR_LIT>' , ) <EOL> form = ProcessNextStepForm <EOL> fields = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> model_mixins = ( LinkElementMixin , ) <EOL> class Media : <EOL> css = { '<STR_LIT:all>' : ( '<STR_LIT>' , '<STR_LIT>' , ) } <EOL> @ classmethod <EOL> def get_identifier ( cls , obj ) : <EOL> identifier = super ( ProcessNextStepPlugin , cls ) . get_identifier ( obj ) <EOL> content = obj . glossary . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return format_html ( '<STR_LIT>' , identifier , content ) <EOL> def get_render_template ( self , context , instance , placeholder ) : <EOL> template_names = [ <EOL> '<STR_LIT>' . format ( shop_settings . APP_LABEL ) , <EOL> '<STR_LIT>' , <EOL> ] <EOL> return select_template ( template_names ) <EOL> plugin_pool . register_plugin ( ProcessNextStepPlugin ) </s>
