class BlobField(Field): """ 保存Blob类型字段的属性 """ def __init__(self, **kw): if 'default' not in kw: kw['default'] = '' if 'ddl' not in kw: kw['ddl'] = 'blob' super(BlobField, self).__init__(**kw) class VersionField(Field): """ 保存Version类型字段的属性 """ def __init__(self, name=None): super(VersionField, self).__init__(name=name, default=0, ddl='bigint') if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) dbHandler.create_engine('root', '123456', 'test', '127.0.0.1') dbHandler.update('drop table if exists user') dbHandler.update('create table user (id int primary key, name text, email text, passwd text, last_modified real)') import doctest doctest.testmod()
# init database def datetime_filter(t): delta = int(time.time() - t) if delta < 60: return u"1分钟前" if delta < 3600: return u"%s分钟前" % (delta // 60) if delta < 86400: return u"%s小时前" % (delta // 3600) if delta < 604800: return u"%s天前" % (delta // 86400) dt = datetime.fromtimestamp(t) return u"%s年%s月%s日" % (dt.year, dt.month, dt.day) dbHandler.create_engine(**configs.db) # create a WSGIApplication: wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__))) template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")) template_engine.add_filter("datetime", datetime_filter) wsgi.template_engine = template_engine import urls wsgi.add_module(urls) if __name__ == "__main__":