<s> from cms . models import CMSPlugin , Placeholder <EOL> from cms . models . aliaspluginmodel import AliasPluginModel <EOL> from cms . models . placeholderpluginmodel import PlaceholderReference <EOL> from cms . plugin_base import CMSPluginBase , PluginMenuItem <EOL> from cms . plugin_pool import plugin_pool <EOL> from cms . plugin_rendering import render_placeholder <EOL> from cms . utils . urlutils import admin_reverse <EOL> from django . conf . urls import url <EOL> from django . http import HttpResponseForbidden , HttpResponseBadRequest , HttpResponse <EOL> from django . middleware . csrf import get_token <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext_lazy as _ , get_language <EOL> class PlaceholderPlugin ( CMSPluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> parent_classes = [ <NUM_LIT:0> ] <EOL> render_plugin = False <EOL> admin_preview = False <EOL> system = True <EOL> model = PlaceholderReference <EOL> plugin_pool . register_plugin ( PlaceholderPlugin ) <EOL> class AliasPlugin ( CMSPluginBase ) : <EOL> name = _ ( "<STR_LIT>" ) <EOL> allow_children = False <EOL> model = AliasPluginModel <EOL> render_template = "<STR_LIT>" <EOL> system = True <EOL> def render ( self , context , instance , placeholder ) : <EOL> from cms . utils . plugins import downcast_plugins , build_plugin_tree <EOL> request = context . get ( '<STR_LIT>' , None ) <EOL> context [ '<STR_LIT>' ] = instance <EOL> context [ '<STR_LIT>' ] = placeholder <EOL> if instance . plugin_id : <EOL> plugins = instance . plugin . get_descendants ( ) . order_by ( '<STR_LIT>' , '<STR_LIT:path>' ) <EOL> plugins = [ instance . plugin ] + list ( plugins ) <EOL> plugins = downcast_plugins ( plugins , request = request ) <EOL> plugins [ <NUM_LIT:0> ] . parent_id = None <EOL> plugins = build_plugin_tree ( plugins ) <EOL> context [ '<STR_LIT>' ] = plugins <EOL> if instance . alias_placeholder_id : <EOL> content = render_placeholder ( instance . alias_placeholder , context ) <EOL> context [ '<STR_LIT:content>' ] = mark_safe ( content ) <EOL> return context <EOL> def get_extra_global_plugin_menu_items ( self , request , plugin ) : <EOL> return [ <EOL> PluginMenuItem ( <EOL> _ ( "<STR_LIT>" ) , <EOL> admin_reverse ( "<STR_LIT>" ) , <EOL> data = { '<STR_LIT>' : plugin . pk , '<STR_LIT>' : get_token ( request ) } , <EOL> ) <EOL> ] <EOL> def get_extra_placeholder_menu_items ( self , request , placeholder ) : <EOL> return [ <EOL> PluginMenuItem ( <EOL> _ ( "<STR_LIT>" ) , <EOL> admin_reverse ( "<STR_LIT>" ) , <EOL> data = { '<STR_LIT>' : placeholder . pk , '<STR_LIT>' : get_token ( request ) } , <EOL> ) <EOL> ] <EOL> def get_plugin_urls ( self ) : <EOL> return [ <EOL> url ( r'<STR_LIT>' , self . create_alias , name = '<STR_LIT>' ) , <EOL> ] <EOL> def create_alias ( self , request ) : <EOL> if not request . user . is_staff : <EOL> return HttpResponseForbidden ( "<STR_LIT>" ) <EOL> if not '<STR_LIT>' in request . POST and not '<STR_LIT>' in request . POST : <EOL> return HttpResponseBadRequest ( "<STR_LIT>" ) <EOL> plugin = None <EOL> placeholder = None <EOL> if '<STR_LIT>' in request . POST : <EOL> pk = request . POST [ '<STR_LIT>' ] <EOL> try : <EOL> plugin = CMSPlugin . objects . get ( pk = pk ) <EOL> except CMSPlugin . DoesNotExist : <EOL> return HttpResponseBadRequest ( "<STR_LIT>" % pk ) <EOL> if '<STR_LIT>' in request . POST : <EOL> pk = request . POST [ '<STR_LIT>' ] <EOL> try : <EOL> placeholder = Placeholder . objects . get ( pk = pk ) <EOL> except Placeholder . DoesNotExist : <EOL> return HttpResponseBadRequest ( "<STR_LIT>" % pk ) <EOL> if not placeholder . has_change_permission ( request ) : <EOL> return HttpResponseBadRequest ( "<STR_LIT>" ) <EOL> clipboard = request . toolbar . clipboard <EOL> clipboard . cmsplugin_set . all ( ) . delete ( ) <EOL> language = get_language ( ) <EOL> if plugin : <EOL> language = plugin . language <EOL> alias = AliasPluginModel ( language = language , placeholder = clipboard , plugin_type = "<STR_LIT>" ) <EOL> if plugin : <EOL> alias . plugin = plugin <EOL> if placeholder : <EOL> alias . alias_placeholder = placeholder <EOL> alias . save ( ) <EOL> return HttpResponse ( "<STR_LIT>" ) <EOL> plugin_pool . register_plugin ( AliasPlugin ) </s>
