<s> """<STR_LIT>""" <EOL> from past . builtins import cmp <EOL> from builtins import str <EOL> from builtins import object <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> import os <EOL> import cgi <EOL> import inspect <EOL> import types <EOL> import datetime <EOL> from textwrap import fill <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from lino . modlib . extjs . elems import Panel <EOL> from lino . utils . report import EmptyTable <EOL> from lino . utils import AttrDict <EOL> from lino . utils . code import codetime , codefiles , SourceFile <EOL> from lino . utils . xmlgen . html import E <EOL> from lino . api import dd <EOL> class Models ( dd . VirtualTable ) : <EOL> label = _ ( "<STR_LIT>" ) <EOL> column_names = "<STR_LIT>" <EOL> detail_layout = """<STR_LIT>""" <EOL> slave_grid_format = '<STR_LIT:html>' <EOL> @ classmethod <EOL> def get_data_rows ( self , ar ) : <EOL> for model in models . get_models ( ) : <EOL> if True : <EOL> yield model <EOL> @ classmethod <EOL> def summary_row ( cls , ar , obj , ** kw ) : <EOL> return [ str ( obj . _meta . verbose_name_plural ) ] <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def app ( self , obj , ar ) : <EOL> return obj . _meta . app_label <EOL> @ dd . displayfield ( _ ( "<STR_LIT:name>" ) ) <EOL> def name ( self , obj , ar ) : <EOL> return obj . __name__ <EOL> @ dd . displayfield ( ) <EOL> def detail_action ( self , obj , ar ) : <EOL> if obj . get_default_table ( ) . detail_action is None : <EOL> return '<STR_LIT>' <EOL> return obj . get_default_table ( ) . detail_action . full_name ( ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def docstring ( self , obj , ar ) : <EOL> return obj . __doc__ <EOL> @ dd . requestfield ( _ ( "<STR_LIT>" ) ) <EOL> def rows ( self , obj , ar ) : <EOL> return obj . get_default_table ( ) . request ( <EOL> ar . ui , <EOL> user = ar . get_user ( ) , renderer = ar . renderer ) <EOL> class FieldsByModel ( dd . VirtualTable ) : <EOL> label = _ ( "<STR_LIT>" ) <EOL> column_names = "<STR_LIT>" <EOL> @ classmethod <EOL> def get_data_rows ( self , ar ) : <EOL> model = ar . master_instance <EOL> if model : <EOL> for ( fld , remote ) in model . _meta . get_fields_with_model ( ) : <EOL> yield fld <EOL> @ dd . displayfield ( _ ( "<STR_LIT:name>" ) ) <EOL> def name ( self , fld , ar ) : <EOL> return fld . name <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def verbose_name ( self , fld , ar ) : <EOL> return str ( fld . vebose_name ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def help_text_column ( self , obj , ar ) : <EOL> return restify ( str ( obj . help_text ) ) <EOL> class Inspected ( object ) : <EOL> def __init__ ( self , parent , prefix , name , value ) : <EOL> self . parent = parent <EOL> self . prefix = prefix <EOL> self . name = name <EOL> self . value = value <EOL> class Inspector ( dd . VirtualTable ) : <EOL> """<STR_LIT>""" <EOL> label = _ ( "<STR_LIT>" ) <EOL> required_roles = dd . required ( dd . SiteStaff ) <EOL> column_names = "<STR_LIT>" <EOL> parameters = dict ( <EOL> inspected = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:100> , blank = True ) , <EOL> show_callables = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> ) <EOL> params_layout = '<STR_LIT>' <EOL> @ classmethod <EOL> def get_inspected ( self , name ) : <EOL> if not name : <EOL> return settings <EOL> try : <EOL> o = eval ( '<STR_LIT>' + name ) <EOL> except Exception as e : <EOL> o = e <EOL> return o <EOL> @ classmethod <EOL> def get_data_rows ( self , ar ) : <EOL> if ar . param_values . show_callables : <EOL> def flt ( v ) : <EOL> return True <EOL> else : <EOL> def flt ( v ) : <EOL> if isinstance ( v , ( <EOL> types . FunctionType , <EOL> types . GeneratorType , <EOL> types . UnboundMethodType , <EOL> types . UnboundMethodType , <EOL> types . BuiltinMethodType , <EOL> types . BuiltinFunctionType <EOL> ) ) : <EOL> return False <EOL> return True <EOL> o = self . get_inspected ( ar . param_values . inspected ) <EOL> if isinstance ( o , ( list , tuple ) ) : <EOL> for i , v in enumerate ( o ) : <EOL> k = "<STR_LIT:[>" + str ( i ) + "<STR_LIT:]>" <EOL> yield Inspected ( o , '<STR_LIT>' , k , v ) <EOL> elif isinstance ( o , AttrDict ) : <EOL> for k , v in list ( o . items ( ) ) : <EOL> yield Inspected ( o , '<STR_LIT:.>' , k , v ) <EOL> elif isinstance ( o , dict ) : <EOL> for k , v in list ( o . items ( ) ) : <EOL> k = "<STR_LIT:[>" + repr ( k ) + "<STR_LIT:]>" <EOL> yield Inspected ( o , '<STR_LIT>' , k , v ) <EOL> else : <EOL> for k in dir ( o ) : <EOL> if not k . startswith ( '<STR_LIT>' ) : <EOL> if not ar . quick_search or ( ar . quick_search . lower ( ) in k . lower ( ) ) : <EOL> v = getattr ( o , k ) <EOL> if flt ( v ) : <EOL> yield Inspected ( o , '<STR_LIT:.>' , k , v ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT:Name>" ) ) <EOL> def i_name ( self , obj , ar ) : <EOL> pv = dict ( ) <EOL> if ar . param_values . inspected : <EOL> pv . update ( inspected = ar . param_values . inspected + <EOL> obj . prefix + obj . name ) <EOL> else : <EOL> pv . update ( inspected = obj . name ) <EOL> newreq = ar . spawn ( param_values = pv ) <EOL> return ar . href_to_request ( newreq , obj . name ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def i_value ( self , obj , ar ) : <EOL> return cgi . escape ( str ( obj . value ) ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def i_type ( self , obj , ar ) : <EOL> return cgi . escape ( str ( type ( obj . value ) ) ) <EOL> class About ( EmptyTable ) : <EOL> """<STR_LIT>""" <EOL> label = _ ( "<STR_LIT>" ) <EOL> help_text = _ ( "<STR_LIT>" ) <EOL> required_roles = set ( ) <EOL> hide_top_toolbar = True <EOL> detail_layout = dd . FormLayout ( """<STR_LIT>""" , window_size = ( <NUM_LIT> , <NUM_LIT:20> ) ) <EOL> @ dd . constant ( ) <EOL> def about_html ( cls ) : <EOL> body = [ ] <EOL> body . append ( settings . SITE . welcome_html ( ) ) <EOL> if settings . SITE . languages : <EOL> body . append ( E . p ( str ( _ ( "<STR_LIT>" ) ) + "<STR_LIT>" + '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> lng . django_code for lng in settings . SITE . languages ] ) ) ) <EOL> def dtfmt ( dt ) : <EOL> if isinstance ( dt , float ) : <EOL> dt = datetime . datetime . fromtimestamp ( dt ) <EOL> return str ( _ ( "<STR_LIT>" ) ) % dict ( <EOL> date = dd . fdf ( dt . date ( ) ) , <EOL> time = dt . time ( ) ) <EOL> items = [ ] <EOL> times = [ ] <EOL> value = settings . SITE . startup_time <EOL> label = _ ( "<STR_LIT>" ) <EOL> body . append ( E . p ( str ( label ) , '<STR_LIT>' , E . b ( dtfmt ( value ) ) ) ) <EOL> if settings . SITE . is_demo_site : <EOL> s = str ( _ ( "<STR_LIT>" ) ) <EOL> body . append ( E . p ( s ) ) <EOL> if settings . SITE . the_demo_date : <EOL> s = _ ( "<STR_LIT>" ) . format ( <EOL> dd . fdf ( settings . SITE . the_demo_date ) ) <EOL> body . append ( E . p ( s ) ) <EOL> body . append ( E . p ( str ( _ ( "<STR_LIT>" ) ) ) ) <EOL> for src in ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> label = src <EOL> value = codetime ( '<STR_LIT>' % src ) <EOL> if value is not None : <EOL> times . append ( ( label , value ) ) <EOL> def mycmp ( a , b ) : <EOL> return cmp ( b [ <NUM_LIT:1> ] , a [ <NUM_LIT:1> ] ) <EOL> times . sort ( mycmp ) <EOL> for label , value in times : <EOL> items . append ( E . li ( str ( label ) , '<STR_LIT>' , E . b ( dtfmt ( value ) ) ) ) <EOL> body . append ( E . ul ( * items ) ) <EOL> return E . div ( * body , class_ = '<STR_LIT>' ) <EOL> @ dd . displayfield ( _ ( "<STR_LIT>" ) ) <EOL> def server_status ( cls , obj , ar ) : <EOL> body = [ ] <EOL> body . append ( E . p ( _ ( "<STR_LIT>" ) % <EOL> len ( settings . SITE . kernel . pending_threads ) ) ) <EOL> return E . div ( * body , class_ = '<STR_LIT>' ) <EOL> class SourceFiles ( dd . VirtualTable ) : <EOL> label = _ ( "<STR_LIT>" ) <EOL> column_names = '<STR_LIT>' <EOL> @ classmethod <EOL> def get_data_rows ( self , ar ) : <EOL> for name , filename in codefiles ( '<STR_LIT>' ) : <EOL> yield SourceFile ( name , filename ) <EOL> @ dd . virtualfield ( models . IntegerField ( _ ( "<STR_LIT>" ) ) ) <EOL> def code_lines ( self , obj , ar ) : <EOL> return obj . count_code <EOL> @ dd . virtualfield ( models . IntegerField ( _ ( "<STR_LIT>" ) ) ) <EOL> def doc_lines ( self , obj , ar ) : <EOL> return obj . count_doc <EOL> @ dd . virtualfield ( models . CharField ( _ ( "<STR_LIT>" ) ) ) <EOL> def module_name ( self , obj , ar ) : <EOL> return obj . modulename </s>
