當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。