Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

commit miss?

  • Loading branch information...
commit cb276f996fbf7429fcf0745b126a2719a1530457 1 parent 228c0ef
root authored
Showing with 65 additions and 2 deletions.
  1. +65 −2 bookmarks_main.py
67 bookmarks_main.py
View
@@ -24,12 +24,75 @@ class Bookmark( db.Model ):
url = db.LinkProperty( required=True)
comment = db.TextProperty()
+class AddBookmark( webapp.RequestHandler ):
+ def get( self ):
+ """ Print Input Scroon.
+ """
+ path = os.path.join( os.path.dirname( __file__),
+ 'bookmark_add.html' )
+ self.response.out.write( template.render( path, None) )
+
+ def post( self, bookmark_id ):
+ """ Execute new input method, and move to Edit Screen.
+ """
+ url = self.request.POST['url']
+ title = self.request.POST['title']
+ bookmark = Bookmark( url=url, title=title )
+ bookmark.comment = self.request.POST['comment']
+ bookmark.put()
+ self.redirect( "/edit/%d/" % (bookmark.key().id() ) )
+
+class ListBookmark( webapp.RequestHandler ):
+ def get( self ):
+ bookmarks = Bookmark.all()
+ data = {'bookmarks': bookmarks }
+ path = os.path.join( os.path.dirname(__file__),
+ "bookmark_list.html" )
+ self.response.out.write( template.render( path, data ))
+
+class EditBookmark( webapp.RequestHandler ):
+ def get( self, bookmark_id ):
+ """ Print Edit screen.
+ """
+ bookmark = Bookmark.get_by_id( bookmark_id )
+ data = {
+ 'bookmark': bookmark,
+ }
+ path = os.path.join( os.path.dirname(__file__), 'book_edit.html' )
+ self.response.out.write( template.render( path, data ) )
+
+ def post( self, bookmark_id ):
+ """Update data, and move List screen
+ """
+ bookmark = get_bookmark_by_id( bookmark_id )
+ bookmark.url = self.request.POST['url']
+ bookmark.title = self.request.POST['title']
+ bookmark.comment = self.request.POST['comment']
+ bookmark.put()
+ sef.redirect("/")
+
+class DeleteBookmark( webapp.RequestHandler ):
+ def post( self, bookmark_id ):
+ bookmark = Bookmark.get_by_id( bookmark_id )
+ if bookmark:
+ bookmark.delete()
+ self.redirect("/")
+
def main():
application = webapp.WSGIApplication( [
- ( '/', MainPage),
- ], debug=True )
+ ( '/', ListBookmark ), # All Bookmarks Brawse.
+ ( '/add/', AddBookmark), # New Input Screen.
+ ( '/edit/(\d+)/', EditBookmark), # Edit Screen.
+ ( '/delete/(\d+)/', DeleteBookmark), # Delete method.
+ ],debug=True )
wsgiref.handlers.CGIHandler().run( application )
+
+# application = webapp.WSGIApplication( [
+# ( '/', MainPage),
+# ], debug=True )
+# wsgiref.handlers.CGIHandler().run( application )
+
if __name__ == '__main__':
main()
Please sign in to comment.
Something went wrong with that request. Please try again.