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


Python Project.to_dict方法代码示例

本文整理汇总了Python中models.Project.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Project.to_dict方法的具体用法?Python Project.to_dict怎么用?Python Project.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Project的用法示例。


在下文中一共展示了Project.to_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_project

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import to_dict [as 别名]
def update_project(project_id):
    """Updates the project matching the id project_id.
    Only the parameters to update or to add should be passed in the request body.
    """
    project = Project.objects(id=project_id).get()
    patched = Project(**dict(chain(project.to_dict().items(), request.get_json().items())))
    patched.save()

    return jsonify(patched.to_dict())
开发者ID:fendgroupproject,项目名称:backend,代码行数:11,代码来源:main.py

示例2: create_project

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import to_dict [as 别名]
    def create_project(self):
        if 'project_name' in self.request.POST:
            project_name = self.request.get('project_name').strip()
            hourly_rate = self.request.get('hourly_rate')

            if not project_name:
                self.response.set_status(400)
                self.response.write(json.dumps({'code': 12, 'error': 'Project name can\'t be only spaces'}))
                return

            if not hourly_rate:
                hourly_rate = '0'
            try:
                if not re.match("^[a-zA-Z0-9_\-\s]+$", project_name):
                    self.response.set_status(400)
                    self.response.write(json.dumps({'code': 13, 'error': 'Project name contains invalid characters'}))
                    return

                if not re.match(r"(\d+(\.\d*)?|\.\d+)", hourly_rate):
                    self.response.set_status(400)
                    self.response.write(json.dumps({'code': 14, 'error': 'Hourly rate is not a positive number or 0'}))
                    return
            except Exception as e:
                self.response.set_status(500)
                self.response.write(json.dumps({'code': 15, 'error': e.message}))
                return
            if len(project_name) > 25:
                self.response.set_status(400)
                self.response.write(json.dumps({'code': 16, 'error': 'Project name must be under 25 chars'}))
                return
            try:
                project = Project(parent=self.user.key)
                project = ProjectService.save_project(project, project_name, hourly_rate, self.user)
                proj = project.to_dict()
                proj['id'] = project.key.urlsafe()
                self.response.write(json.dumps({'project': proj}))

            except Exception as e:
                self.response.set_status(500)
                self.response.write(json.dumps({'code': 17, 'error': e.message}))
        else:
            self.response.set_status(400)
            self.response.write(json.dumps({'code': 18, 'error': 'Request doesn\'t contain a project_name'}))
        return
开发者ID:giovamo,项目名称:Sar,代码行数:46,代码来源:api.py

示例3: projects

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import to_dict [as 别名]
def projects():
    """Retrieves a list of projects from the database or create a new project.
    When retrieving a list of projects, the URL can contain pagination parameters
    page and per_page which default respectively to 1 and 10 if omitted.
    """
    if request.method == 'GET':
        return paginate(resource_name='projects', endpoint='projects', objects=Project.objects)

    json = request.get_json()

    author_id = json.get('author_id')
    if author_id is not None:
        assert_author_exists(json.get('author_id'))

    project = Project(**json)
    project.save()

    # Add the project in the list of the author projects.
    Author.objects(id=project.author_id).update_one(push__projects=project.id)

    return jsonify(project.to_dict()), 201
开发者ID:fendgroupproject,项目名称:backend,代码行数:23,代码来源:main.py


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