def _clean_collection(self, existlinks): from uliweb.utils.sorteddict import SortedDict r = {'toplinks': SortedDict(), 'bottomlinks': SortedDict()} #process links, link could be (order, link) or link for _type in ['toplinks', 'bottomlinks']: t = self.links.get(_type, []) for link in t: #link will also be template string if '{{' in link and '}}' in link: #link = template(link, self.env) raise TemplateDefineError( "Can't support tag {{}} in links") #process static combine if isinstance(link, dict): link_key = link.get('value') link_value = link.copy() link_value.pop('value') else: link_key = link link_value = {} if link_key.endswith('.js') or link_key.endswith('.css'): _link = functions.url_for_static(link_key) else: _link = link_key if not link_key in r[_type] and not _link in existlinks: link_value['link'] = _link r[_type][link_key] = link_value existlinks.append(_link) return r
def p(menus, tab=0): print ' '*tab + menus['name'], if title or verbose: txt = '[' + menus.get('title', menus['name']) + ']' else: txt = '' if verbose: d = SortedDict() for x in ['id', 'link']: if menus.get(x): d[x] = menus.get(x) txt += ' {%s}' % (','.join(['%s="%s"' % (x, y) for x, y in d.items()])) print txt for x in menus.get('subs', []): p(x, tab+4)
def p(menus, tab=0): print ' '*tab + menus['name'], if title or verbose: txt = '[' + menus.get('title', menus['name']) + ']' else: txt = '' if verbose: d = SortedDict() for x in ['id', 'link']: if menus.get(x): d[x] = menus.get(x) txt += ' {%s}' % (','.join(['%s="%s"' % (x, y) for x, y in d.items()])) print txt for x in menus.get('subs', []): p(x, tab+4)
def make_form(fields=None, layout=None, layout_class=None, base_class=None, get_form_field=None, name=None, rules=None, **kwargs): """ Make a from according dict data: {'fields':[ {'name':'name', 'type':'str', 'label':'label, 'rules':{ 'required': 'email' 'required:back|front' #back means server side, front means front side } ...}, ... ], #layout_class should be defined in settings.ini, just like #[FORM_LAYOUT_CLASSES] #bs3 = '#{appname}.form_help.Bootstrap3Layout' #is also can be a Layout Class #default is BootstrapLayout 'layout_class':'bs3', 'layout':{ 'rows':[ '-- legend title --', 'field_name', ['group_fieldname', 'group_fieldname'] {'name':'name', 'colspan':3} ], } 'base_class':'form class if not existed, then use Form' } get_form_field is a callback function, used to defined customized field class if has name then it'll be cached """ from uliweb.utils.sorteddict import SortedDict get_form_field = get_form_field or (lambda name, f:None) #make fields props = SortedDict({}) for f in fields or []: if isinstance(f, BaseField): props[f.name] = get_form_field(f.name, f) or f else: props[f['name']] = get_form_field(f['name'], f) or make_field(**f) #set other props if layout: props['layout'] = layout if layout_class: props['layout_class'] = layout_class if rules: props['rules'] = rules layout_class_args = kwargs.pop('layout_class_args', None) if layout_class_args: props['layout_class_args'] = layout_class_args cls = type(name or 'MakeForm_', (base_class or Form,), props) return cls
def get_jobs(): global jobs jobs = SortedDict() Job = functions.get_model('cron_job') for row in Job.filter(Job.c.enabled == True): jobs[row.id] = row
def reflect_column(column): type_name = column.type.__class__.__name__.lower() kwargs = SortedDict() field_type = type_name if type_name in ('char', 'varchar'): kwargs['max_length'] = column.type.length elif type_name in ('text', 'blob', 'integer', 'float', 'bigint'): pass elif type_name == 'long': field_type = 'bigint' elif type_name in ('clob',): field_type = 'text' elif type_name in ('decimal', 'float'): kwargs['precision'] = column.type.precision kwargs['scale'] = column.type.scale elif type_name == 'raw': # oracle field_type = 'binary' kwargs['max_length'] = column_type.length elif type_name == 'number': if column.type.scale: kwargs['precision'] = column.type.precision kwargs['scale'] = column.type.scale field_type = 'decimal' else: field_type = 'int' elif type_name == 'numeric': field_type = 'decimal' kwargs['precision'] = column.type.precision kwargs['scale'] = column.type.scale elif type_name in ('timestamp',): field_type = 'timestamp' elif type_name in ('datetime', 'date', 'time'): pass # for tinyint will be treated as bool elif type_name in ('tinyint', 'boolean'): field_type = 'bool' else: raise ValueError("Don't support column [{0}] for type [{1}] when parsing {2}".format(column.name, type_name, column.table.name)) if sa_version >= '1.2' and column.comment: kwargs['label'] = column.comment if not kwargs.get('label'): kwargs['label'] = column.name return field_type, kwargs
def _clean_collection(self, existlinks): from uliweb.utils.sorteddict import SortedDict r = {'toplinks': SortedDict(), 'bottomlinks': SortedDict()} #process links, link could be (order, link) or link for _type in ['toplinks', 'bottomlinks']: t = self.links.get(_type, []) for link in t: #link will also be template string if '{{' in link and '}}' in link: #link = template(link, self.env) raise TemplateDefineError( "Can't support tag {{}} in links") #process static combine if isinstance(link, dict): link_key = link.get('value') link_value = link.copy() link_value.pop('value') else: link_key = link link_value = {} new_link = __static_mapping__.get(link_key, link_key) if new_link.endswith('.js') or new_link.endswith('.css'): _link = functions.url_for_static(new_link) else: _link = new_link if not new_link in r[_type] and not _link in existlinks: link_value['link'] = _link _js_file, ext = os.path.splitext(new_link) if new_link in __static_combine__ and ext == '.js': _css_file = _js_file + '.css' if _css_file in __static_combine__: _new_link_value = link_value.copy() _new_link_value['link'] = functions.url_for_static( _css_file) r[_type][_css_file] = _new_link_value r[_type][new_link] = link_value existlinks.append(_link) return r
from __future__ import print_function, absolute_import, unicode_literals import os import re import inspect from uliweb.utils.common import log from uliweb.utils.sorteddict import SortedDict import copy from ..utils._compat import string_types, iterkeys, ismethod, isfunction, get_class class ReservedKeyError(Exception): pass __exposes__ = SortedDict() __no_need_exposed__ = [] __class_methods__ = {} __app_rules__ = {} __url_route_rules__ = [] __url_names__ = {} static_views = [] reserved_keys = [ 'settings', 'redirect', 'application', 'request', 'response', 'error', 'json' ] def add_rule(map, url, endpoint=None, **kwargs): from werkzeug.routing import Rule kwargs['endpoint'] = endpoint
from __future__ import print_function, absolute_import, unicode_literals __version__ = '1.0' __url__ = '' __author__ = 'limodou' __email__ = '*****@*****.**' import os from copy import deepcopy from uliweb.utils.sorteddict import SortedDict from uliweb.utils.common import import_attr from uliweb.utils._compat import string_types, u __menus__ = SortedDict() __menu_items__ = {} #saving item to parent relation _menu_order = 9000 class MenuException(Exception): pass def load_menu(menus): """ Load menu definitions """ global __menus__, __menu_items__ __menus__.clear() __menu_items__.clear() _m = [] _menu_names = set() #each menu item should has unique name
import sys import re from uliweb import functions from uliweb.orm import Begin, Commit, Rollback import logging from uliweb.utils import date from uliweb.utils.sorteddict import SortedDict import datetime import time import signal import bisect log = logging.getLogger(__name__) is_exit = False jobs = SortedDict() jobs_time = [] def handler(signum, frame): global is_exit is_exit = True print("Process %d received a signal %d" % (os.getpid(), signum)) sys.exit(0) def get_jobs(): global jobs jobs = SortedDict() Job = functions.get_model('cron_job')