<s> from __future__ import unicode_literals <EOL> import frappe <EOL> from frappe . website . doctype . website_settings . website_settings import get_website_settings <EOL> from frappe . website . router import get_route_info <EOL> def get_context ( path , args = None ) : <EOL> context = get_route_info ( path ) <EOL> if args : <EOL> context . update ( args ) <EOL> context = build_context ( context ) <EOL> if hasattr ( frappe . local , '<STR_LIT>' ) : <EOL> context [ "<STR_LIT:path>" ] = frappe . local . request . path [ <NUM_LIT:1> : ] <EOL> else : <EOL> context [ "<STR_LIT:path>" ] = path <EOL> if hasattr ( frappe . local , '<STR_LIT>' ) and frappe . local . response . get ( '<STR_LIT>' ) : <EOL> context . update ( frappe . local . response . context ) <EOL> return context <EOL> def build_context ( context ) : <EOL> """<STR_LIT>""" <EOL> context = frappe . _dict ( context ) <EOL> if not "<STR_LIT>" in context : <EOL> context . url_prefix = "<STR_LIT>" <EOL> context . update ( get_website_settings ( ) ) <EOL> context . update ( frappe . local . conf . get ( "<STR_LIT>" ) or { } ) <EOL> if context . doc : <EOL> context . update ( context . doc . as_dict ( ) ) <EOL> context . update ( context . doc . website ) <EOL> if hasattr ( context . doc , "<STR_LIT>" ) : <EOL> ret = context . doc . get_context ( context ) <EOL> if ret : <EOL> context . update ( ret ) <EOL> for prop in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if not prop in context : <EOL> context [ prop ] = getattr ( context . doc , prop , False ) <EOL> elif context . controller : <EOL> module = frappe . get_module ( context . controller ) <EOL> if module : <EOL> for prop in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) : <EOL> if hasattr ( module , prop ) : <EOL> context [ prop ] = getattr ( module , prop ) <EOL> if hasattr ( module , "<STR_LIT>" ) : <EOL> ret = module . get_context ( context ) <EOL> if ret : <EOL> context . update ( ret ) <EOL> if hasattr ( module , "<STR_LIT>" ) : <EOL> context . children = module . get_children ( context ) <EOL> if context . show_sidebar : <EOL> add_sidebar_data ( context ) <EOL> add_metatags ( context ) <EOL> if not context . base_template_path : <EOL> app_base = frappe . get_hooks ( "<STR_LIT>" ) <EOL> context . base_template_path = app_base [ <NUM_LIT:0> ] if app_base else "<STR_LIT>" <EOL> return context <EOL> def add_sidebar_data ( context ) : <EOL> from frappe . utils . user import get_fullname_and_avatar <EOL> import frappe . templates . pages . list <EOL> context . my_account_list = frappe . get_all ( '<STR_LIT>' , <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] , filters = { '<STR_LIT>' : <NUM_LIT:1> } , order_by = '<STR_LIT>' ) <EOL> for item in context . my_account_list : <EOL> if item . reference_doctype : <EOL> item . count = len ( frappe . templates . pages . list . get ( item . reference_doctype ) . get ( '<STR_LIT:result>' ) ) <EOL> info = get_fullname_and_avatar ( frappe . session . user ) <EOL> context [ "<STR_LIT>" ] = info . fullname <EOL> context [ "<STR_LIT>" ] = info . avatar <EOL> def add_metatags ( context ) : <EOL> tags = context . get ( "<STR_LIT>" ) <EOL> if tags : <EOL> if not "<STR_LIT>" in tags : <EOL> tags [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if not "<STR_LIT>" in tags : <EOL> tags [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if tags . get ( "<STR_LIT:name>" ) : <EOL> tags [ "<STR_LIT>" ] = tags [ "<STR_LIT>" ] = tags [ "<STR_LIT:name>" ] <EOL> if tags . get ( "<STR_LIT:description>" ) : <EOL> tags [ "<STR_LIT>" ] = tags [ "<STR_LIT>" ] = tags [ "<STR_LIT:description>" ] <EOL> if tags . get ( "<STR_LIT:image>" ) : <EOL> tags [ "<STR_LIT>" ] = tags [ "<STR_LIT>" ] = tags [ "<STR_LIT:image>" ] </s>
