本文整理汇总了Python中tornado.util.ObjectDict类的典型用法代码示例。如果您正苦于以下问题:Python ObjectDict类的具体用法?Python ObjectDict怎么用?Python ObjectDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
data = self.application.data
lattice_ids = self.get_arguments("lattice")
if len(lattice_ids) < 2:
self.send_error(400, message="Must select two lattice for comparison")
return
lattice1 = yield data.find_lattice_by_id(lattice_ids[0])
if not lattice1:
self.send_error(400, message="Lattice (1) not found: " + lattice_ids[0])
return
lattice_elements1 = yield data.find_lattice_elements_by_lattice_id(lattice_ids[0])
lattice2 = yield data.find_lattice_by_id(lattice_ids[1])
if not lattice2:
self.send_error(400, message="Lattice (2) not found: " + lattice_ids[1])
return
lattice_elements2 = yield data.find_lattice_elements_by_lattice_id(lattice_ids[1])
ctx = ObjectDict()
ctx.lattice = (lattice1, lattice2)
n1 = len(lattice_elements1)
n2 = len(lattice_elements2)
ctx.lattice_elements = []
for idx in range(max(n1, n2)):
if idx < n1 and idx < n2:
ctx.lattice_elements.append((lattice_elements1[idx], lattice_elements2[idx]))
elif idx < n1:
ctx.lattice_elements.append((lattice_elements1[idx], None))
elif idx < n2:
ctx.lattice_elements.append((None, lattice_elements2[idx]))
ctx.particle_types = yield data.find_particle_types()
self.render("latticemodel/lattice_compare.html", **ctx)
示例2: get
def get(self):
ctx = ObjectDict()
ctx.search_active = True
ctx.search = ObjectDict()
data = self.application.data
ctx.particle_types = yield data.find_particle_types()
self.render("latticemodel/lattice_search.html", **ctx)
示例3: wrapper
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
logger.info(args)
logger.info(kwargs)
logger.info("====[EXIT]====")
# svc = args[0]
# # from code import interact
# # interact(local=locals())
# if isinstance(e, Exception):
# svc.db.rollback()
# logger.info("====[ROLLBACK]====")
# else:
# svc.db.commit()
# # svc.db.flush()
# logger.info("====[COMMIT]====")
# svc.db.remove()
# svc.db.close()
logger.info("====[CLOSE]====")
# svc = args[0]
# svc.db.close()
# svc.db.remove()
# logger.info(svc.db)
logThrown()
data = ObjectDict()
data.return_code = ERROR.system_err.errcode
data.return_message = e.__unicode__()
data.data = None
return data
示例4: read_meta
def read_meta(path):
"""
:param path: path for the theme.
:return: Theme meta read in path.
"""
if not os.path.exists(path):
return
meta = os.path.join(path, 'theme.py')
if not os.path.exists(meta):
logging.warn("%s is not a catsup theme." % path)
return
theme = ObjectDict(
name='',
author='',
homepage='',
pages=[],
has_index=False,
path=path,
vars={},
)
execfile(meta, {}, theme)
templates_path = os.path.join(path, 'templates')
for page in theme.pages:
if page == 'page.html':
theme.has_index = True
# If your theme does not have index page,
# catsup will rename page/1.html to page.html.
if not os.path.exists(os.path.join(templates_path, page)):
logging.warning("%s announces a page %s"
" which not exists." % (theme.name, page))
theme.name = theme.name.lower()
return theme
示例5: get_resources_by_status
def get_resources_by_status(self):
logger.info("\t ==========[ get_resources_by_status ]==========")
conditions = and_()
or_conditions = or_()
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.APPLIED)
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.CHECKED)
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.PAYED)
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.CONFIRMPAYED)
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.STARTED)
or_conditions.append(Pro_Resource_Apply.status == STATUS_RESOURCE.CLOSED)
conditions.append(or_conditions)
res_status = self.params.get("res_status")
if res_status:
conditions.append(Pro_Resource_Apply.status == res_status)
env_id = self.params.get("env_id", 0)
if env_id:
conditions.append(Pro_Info.env_id == env_id)
logger.info("\t [res_status]: %s" % res_status)
resource_list = self.db.query(
Pro_Resource_Apply
).outerjoin(
Pro_Info, Pro_Info.id == Pro_Resource_Apply.pro_id
).filter(
conditions
).order_by(
Pro_Resource_Apply.create_time.desc()
).all()
# 按状态查询申请数量
status_counts = self.db.query(
Pro_Resource_Apply.status, func.count(Pro_Resource_Apply.id)
).filter(
or_conditions
).group_by(
Pro_Resource_Apply.status
).all()
status_counts = dict(status_counts)
logger.info("status_counts: %s" % status_counts)
# 按环境查询申请数量
env_counts = self.db.query(
Pro_Info.env_id, func.count(Pro_Resource_Apply.id)
).outerjoin(
Pro_Resource_Apply, Pro_Resource_Apply.pro_id == Pro_Info.id
).outerjoin(
Env_Info, Env_Info.id == Pro_Info.env_id
).filter(
or_conditions
).group_by(
Env_Info.id
).all()
env_counts = dict(env_counts)
logger.info("env_counts: %s" % env_counts)
data = ObjectDict()
data.resource_list = resource_list
data.status_counts = status_counts
data.env_counts = env_counts
return self.success(data=data)
示例6: failures
def failures(self, failure_list, data=None):
result = ObjectDict()
result.return_code = ERROR.database_save_err.errcode
# result.return_message = u",".join(["(%s)%s" % (f.return_code, f.return_message) for f in failure_list])
result.return_message = u"\n,".join([f for f in failure_list])
result.return_messages = failure_list
result.data = data
return result
示例7: _create_upload_context
def _create_upload_context(self):
data = self.application.data
ctx = ObjectDict()
ctx.upload_active = True
ctx.particle_types = yield data.find_particle_types()
ctx.lattice_types = yield data.find_lattice_types()
ctx.lattice = ObjectDict(lattice_type=self.type)
ctx.lattice_autoversion = True
ctx.errors = ObjectDict()
raise Return(ctx)
示例8: read
def read(self, phone):
endpoint = self.selector(phone)
if endpoint == self.bemuch.endpoint:
if phone in self.phonebook:
item = ObjectDict(self.phonebook[phone])
item.phone = phone
return item
else:
raise tornado.web.HTTPError(404)
else:
item = yield self.bemuch.call(endpoint, 'read', phone)
return item
示例9: filter_list
def filter_list(self):
conditions = and_()
group_conditions = and_()
# if "pro_info.view" in self.handler.current_user.get_current_perms():
if not self.handler.current_user.imchecker:
conditions.append(Pro_Info.user_id == self.handler.current_user.id)
group_conditions.append(Pro_Info.user_id == self.handler.current_user.id)
env = self.params.get("env")
status = self.params.get("status")
if env:
conditions.append(Pro_Info.env_id == env)
if status:
conditions.append(Pro_Resource_Apply.status == status)
projects = self.db.query(
Pro_Info
).outerjoin(
Pro_Resource_Apply, Pro_Info.last_apply_id == Pro_Resource_Apply.id
).filter(
conditions
).order_by(
Pro_Info.id.desc()
).all()
# project_list = [i.as_dict() for i in projects]
# logger.info("project_list %s" % project_list)
# self.db.commit()
# self.db.remove()
projects_by_env = self.db.query(
Env_Info.id, Env_Info.name, func.count(Pro_Info.id)
).outerjoin(
Pro_Info, Env_Info.id == Pro_Info.env_id
).filter(
group_conditions
).group_by(
Env_Info.id
).all()
logger.info(projects_by_env)
projects_by_status = self.db.query(
Pro_Resource_Apply.status, func.count(Pro_Info.id)
).outerjoin(
Pro_Info, Pro_Resource_Apply.id == Pro_Info.last_apply_id
).filter(
group_conditions
).group_by(
Pro_Resource_Apply.status
).all()
logger.info(projects_by_status)
data = ObjectDict()
data.projects = projects
data.projects_by_env = projects_by_env
data.projects_by_status = projects_by_status
return self.success(data=data)
示例10: run_cmd
def run_cmd(self, payload):
host = payload['host']
request = ObjectDict(host=host)
request.track = ObjectDict(host=host)
uri = urlparse(payload['cmd'])
cmd = uri.path
if cmd == 'delete/module':
result = delete_module(request, parse_qs(uri.query)['name'])
log.debug('result: {0}'.format(result))
else:
raise HTTPServerError(title="command '{0}' is not supported".format(
cmd))
log.info('background processed command: {0}'.format(payload['cmd']))
示例11: respond
def respond(data, msg=None):
parser = feedparser.parse(options.feed_url)
articles = []
i = 0
for entry in parser.entries:
if i > 9:
break
article = ObjectDict()
article.title = entry.title
article.description = entry.description[0:100]
article.url = entry.link
article.picurl = ''
articles.append(article)
i += 1
return articles
示例12: __init__
def __init__(self):
settings = ObjectDict()
settings.debug = options.debug
settings.autoescape = None
self.base_dir = os.path.abspath(os.path.dirname(__file__))
settings.template_path = os.path.join(self.base_dir, 'templates')
handlers = [
(r'/', IndexHandler),
(r'/api/torrent/link', TorrentLinkHandler),
(r'/api/torrent/file', TorrentFileHandler),
(r'/api/torrent/bttiantang', TorrentBTTianTangHandler),
]
super(Application, self).__init__(handlers, **settings)
示例13: _find_user
def _find_user(self, account):
rs = self.db.query("SELECT * FROM users WHERE account=%s", account)
if not rs:
return None
r = rs[0]
d = copy.deepcopy(r)
d = ObjectDict(d)
d._id = d.id
del d['id']
del d['auth_time']
del d['ins_time']
d.user_no = str(d.user_no)
d.token = self._gen_token(d._id, d.user_no)
if d.ext_data:
d.ext_data = json.loads(d.ext_data)
d['class'] = 'user' # TODO class是python关键字,不建议用对象属性的方法赋值
return d
示例14: __init__
def __init__(self):
settings = ObjectDict()
settings.debug = options.debug
settings.autoescape = None
self.base_dir = os.path.abspath(os.path.dirname(__file__))
settings.template_path = os.path.join(self.base_dir, 'templates')
settings.static_path = os.path.join(self.base_dir, 'static')
handlers = [
(r'/', IndexHandler),
(r'/upload', IndexHandler),
(r'/myfile', MyFileHandler),
(r'/myfile/list', ListRemoteFileHandler),
(r'/myfile/delete', DeleteRemoteFileHandler),
]
super(Application, self).__init__(handlers, **settings)
示例15: _on_github_request
def _on_github_request(future, response):
""" Parse the JSON from the API """
if response.error:
print response.error
future.set_exception(
AuthError("Error response {0!s} fetching {1!s}".format(response.error, response.request.url)))
return
result = ObjectDict(code=response.code, headers=response.headers, body=None)
try:
result.body = json_decode(response.body)
except Exception:
gen_log.warning("Invalid JSON from Github: %r", response.body)
future.set_result(result)
return
future.set_result(result)