<s> import os <EOL> from djangorestframework . response import Response <EOL> from djangorestframework import status <EOL> from django . template . loader import render_to_string <EOL> from django . template import RequestContext <EOL> from django . conf import settings <EOL> from ionyweb . administration . views import IsAdminView <EOL> from ionyweb . administration . permissions import _400_BAD_REQUEST <EOL> from ionyweb . website . rendering import RenderingContext <EOL> from ionyweb . loaders . manifest import layouts_info , themes_info <EOL> from ionyweb . administration . utils import MESSAGES <EOL> class LayoutsListView ( IsAdminView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request ) : <EOL> """<STR_LIT>""" <EOL> layout_section_slug = request . GET . get ( '<STR_LIT>' , None ) <EOL> if not layout_section_slug : <EOL> raise _400_BAD_REQUEST <EOL> else : <EOL> rendering_context = RenderingContext ( request ) <EOL> current_layout_slug = rendering_context . get_layout_template_slug ( layout_section_slug ) <EOL> list_layouts = layouts_info ( ) <EOL> html = render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : list_layouts , <EOL> '<STR_LIT>' : layout_section_slug , <EOL> '<STR_LIT>' : current_layout_slug } , <EOL> context_instance = RequestContext ( request ) ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT:html>" : html } ) <EOL> return self . render ( response ) <EOL> class LayoutListView ( IsAdminView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request ) : <EOL> """<STR_LIT>""" <EOL> layout_section_slug = request . GET . get ( '<STR_LIT>' , None ) <EOL> layout_template_slug = request . GET . get ( '<STR_LIT>' , None ) <EOL> plugin_relation_default = request . GET . getlist ( '<STR_LIT>' ) <EOL> plugin_relation_default_placeholder = request . GET . getlist ( '<STR_LIT>' ) <EOL> if not layout_section_slug : <EOL> raise _400_BAD_REQUEST <EOL> rendering_context = RenderingContext ( request ) <EOL> html_layout_rendering = rendering_context . get_html_layout ( layout_section_slug , <EOL> template_file_preview = layout_template_slug ) <EOL> plugin_relation_default_data = [ ] <EOL> for i in xrange ( len ( plugin_relation_default ) ) : <EOL> plugin_relation_default_data . append ( { <EOL> '<STR_LIT:id>' : plugin_relation_default [ i ] , <EOL> '<STR_LIT>' : plugin_relation_default_placeholder [ i ] . split ( settings . HTML_ID_PLACEHOLDER ) [ <NUM_LIT:0> ] } ) <EOL> layout_default_infos_refresh = rendering_context . refresh_default ( layout_section_slug , <EOL> plugin_relation_default_data ) <EOL> response = Response ( status . HTTP_200_OK , <EOL> { "<STR_LIT>" : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> '<STR_LIT>' : layout_default_infos_refresh [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : layout_default_infos_refresh [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : layout_section_slug , <EOL> '<STR_LIT:html>' : html_layout_rendering } ) <EOL> return self . render ( response ) <EOL> def post ( self , request ) : <EOL> """<STR_LIT>""" <EOL> layout_section_slug = request . POST . get ( '<STR_LIT>' , None ) <EOL> layout_template_slug = request . POST . get ( '<STR_LIT>' , None ) <EOL> if not layout_section_slug and not layout_template_slug : <EOL> raise _400_BAD_REQUEST <EOL> rendering_context = RenderingContext ( request ) <EOL> rendering_context . set_layout_template_file ( layout_section_slug , layout_template_slug ) <EOL> response = Response ( status . HTTP_200_OK , <EOL> { "<STR_LIT>" : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) } ) <EOL> return self . render ( response ) <EOL> class ThemesListView ( IsAdminView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request ) : <EOL> """<STR_LIT>""" <EOL> list_themes = sorted ( themes_info ( ) , key = lambda theme : theme [ '<STR_LIT:title>' ] . lower ( ) ) <EOL> html = render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : list_themes , <EOL> '<STR_LIT>' : request . website . theme } , <EOL> context_instance = RequestContext ( request ) ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT:html>" : html } ) <EOL> return self . render ( response ) <EOL> def post ( self , request ) : <EOL> """<STR_LIT>""" <EOL> request . website . theme = request . POST [ '<STR_LIT>' ] <EOL> request . website . save ( ) <EOL> response = Response ( status . HTTP_200_OK , <EOL> { "<STR_LIT>" : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) } ) <EOL> return self . render ( response ) </s>
