本文整理汇总了Python中models.Job.to_web方法的典型用法代码示例。如果您正苦于以下问题:Python Job.to_web方法的具体用法?Python Job.to_web怎么用?Python Job.to_web使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Job
的用法示例。
在下文中一共展示了Job.to_web方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jobs_post
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import to_web [as 别名]
def jobs_post(id):
"""
Add a Job
Add job to printer
---
tags:
- printer
parameters:
- in: path
description: ID of the printer
required: true
type: integer
name: id
- in: body
description: Job to add to the printer
required: true
name: Job
schema:
$ref: "#/definitions/Web_Job"
responses:
201:
description: returns "(job) has been uploaded successfully"
400:
description: no file was provided
404:
description: printer isn't found
"""
printer = Printer.get_by_webid(id)
if printer == None:
abort(404)
id = printer.id
f = request.files.get('file', None)
if f:
webid = request.form.get('id')
job = Job.get_by_webid(webid)
if not job:
job = Job(int(webid))
ext = f.filename.rsplit(".", 1)[1]
name = str(job.id) + "." + ext
fpath = os.path.join(app.config['UPLOAD_FOLDER'],name)
f.save(fpath)
file = File(f.filename, fpath)
job.set_file(file)
elif job.file == None:
ext = f.filename.rsplit(".", 1)[1]
name = str(job.id) + "." + ext
fpath = os.path.join(app.config['UPLOAD_FOLDER'],name)
f.save(fpath)
file = File(f.filename, fpath)
job.set_file(file)
printer = Printer.get_by_id(id)
printer.add_job(job)
t = threading.Thread(target=hub.Webapi.patch_job,
args=(job.to_web(),))
t.start()
# if printer.current_job().id == job.id:
# t = Command(printer.id, hub.log, "start",
# hub.Webapi)
# t.start()
else:
abort(400)
return json.jsonify({"message": "Job " + str(webid)
+ " has been uploaded successfully"}),201