@@ -19,22 +19,23 @@ def remove(postid):
19
19
afterdelete = "Post successfully deleted"
20
20
redirect (url_for ("home" ))
21
21
return render_template ("index.html" ,posts = Post .select ().order_by (Post .date_posted .desc ()),after = afterdelete ,count = len (Post .select ().order_by (Post .date_posted .desc ())))
22
- @app .route ("/<username >/edit" ,methods = ['POST' ,'GET' ])
23
- def edituser (username ):
22
+ @app .route ("/<postid >/edit" ,methods = ['POST' ,'GET' ])
23
+ def edituser (postid ):
24
24
error = ""
25
- success = "The record <strong><em>{}</strong></em> was successfully update" .format (username )
26
- if username not in users :
27
- return render_template ("404.html" )
25
+ success = "The record was successfully updated"
26
+ post = Post .get (Post .id == postid )
28
27
if request .method == "POST" :
29
- newusername = request .form ['username' ].strip ()
30
- if (newusername == "" ):
31
- error = "Please give us a username"
28
+ newtitle = request .form ['title' ].strip ()
29
+ newcontent = request .form ['content' ].strip ()
30
+ if (newtitle == "" or newcontent == "" ):
31
+ error = "Please provide a title and content before saving"
32
32
else :
33
- if username not in users :
34
- return render_template ("404.html" )
35
- users [users .index (username )]= newusername
33
+ post .title = newtitle
34
+ post .content = newcontent
35
+ post .date_posted = datetime .datetime .now ()
36
+ post .save ()
36
37
return redirect (url_for ('home' ,success = success ))
37
- return render_template ("view.html" ,user = username ,error = error )
38
+ return render_template ("view.html" ,post = post ,error = error )
38
39
@app .route ("/user/new" ,methods = ["POST" ,"GET" ])
39
40
def newuser ():
40
41
error = None
0 commit comments