コード例 #1
0
ファイル: views.py プロジェクト: kadefor/testdoc
 def f():
     content = file(_f).read()
     if render:
         content = to_html(template(content, env=application.get_view_env()))
     else:
         content = to_html(content)
     return application.template('show_document.html', locals())
コード例 #2
0
def process_tag(data, tag, loader, log=None):
    from uliweb.core.template import template

    t = loader.find(tag)
    if not t:
        raise ValueError("Tag {} can't be found".format(tag))

    env = {
        'to_attrs': _to_attrs,
        'xml': _unparse,
        'xml_full': _unparse_full,
        'get_list': _get_list,
        'get_options': _get_options,
        'has_attr': _has_attr,
        'get_attr': _get_attr,
        'get_text': _get_text
    }

    return template(t,
                    data,
                    env=env,
                    begin_tag='{%',
                    end_tag='%}',
                    log=log,
                    multilines=True)
コード例 #3
0
ファイル: taglibs.py プロジェクト: ppa737/uliweb
def process_tag(data, tag, loader, log=None):
    from uliweb.core.template import template

    t = loader.find(tag)
    if not t:
        raise ValueError("Tag {} can't be found".format(tag))

    env = {'to_attrs':_to_attrs, 'xml':_unparse, 'xml_full':_unparse_full}

    return template(t, data, env=env, begin_tag='{%', end_tag='%}', log=log, multilines=True)
コード例 #4
0
ファイル: graph.py プロジェクト: anyexxx/uliweb
def generate_dot(tables, apps, **kwargs):
    from uliweb.orm import get_model, OneToOne, ReferenceProperty, ManyToMany
    from uliweb.core.template import template
    
    dot = head_template

    graphs = []
    for app in apps:
        graph = {
            'name': '"%s"' % app,
            'app_name': "%s" % app,
            'cluster_app_name': "cluster_%s" % app.replace('.', '_'),
#            'disable_fields': disable_fields,
            'use_subgraph': True,
            'models': []
        }

        t = get_model_tables(tables, app)
        if not t: continue
        for tablename in t:
            model = {
                'app_name': app.replace('.', '_'),
                'name': tablename,
#                'abstracts': abstracts,
                'fields': [],
                'relations': []
            }
            
            try:
                M = get_model(tablename)
            except:
                continue

            # consider given model name ?
#            def consider(model_name):
#                return not include_models or model_name in include_models
#
#            if not consider(appmodel._meta.object_name):
#                continue

#            if verbose_names and appmodel._meta.verbose_name:
#                model['label'] = appmodel._meta.verbose_name
#            else:
#                model['label'] = model['name']
            if getattr(M, '__verbose_name__', None):
                model['label'] = "%s(%s)" % (tablename, getattr(M, '__verbose_name__', None))
            else:
                model['label'] = tablename
            
            # model attributes
            def add_attributes(field):
                if field.verbose_name:
                    label = "%s(%s)" % (field.property_name, field.verbose_name)
                else:
                    label = "%s" % field.property_name
                    
                model['fields'].append({
                    'name': field.property_name,
                    'label': label,
                    'type': type(field).__name__,
                    'required': field.required,
#                    'abstract': field in abstract_fields,
                })
                    

            for k, field in M._fields_list:
                add_attributes(field)

            # relations
            def add_relation(field, extras="", rel=''):
                label = "%s(%s)" % (field.property_name, rel)
                    
                _rel = {
                    'target_app': field.reference_class.table.__appname__.replace('.', '_'),
                    'target': field.reference_class.tablename,
                    'type': type(field).__name__,
                    'name': field.property_name,
                    'label': label,
                    'arrows': extras,
                    'needs_node': True
                }
                if _rel not in model['relations']:
                    model['relations'].append(_rel)

            for k, field in M._fields_list:
                if field.__class__ is OneToOne:
                    add_relation(field, '[dir=both arrowhead=none arrowtail=none]', rel='1:1')
                elif field.__class__ is ReferenceProperty:
                    add_relation(field, rel='n:1')

            if M._manytomany:
                for k, field in M._manytomany.iteritems():
                    if field.__class__ is ManyToMany:
                        add_relation(field, '[dir=both arrowhead=normal arrowtail=normal]', rel='m:n')
            graph['models'].append(model)
        graphs.append(graph)

    nodes = []
    for graph in graphs:
        nodes.extend([e['name'] for e in graph['models']])

    for graph in graphs:
        # don't draw duplication nodes because of relations
        for model in graph['models']:
            for relation in model['relations']:
                if relation['target'] in nodes:
                    relation['needs_node'] = False
        # render templates
        dot += '\n' + template(body_template, graph)

    for graph in graphs:
        dot += '\n' + template(rel_template, graph)

    dot += '\n' + tail_template
    return dot
コード例 #5
0
ファイル: diff2html.py プロジェクト: chyhutu/plugs
def diff2html(filename, id, diff, fileinfo='', actions='', tmpl=None):
    tmpl = tmpl or default_template
    
    if isinstance(diff, (str, unicode)):
        lines = diff.splitlines()
    else:
        lines = diff
        
    def get_lines(diff, counts):
        skip = True
        left = 0
        right = 0
        ins_count = 0
        del_count = 0
        for line in diff:
            if skip:
                if line.startswith('@@'):
                    skip = False
                    info = parse_info_line(line)
                    left = info['L-begin']
                    right = info['R-begin']
                    yield '...', '...', 'gc', line.rstrip()
            else:
                if line.startswith('@@'):
                    info = parse_info_line(line)
                    if info:
                        left = info['L-begin']
                        right = info['R-begin']
                        yield '...', '...', 'gc', line.rstrip()
                        continue
                
                left_line_num = left
                right_line_num = right
                if line.startswith('-'):
                    left += 1
                    del_count += 1
                    right_line_num = ''
                    _cls = 'gd'
                elif line.startswith('+'):
                    right += 1
                    ins_count += 1
                    left_line_num = ''
                    _cls = 'gi'
                else:
                    left += 1
                    right += 1
                    _cls = ''
                yield left_line_num, right_line_num, _cls, line.rstrip()
        counts.append(ins_count)
        counts.append(del_count)
        
    def parse_info_line(line):
        m = r_info.match(line)
        if m:
            return {'L-begin':int(m.group(1)), 'L-count':int(m.group(2) or 1),
                'R-begin':int(m.group(3)), 'R-count':int(m.group(4) or 1)}
                
    counts = []
    text1 = template(tmpl[0], {'filename':filename, 'id':id})
    text2 = template(tmpl[1], {'lines':get_lines(lines, counts), 
        'filename':filename, 'id':id, 'fileinfo':fileinfo, 'actions':actions})

        
    ins_count, del_count = counts
    change_direct, changes = get_changes(ins_count, del_count)
    d = {'total_count':ins_count+del_count,
        'change_direct':change_direct,
        'changes':changes,
        }
    return text1 + (info_template % d) + text2
コード例 #6
0
def generate_dot(tables, apps, engine_name=None, fontname=None, **kwargs):
    from uliweb.orm import (get_model, OneToOne, ReferenceProperty,
                            ManyToMany, engine_manager, Model)
    from uliweb.core.template import template

    graphs = []
    table_apps = set([t.__appname__ for t in tables.values()])
    apps = list( table_apps | set(list((apps or []))))

    visited_models = set(tables)
    models = {}
    apps_graph = {}
    nodes = []
    fontname = fontname or 'Helvetica'

    def get_graph(name):
        graph = apps_graph.get(name)
        if not graph:
            graph = {
                'name': '"%s"' % app,
                'app_name': app,
                'fontname': fontname,
                'cluster_app_name': "cluster_%s" % app.replace('.', '_'),
                #only name in tables'app will use subgraph
                'use_subgraph': False, #bool(name in table_apps),
                'models': []
            }
            apps_graph[name] = graph
            graphs.append(graph)
        return graph

    def make_model_info(M):
        model = models.get(M.tablename)
        if model: return model
        model = {
            'app_name': M.table.__appname__.replace('.', '_'),
            'name': M.tablename,
            'fields': [],
            'relations': [],

        }
        model['label'] = M.tablename
        if model['name'] not in models:
            models[M.tablename] = model
            get_graph(M.table.__appname__)['models'].append(model)
        return model

    def add_relation(model, field, extras="", rel='', target_app=None):
        label = "%s(%s)" % (field.property_name, rel)
        target_app = (target_app or field.reference_class.table.__appname__).replace('.', '_')
        target = field.reference_class.tablename
        _rel = {
            'target_app': target_app,
            'target': target,
            'type': type(field).__name__,
            'name': field.property_name,
            'label': label,
            'arrows': extras,
            'needs_node': True
        }
        name = target_app+'_'+target
        if name in nodes:
            _rel['needs_node'] = False
        else:
            _model = {
                'app_name': target_app.replace('.', '_'),
                'name': target,
                'label': target,
                'fields': [],
                'relations': []
            }
            if target not in models:
                models[target] = _model
                graph = apps_graph.get(target_app)
                if not graph:
                    graph = {
                        'name': '"%s"' % target_app,
                        'app_name': target_app,
                        'fontname': fontname,
                        'cluster_app_name': "cluster_%s" % target_app.replace('.', '_'),
                        'use_subgraph': False,
                        'models': []
                    }
                    graphs.append(graph)
                    apps_graph[target_app] = graph
                graph['models'].append(_model)
            else:
                _rel['needs_node'] = False
            nodes.append(name)

        if _rel not in model['relations']:
            model['relations'].append(_rel)


    for app in apps:
        graph = get_graph(app)

        t = get_model_tables(tables, app)
        if not t: continue
        for tablename in t:
            try:
                M = get_model(tablename)
            except:
                continue

            model = make_model_info(M)

            # model attributes
            def add_attributes(field):
                if field.verbose_name:
                    label = "%s(%s)" % (field.property_name, field.verbose_name)
                else:
                    label = "%s" % field.property_name

                d = field.to_column_info()
                # if not isinstance(field, ManyToMany):
                #     d = field.to_column_info()
                # else:
                #     d = {
                #     'name': field.property_name,
                #     'type': ' ',
                #     'relation': 'ManyToMany(%s)' % field.reference_class.__name__,
                #     'primary_key': False
                #     }
                d['label'] = label
                model['fields'].append(d)


            for k, field in M._fields_list:
                add_attributes(field)

            for k, field in M._fields_list:
                if field.__class__ is OneToOne:
                    add_relation(model, field, '[dir=both arrowhead=none arrowtail=none]', rel='1:1')
                elif field.__class__ is ReferenceProperty:
                    add_relation(model, field, rel='n:1')
                elif field.__class__ is ManyToMany:
                    add_relation(model, field, '[dir=both arrowhead=normal arrowtail=normal]', rel='m:n')

    #process the rest models
    engine = engine_manager[engine_name]
    for tablename, m in engine.models.items():
        if tablename not in visited_models:
            M = get_model(tablename)
            appname = M.table.__appname__
            if appname in apps:
                for k, field in M._fields_list:
                    if field.__class__ is OneToOne:
                        name = field.reference_class.tablename
                        target_app = field.reference_class.table.__appname__
                        if name in tables:
                            model = make_model_info(M)
                            add_relation(model, field,
                                         '[dir=both arrowhead=none arrowtail=none color=red]',
                                         rel='1:1',
                                         target_app=target_app)
                    elif field.__class__ is ReferenceProperty:
                        name = field.reference_class.tablename
                        target_app = field.reference_class.table.__appname__
                        if name in tables:
                            model = make_model_info(M)
                            add_relation(model, field, '[color=red]',
                                         rel='n:1',
                                         target_app=target_app)
                    elif field.__class__ is ManyToMany:
                        name = field.reference_class.tablename
                        target_app = field.reference_class.table.__appname__
                        if name in tables:
                            model = make_model_info(M)
                            add_relation(model, field,
                                         '[dir=both arrowhead=normal arrowtail=normal color=red]',
                                         rel='m:n',
                                         target_app=target_app)

    nodes = []
    for graph in graphs:
        nodes.extend([e['name'] for e in graph['models']])

    #create dot file
    dot = template(head_template, graph)

    for graph in graphs:
        # don't draw duplication nodes because of relations
        for model in graph['models']:
            for relation in model['relations']:
                if relation['target'] in nodes:
                    relation['needs_node'] = False
        # render templates
        dot += '\n' + template(body_template, graph)

    for graph in graphs:
        dot += '\n' + template(rel_template, graph)

    dot += '\n' + tail_template
    return dot
コード例 #7
0
ファイル: graph.py プロジェクト: 08haozi/uliweb
def generate_dot(tables, apps, **kwargs):
    from uliweb.orm import get_model, OneToOne, ReferenceProperty, ManyToMany
    from uliweb.core.template import template
    
    dot = head_template

    graphs = []
    for app in apps:
        graph = {
            'name': '"%s"' % app,
            'app_name': "%s" % app,
            'cluster_app_name': "cluster_%s" % app.replace('.', '_'),
#            'disable_fields': disable_fields,
            'use_subgraph': True,
            'models': []
        }

        t = get_model_tables(tables, app)
        if not t: continue
        for tablename in t:
            model = {
                'app_name': app.replace('.', '_'),
                'name': tablename,
#                'abstracts': abstracts,
                'fields': [],
                'relations': []
            }
            
            try:
                M = get_model(tablename)
            except:
                continue

            # consider given model name ?
#            def consider(model_name):
#                return not include_models or model_name in include_models
#
#            if not consider(appmodel._meta.object_name):
#                continue

#            if verbose_names and appmodel._meta.verbose_name:
#                model['label'] = appmodel._meta.verbose_name
#            else:
#                model['label'] = model['name']
            if getattr(M, '__verbose_name__', None):
                model['label'] = "%s(%s)" % (tablename, getattr(M, '__verbose_name__', None))
            else:
                model['label'] = tablename
            
            # model attributes
            def add_attributes(field):
                if field.verbose_name:
                    label = "%s(%s)" % (field.property_name, field.verbose_name)
                else:
                    label = "%s" % field.property_name
                    
                model['fields'].append({
                    'name': field.property_name,
                    'label': label,
                    'type': type(field).__name__,
                    'required': field.required,
#                    'abstract': field in abstract_fields,
                })
                    

            for k, field in M._fields_list:
                add_attributes(field)

            if M._manytomany:
                for k, field in M._manytomany.iteritems():
                    add_attributes(field)

            # relations
            def add_relation(field, extras="", rel=''):
                label = "%s(%s)" % (field.property_name, rel)
                    
                _rel = {
                    'target_app': field.reference_class.table.__appname__.replace('.', '_'),
                    'target': field.reference_class.tablename,
                    'type': type(field).__name__,
                    'name': field.property_name,
                    'label': label,
                    'arrows': extras,
                    'needs_node': True
                }
                if _rel not in model['relations']:
                    model['relations'].append(_rel)

            for k, field in M._fields_list:
                if field.__class__ is OneToOne:
                    add_relation(field, '[dir=both arrowhead=none arrowtail=none]', rel='1:1')
                elif field.__class__ is ReferenceProperty:
                    add_relation(field, rel='n:1')

            if M._manytomany:
                for k, field in M._manytomany.iteritems():
                    if field.__class__ is ManyToMany:
                        add_relation(field, '[dir=both arrowhead=normal arrowtail=normal]', rel='m:n')
            graph['models'].append(model)
        graphs.append(graph)

    nodes = []
    for graph in graphs:
        nodes.extend([e['name'] for e in graph['models']])

    for graph in graphs:
        # don't draw duplication nodes because of relations
        for model in graph['models']:
            for relation in model['relations']:
                if relation['target'] in nodes:
                    relation['needs_node'] = False
        # render templates
        dot += '\n' + template(body_template, graph)

    for graph in graphs:
        dot += '\n' + template(rel_template, graph)

    dot += '\n' + tail_template
    return dot