Measuring open the road to one hundred thirty-two: Implement editing

 

 

Achieve editing functions

 

Implementation steps:

1. Bind view function edit button
2. Click the Edit button to jump to the edit page, and renders the original content
3. Edit, submit
4. warehousing, updates, new content rendering

 

1, binding view of the edit button function:

app.route @ ( "/ Edit / <ID> /") 
DEF Edit (ID = None):
"" "The front end of the edit return pass over HTML ID" ""
return the render_template ( 'edit.html')

 

 

html editor button binding function

The extends% { 'base.html'%} 

{%}% Block main_content
<div class = "Row">
<Table class = "Table Table-hover">
<TR>
<TH> ID </ TH>
<TH> topic </ TH>
<TH> Category </ TH>
<TH> user </ TH>
<TH> mailbox </ TH>
<TH> processing status </ TH>
<TH> submitted </ TH>
<TH> operation </ TH>
</ TR>
{%}% for items in Item
<TR>
<TD> loop.index {{}} </ TD> <-! traverse ID function provided template jinja ->
<td>{{ item[1] }}</td>
<td>{{ item[2] }}</td>
<td>{{ item[3] }}</td>
<td>{{ item[4] }}</td>
<td><span class="label label-{{ 'danger' if item[7] ==0 else 'success' }}">{{ "未处理" if item[7] ==0 else "已处理" }}</span></td>
<td>{{ item[9] }}</td>
<td>
<a href="#" class="btn btn-success">查看</a>
<a href="{{ url_for('edit', id=item[0]) }}" class="btn btn-default">编辑</a>
<a href="{{ url_for('delete_feedback', id=item[0]) }}" class="btn btn-danger">删除</a>
</td>
</tr>
{% endfor %}
</table>
</div>

{% endblock %}

 

New edit.html

<!--继承base.html-->
{% extends 'base.html' %}

<!--引用base.html预留的正文部分-->
{% block main_content %}
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h4>问题反馈信息编辑</h4>
</div>
<div class="panel-body">
<form action="#" method="POST" class="form-horizontal">
<div class="form-group">
<label for="subject" class="control-label col-md-2">主题</label>
<div class="col-md-6">
<input type="text" class="form-control" id="subject" name="subject">
</div>
</div>
<div class="form-group">
<label for="category" class="control-label col-md-2">问题分类</label>
<div class="col-md-2">
<select name="category" id="category" class="form-control">
<option value="1">产品质量</option>
<option value="2">客户服务</option>
<option value="3">购买支付</option>
</select>
</div>
</div>
<div class="form-group">
<label for="username" class="control-label col-md-2">姓名</label>
<div class="col-md-2">
<input type="text" class="form-control" id="username" name="username">
</div>
</div>
<div class="form-group">
<label for="email" class="control-label col-md-2">邮箱</label>
<div class="col-md-6">
<input type="text" class="form-control" id="email" name="email">
</div>
</div>
<div class="form-group">
<label for="image" class="control-label col-md-2">图片</label>
<div class="col-md-6">
<input type="file" id="image" name="image">
</div>
</div>

<div class="form-group">
<label for="body" class="control-label col-md-2">内容</label>
<div class="col-md-6">
<textarea name="body" id="body" cols="30" rows="10" class="form-control"></textarea> <div class = "form-Group"> <-! increase reply, release time and processing status -> </ div>
</ div>



<label for="reply" class="control-label col-md-2">回复</label>
<div class="col-md-6">
<textarea name="reply" id="reply" cols="30" rows="10" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<label for="releasetime" class="control-label col-md-2">发布时间</label>
<div class="col-md-6">
<input type="text" name="releasetime" id="releasetime" class="form-control">
</div>
</div>
<div class="form-group">
<label for="state" class="control-label col-md-2">处理状态</label>
<div class="col-md-6">
<input type="checkbox" name="state" id="state">
</div>
</div>

<div class="col-md-offset-2">
<input type="submit" class="btn btn-primary" value="提交">
<input type="reset" class="btn btn-default" value="重置">
</div>
</form>
</div>
<div class="panel-footer">

</div>
</div>
</div>

{% endblock %}

Look at the results

 

 

 

2, obtain and render the original content

app.route @ ( "/ Edit / <ID> /") 
DEF Edit (ID = None):
"" "The front end of the edit return pass over HTML ID" ""
Conn = sqlite3.connect (DATABASE)
C = Conn .cursor ()

# get the drop-down list bound
SQL = "the SELECT the ROWID, the CategoryName from category"
the Categories = c.execute (SQL) .fetchall ()

# get the current id information, and bind to form a form to prepare for modification
= SQL "the SELECT the ROWID, the WHERE * Feedback from the ROWID =?"
curren_feedback = c.execute (SQL, (the above mentioned id,)). fetchone ()

conn.Close ()
# return str (curren_feedback) # View check out the data sequence, html rendering easy sorting
return render_template ( 'edit.html', categories = categories, item = curren_feedback)

 

edit.html

<!--继承base.html-->
{% extends 'base.html' %}

<!--引用base.html预留的正文部分-->
{% block main_content %}
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h4>问题反馈信息编辑</h4>
</div>
<div class="panel-body">
<form action="#" method="POST" class="form-horizontal">
<div class="form-group">
<label for="subject" class="control-label col-md-2">主题</label>
<class = div "COL-md-6">
<-! Render Theme ->
<input type="text" value="{{ item[1] }}" class="form-control" id="subject" name="subject">
</div>
</div>
<div class="form-group">
<label for="category" class="control-label col-md-2">问题分类</label>
<div class="col-md-2">
<select name="category" id="category" class="form-control">
<!--显示当前问题的问题分类-->
{% for category in categories %}
<option {{ 'selected=selected' if item[2]==category[0] else '' }} value="{{ category[0] }}">{{ category[1] }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label for="username" class="control-label col-md-2">姓名</label>
<div class="col-md-2">
<!--渲染姓名-->
<input type="text" class="form-control" value="{{ item[3] }}" id="username" name="username">
</div>
</div>
<div class="form-group">
<label for="email" class="control-label col-md-2">邮箱</label>
<div class="col-md-6">
<!--渲染邮箱-->
<input type="text" class="form-control" value="{{ item[4] }}" id="email" name="email">
</div>
</div>
<div class="form-group">
<label for="image" class="control-label col-md-2">图片</label>
<div class="col-md-6">
<input type="file" id="image" name="image">
</div> <-! Render Content -> <div class = "form-Group">
</ div>



<label for="body" class="control-label col-md-2">内容</label>
<div class="col-md-6">
<textarea name="body" id="body" cols="30" rows="10" class="form-control">{{ item[6] }}</textarea>
</div>
</div>
<!--增加回复内容、发布时间和处理状态-->
<div class="form-group">
<label for="reply" class="control-label col-md-2">回复</label>
<div class="col-md-6">
<!--渲染回复-->
<textarea name="reply" id="reply" cols="30" rows="10" class="form-control">{{ item[8] if item[8] }}</textarea>
</div>
</div>
<div class="form-group">
<label for="releasetime" class="control-label col-md-2">发布时间</label>
<div class="col-md-6">
<input type="text" value="{{ item[9] }}" name="releasetime" id="releasetime" class="form-control">
</div>
</div>
<div class="form-group">
<label for="state" class="control-label col-md-2">处理状态</label> <-! rendering state ->
<div class = ". 6-COL-MD">

<input type="checkbox" name="state" id="state" {{ 'checked=checked' if item[7] == 1 else ''}} >
</div>
</div>

<div class="col-md-offset-2">
<input type="submit" class="btn btn-primary" value="提交">
<input type="reset" class="btn btn-default" value="重置">
</div>
</form>
</div>
<div class="panel-footer">

</div>
</div>
</div>

{% endblock %}

 

Automatic rendering to access

 

 

 

Save Edit View

@app.route("/save_edit/", methods=['POST'])
def save_edit():
""" 保存编辑 """
if request.method == 'POST':
id = request.form.get('rowid', None)
reply = request.form.get('reply')
state = 1 if request.form.get('state', 0) == 'on' else 0
sql = 'update feedback set Reply=?, State=? where rowid=?'
conn = sqlite3.connect(DATABASE)
c = conn.cursor()
c.execute(sql, (reply, state, id))
conn.commit()
conn.close()
return redirect(url_for('list'))

 

 

edit.html

<!--继承base.html-->
{% extends 'base.html' %}

<!--引用base.html预留的正文部分-->
{% block main_content %}
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h4>问题反馈信息编辑</h4>
</div>
<div class="panel-body">
<!--保存的url-->
<form action="{{ url_for('save_edit') }}" method="POST" class="form-horizontal">
<div class="form-group">
<label for="subject" class="control-label col-md-2 "> theme </ label> <-! Render Theme ->
<div class =" COL-md-6 ">

<input type="text" value="{{ item[1] }}" class="form-control" id="subject" name="subject">
<!--拿到id,不渲染,用于保存的时候做sql条件-->
<input type="hidden" value="{{ item[0] }}" class="form-control" id="rowid" name="rowid">
</div>
</div>
<div class="form-group">
<label for="category" class="control-label col-md-2">问题分类</label>
<div class="col-md-2">
<name = the SELECT "category" the above mentioned id = "category" class = "form-Control">
<-! displays the current issue of classification issues ->
{% for category in categories %}
<option {{ 'selected=selected' if item[2]==category[0] else '' }} value="{{ category[0] }}">{{ category[1] }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label for="username" class="control-label col-md-2">姓名</label>
<div class="col-md-2">
<!--渲染姓名-->
<input type="text" class="form-control" value="{{ item[3] }}" id="username" name="username">
</div>
</div>
<div class="form-group">
<label for="email" class="control-label col-md-2">邮箱</label>
<div class="col-md-6">
<!--渲染邮箱-->
<input type="text" class="form-control" value="{{ item[4] }}" id="email" name="email">
</div>
</div>
<div class="form-group">
<label for="image" class="control-label col-md-2">图片</label>
<div class="col-md-6">
<input type="file" id="image" name="image">
</ div>
</ div>

<div class = "form-Group">
<-! Render Content ->
<label for = "body" class = "label Control-COL-MD-2"> SUMMARY </ label>
<div class = "COL-MD-. 6">
<TextArea name = "body" ID = "body" cols = "30" rows = "10" class = "form-Control"> {{Item [. 6] }} </ TextArea>
</ div>
</ div>
<-! reply increase release time and processing state ->
<div class = "form-Group">
<label for="reply" class="control-label col-md-2">回复</label>
<div class="col-md-6">
<!--渲染回复-->
<textarea name="reply" id="reply" cols="30" rows="10" class="form-control">{{ item[8] if item[8] }}</textarea>
</div>
</div>
<div class="form-group">
<label for="releasetime" class="control-label col-md-2">发布时间</label>
<div class="col-md-6">
<input type="text" value="{{ item[9] }}" name="releasetime" id="releasetime" class="form-control">
</div>
</div>
<div class="form-group">
<label for="state" class="control-label col-md-2">处理状态</label>
<div class="col-md-6">
<!--渲染处理状态-->
<input type="checkbox" name="state" id="state" {{ 'checked=checked' if item[7] == 1 else ''}} >
</div>
</div>

<div class="col-md-offset-2">
<input type="submit" class="btn btn-primary" value="提交">
<input type="reset" class="btn btn-default" value="重置"> <a href="{{ url_for('list') }} "class="btn btn-default"> Click back to list page </ a>
<! - If you do not want to modify, click the Back to the list page ->

</div>
</form>
</div>
<div class="panel-footer">

</div>
</div>
</div>

{% endblock %}

 

Edit it

Original state

edit

submit 

 

 

Guess you like

Origin www.cnblogs.com/zhongyehai/p/11456547.html