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


Python Project.update方法代码示例

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


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

示例1: editProject

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import update [as 别名]
def editProject(project):
    res = {}
    res['result'] = 1
    res['message'] = ''

    if Project.update({'id': project['id']}, {"$set": project}):
        res['message'] = 'success'
    else:
        res['result'] = 0
        res['message'] = 'Fail to modify project!'

    return res
开发者ID:EmbeddedSoftwareCaiShuPeng,项目名称:vehicleDispatcher,代码行数:14,代码来源:ProjectAccess.py

示例2: single_project

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import update [as 别名]
def single_project(project_id):
    if request.method == "POST" and request.form and request.form['_method']:
        if authenticate():
            if request.form['_method'] == "PUT" or request.form['_method'] == "PATCH":
                post = request.form
                error = False
                title = request.form['title'].strip() if request.form['title'] != None else None
                if title:
                    if re.search("^[ a-zA-Z0-9\,\?\!]+$", title) == None:
                        flash('Invalid characters detected in title')
                        error = True
                else:
                    flash('Title cannot be empty')
                    error = True
                title_desc = request.form['title_desc'].strip()
                if title_desc:
                    title_desc = title_desc.replace("\r","")
                    num_matches = len(re.findall("^[ a-zA-Z0-9\.\?\,\!/]+$",title_desc,re.MULTILINE))
                    num_lines = len(list(filter(remove_blanks,title_desc.split("\n"))))
                    if num_matches != num_lines:
                        flash('Invalid characters detected in title description')
                        error = True
                else:
                    flash('Title description cannot be blank')
                    error = True
                description = request.form['description'].strip()
                if description:
                    regex = re.compile("^[ a-zA-Z0-9\.\?\,\!]+$", re.MULTILINE)
                    description = description.replace("\r","")
                    num_matches = len(regex.findall(description))
                    num_lines = len(list(filter(remove_blanks,description.split("\n"))))
                    if num_matches != num_lines:
                        flash('Invalid characters detected in project description')
                        error = True
                    if not error:
                        try:
                            q = Project.update(
                                title=request.form['title'],
                                title_desc=request.form['title_desc'],
                                description=request.form['description']
                            ).where(Project.id == project_id)
                            q.execute()
                        except IntegrityError:
                            flash('That title is already taken')
                            error = True
                        except Project.DoesNotExist:
                            return redirect(url_for('projects'))
                else:
                    flash('Project description cannot be empty')
                    error = True
    
                if error:
                    return render_template('projects/edit.html', project=project)
                else:
                    return redirect(url_for('single_project', project_id=project_id))
            elif request.form['_method'] == "DELETE":
                try:
                    project = Project.get(Project.id == project_id)
                    project.delete_instance()
                    flash('Successfully deleted the project')
                    return redirect(url_for('projects'))
                except Project.DoesNotExist:
                    return redirect(url_for('projects'))
    
            else:
                abort(405)
        else:
            flash('Not authorized to do that')
            return redirect(url_for('projects'))
    else:
        try:
            project = Project.get(Project.id == project_id)
            tags = ""
            learned_points = ""
            if project.tags:
                tags = project.tags.split(',')
            if project.learned:
                learned_points = project.learned.replace('+',',')
                learned_points = learned_points.split(",")
            return render_template('projects/show.html', project=project, tags=tags, learned_points=learned_points)
        except Project.DoesNotExist:
            return redirect(url_for('projects'))
开发者ID:brendanWeb,项目名称:old-brendanhenderson.com,代码行数:84,代码来源:views.py


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