本文整理汇总了Python中models.Job.get_by_webid方法的典型用法代码示例。如果您正苦于以下问题:Python Job.get_by_webid方法的具体用法?Python Job.get_by_webid怎么用?Python Job.get_by_webid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Job
的用法示例。
在下文中一共展示了Job.get_by_webid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_job
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_webid [as 别名]
def get_job(job_id):
"""
Job Action
Get current job information
---
tags:
- printer
parameters:
- in: path
description: ID of the job
required: true
type: integer
name: id
responses:
200:
description: Returns current status of job
schema:
$ref: "#/definitions/Web_Job"
"""
job = Job.get_by_webid(job_id)
if job:
return json.jsonify(job.to_web())
else:
abort(404)
示例2: delete_job
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_webid [as 别名]
def delete_job(job_id):
"""
Delete Job Action
Stops and Deletes Job
---
tags:
- printer
parameters:
- in: path
type: integer
name: id
description: ID of the Job
required: true
responses:
200:
description: TODO
"""
job = Job.get_by_webid(job_id)
if job:
printer_id = job.printer_id
if printer_id != None:
printer = Printer.get_by_id(printer_id)
if printer != None:
if job.position == 0:
if printer.state("cancelled"):
printer.cancel_job()
payload = printer.to_web()
hub.Webapi.patch_printer(payload)
else:
printer.remove_job(job.id)
if job.state("cancelled"):
payload = job.to_web()
hub.Webapi.patch_job(payload)
return json.jsonify({"message": "Job " + str(job_id)
+ " has been deleted"}),200
示例3: jobs_post
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_webid [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