#NEWLINE# def post( self , request , page_pk = None ) : #NEWLINE# #INDENT# '\n        Save App Page modifications.\n\n        If correct return confirmation message\n        if not, return the form with error messages\n        ' #NEWLINE# if ( page_pk is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# page = request . website . pages . select_related ( ) . get ( pk = page_pk ) #NEWLINE# app_page = page . app_page_object #NEWLINE# #UNINDENT# except Page . DoesNotExist : #NEWLINE# #INDENT# raise ErrorResponse ( status . HTTP_400_BAD_REQUEST , { #NEWLINE# #INDENT# 'msg' : MESSAGES . get ( 'default_error' , '' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# app_page = request . page . app_page_object #NEWLINE# page = request . page #NEWLINE# #UNINDENT# PageAppForm = app_page . get_admin_form ( ) #NEWLINE# form = PageAppForm ( request . POST , instance = app_page ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# new_app_page = form . save ( ) #NEWLINE# if ( data_context . page == page ) : #NEWLINE# #INDENT# placeholder_slug_items = check_placeholder_html_id ( page . placeholder_slug ) #NEWLINE# layout_section_slug = placeholder_slug_items [ 0 ] #NEWLINE# rendering_context = RenderingContext ( request ) #NEWLINE# html_rendering = rendering_context . get_html_layout ( layout_section_slug ) #NEWLINE# data_context = { #NEWLINE# #INDENT# 'msg' : MESSAGES . get ( 'app_edit_success' , '' ) , #NEWLINE# 'html' : html_rendering , #NEWLINE# 'layout_section_slug' : layout_section_slug , #NEWLINE# #UNINDENT# } #NEWLINE# if page_pk : #NEWLINE# #INDENT# data_context [ 'refresh_pages_list' ] = True #NEWLINE# #UNINDENT# response = Response ( status . HTTP_200_OK , data_context ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data_context = { #NEWLINE# #INDENT# 'msg' : MESSAGES . get ( 'app_edit_success' , '' ) , #NEWLINE# #UNINDENT# } #NEWLINE# if page_pk : #NEWLINE# #INDENT# data_context [ 'refresh_pages_list' ] = True #NEWLINE# #UNINDENT# response = Response ( status . HTTP_200_OK , data_context ) #NEWLINE# #UNINDENT# return self . render ( response ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data_context = { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# 'object' : app_page , #NEWLINE# #UNINDENT# } #NEWLINE# if page_pk : #NEWLINE# #INDENT# data_context [ 'page' ] = page #NEWLINE# #UNINDENT# html = render_to_string ( 'administration/app/app-edit.html' , data_context , context_instance = RequestContext ( request ) ) #NEWLINE# raise ErrorResponse ( status . HTTP_400_BAD_REQUEST , { #NEWLINE# #INDENT# 'msg' : MESSAGES . get ( 'invalid_data' , '' ) , #NEWLINE# 'html' : html , #NEWLINE# #UNINDENT# } )