当前位置: 首页>>代码示例>>Python>>正文


Python Job.to_web方法代码示例

本文整理汇总了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
开发者ID:StratusPrint,项目名称:HUB,代码行数:65,代码来源:printers.py


注:本文中的models.Job.to_web方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。