<s> import json <EOL> from django . template . loader import render_to_string <EOL> from django . contrib . auth import get_permission_codename <EOL> from django . contrib . sites . models import Site <EOL> from django . http import HttpResponse <EOL> from django . utils . encoding import smart_str <EOL> from cms . constants import PUBLISHER_STATE_PENDING , PUBLISHER_STATE_DIRTY <EOL> from cms . models import Page , GlobalPagePermission <EOL> from cms . utils import get_language_from_request , get_language_list , get_cms_setting <EOL> NOT_FOUND_RESPONSE = "<STR_LIT>" <EOL> def jsonify_request ( response ) : <EOL> """<STR_LIT>""" <EOL> content = { '<STR_LIT:status>' : response . status_code , '<STR_LIT:content>' : smart_str ( response . content , response . charset ) } <EOL> return HttpResponse ( json . dumps ( content ) , content_type = "<STR_LIT:application/json>" ) <EOL> publisher_classes = { <EOL> PUBLISHER_STATE_DIRTY : "<STR_LIT>" , <EOL> PUBLISHER_STATE_PENDING : "<STR_LIT>" , <EOL> } <EOL> def get_admin_menu_item_context ( request , page , filtered = False , language = None ) : <EOL> """<STR_LIT>""" <EOL> has_add_page_permission = page . has_add_permission ( request ) <EOL> has_move_page_permission = page . has_move_page_permission ( request ) <EOL> site = Site . objects . get_current ( ) <EOL> lang = get_language_from_request ( request ) <EOL> metadata = "<STR_LIT>" <EOL> if get_cms_setting ( '<STR_LIT>' ) : <EOL> md = [ ] <EOL> if not has_move_page_permission : <EOL> md . append ( ( '<STR_LIT>' , False ) ) <EOL> md . append ( ( '<STR_LIT>' , False ) ) <EOL> if md : <EOL> metadata = "<STR_LIT:{>" + "<STR_LIT:U+002CU+0020>" . join ( map ( lambda e : "<STR_LIT>" % ( e [ <NUM_LIT:0> ] , <EOL> isinstance ( e [ <NUM_LIT:1> ] , bool ) and str ( e [ <NUM_LIT:1> ] ) or e [ <NUM_LIT:1> ] . lower ( ) ) , md ) ) + "<STR_LIT:}>" <EOL> has_add_on_same_level_permission = False <EOL> opts = Page . _meta <EOL> if get_cms_setting ( '<STR_LIT>' ) : <EOL> if hasattr ( request . user , '<STR_LIT>' ) : <EOL> global_add_perm = request . user . _global_add_perm_cache <EOL> else : <EOL> global_add_perm = GlobalPagePermission . objects . user_has_add_permission ( <EOL> request . user , page . site_id ) . exists ( ) <EOL> request . user . _global_add_perm_cache = global_add_perm <EOL> if request . user . has_perm ( opts . app_label + '<STR_LIT:.>' + get_permission_codename ( '<STR_LIT>' , opts ) ) and global_add_perm : <EOL> has_add_on_same_level_permission = True <EOL> from cms . utils import permissions <EOL> if not has_add_on_same_level_permission and page . parent_id : <EOL> has_add_on_same_level_permission = permissions . has_generic_permission ( page . parent_id , request . user , "<STR_LIT>" , <EOL> page . site_id ) <EOL> context = { <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : page , <EOL> '<STR_LIT>' : site , <EOL> '<STR_LIT>' : lang , <EOL> '<STR_LIT>' : filtered , <EOL> '<STR_LIT>' : metadata , <EOL> '<STR_LIT>' : language , <EOL> '<STR_LIT>' : page . has_change_permission ( request ) , <EOL> '<STR_LIT>' : page . has_publish_permission ( request ) , <EOL> '<STR_LIT>' : page . has_delete_permission ( request ) , <EOL> '<STR_LIT>' : has_move_page_permission , <EOL> '<STR_LIT>' : has_add_page_permission , <EOL> '<STR_LIT>' : has_add_on_same_level_permission , <EOL> '<STR_LIT>' : get_cms_setting ( '<STR_LIT>' ) , <EOL> } <EOL> return context <EOL> def render_admin_menu_item ( request , page , template = None , language = None , <EOL> open_nodes = ( ) ) : <EOL> """<STR_LIT>""" <EOL> if not template : <EOL> template = "<STR_LIT>" <EOL> if not page . pk : <EOL> return HttpResponse ( NOT_FOUND_RESPONSE ) <EOL> from cms . utils import permissions <EOL> languages = get_language_list ( page . site_id ) <EOL> context = { <EOL> '<STR_LIT>' : permissions . has_page_add_permission_from_request ( request ) , <EOL> '<STR_LIT>' : languages , <EOL> '<STR_LIT>' : open_nodes , <EOL> } <EOL> filtered = '<STR_LIT>' in request . GET or '<STR_LIT>' in request . POST <EOL> context . update ( get_admin_menu_item_context ( request , page , filtered , language ) ) <EOL> return render_to_string ( template , context ) </s>
