File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -86,3 +86,20 @@ def edit_profile_admin(id):
86
86
def post (id ):
87
87
post = Post .query .get_or_404 (id )
88
88
return render_template ('post.html' , posts = [post ])
89
+
90
+
91
+ @main .route ('/edit/<int:id>' , methods = ['GET' , 'POST' ])
92
+ @login_required
93
+ def edit (id ):
94
+ post = Post .query .get_or_404 (id )
95
+ if current_user != post .author and \
96
+ not current_user .can (Permission .ADMINISTER ):
97
+ abort (403 )
98
+ form = PostForm ()
99
+ if form .validate_on_submit ():
100
+ post .body = form .body .data
101
+ db .session .add (post )
102
+ flash ('The post has been updated.' )
103
+ return redirect (url_for ('.post' , id = post .id ))
104
+ form .body .data = post .body
105
+ return render_template ('edit_post.html' , form = form )
Original file line number Diff line number Diff line change 17
17
{% endif %}
18
18
</ div >
19
19
< div class ="post-footer ">
20
+ {% if current_user == post.author %}
21
+ < a href ="{{ url_for('.edit', id=post.id) }} ">
22
+ < span class ="label label-primary "> Edit</ span >
23
+ </ a >
24
+ {% elif current_user.is_administrator() %}
25
+ < a href ="{{ url_for('.edit', id=post.id) }} ">
26
+ < span class ="label label-danger "> Edit [Admin]</ span >
27
+ </ a >
28
+ {% endif %}
20
29
< a href ="{{ url_for('.post', id=post.id) }} ">
21
30
< span class ="label label-default "> Permalink</ span >
22
31
</ a >
Original file line number Diff line number Diff line change
1
+ {% extends "base.html" %}
2
+ {% import "bootstrap/wtf.html" as wtf %}
3
+
4
+ {% block title %}Flasky - Edit Post{% endblock %}
5
+
6
+ {% block page_content %}
7
+ < div class ="page-header ">
8
+ < h1 > Edit Post</ h1 >
9
+ </ div >
10
+ < div >
11
+ {{ wtf.quick_form(form) }}
12
+ </ div >
13
+ {% endblock %}
14
+
15
+ {% block scripts %}
16
+ {{ super() }}
17
+ {{ pagedown.include_pagedown() }}
18
+ {% endblock %}
You can’t perform that action at this time.
0 commit comments