Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated with docstrings for PEP8 compliance.

  • Loading branch information...
commit b6784224c9e394a56d1b24df1b1a95b1d05c9d7a 1 parent 14115a6
@dhermes dhermes authored
Showing with 40 additions and 16 deletions.
  1. +18 −8 suggest_cursor.py
  2. +22 −8 suggest_unique.py
View
26 suggest_cursor.py
@@ -20,8 +20,8 @@
provided for queries.
"""
+
from google.appengine.ext import ndb
-from google.appengine.ext.webapp.util import login_required
import webapp2
from base_handler import BaseHandler
@@ -52,13 +52,19 @@ def populate(cls, num_values=PAGE_SIZE + 1):
class SuggestionByCursorHandler(BaseHandler):
- """
- Handles the creation of a single Suggestion, and the display
- of suggestions broken into PAGE_SIZE pages.
+ """Handles the insert of a suggestion and display of existing suggestions.
+
+ The GET handler is intended for general display and paging and the POST
+ handler is used for inserting new suggestions.
"""
- @login_required
def get(self):
+ """Handles GET requests to the paging by cursors sub-application.
+
+ If there is a bookmark value in the query parameters, uses it to create
+ a cursor and page using it. Includes up to PAGE_SIZE results and a link
+ to the next page of results if any more exist.
+ """
cursor = None
bookmark = self.request.get('bookmark')
if bookmark:
@@ -76,16 +82,20 @@ def get(self):
suggestions=suggestions)
def post(self):
+ """Handles POST requests for inserting a single suggestion."""
SuggestionByCursor(suggestion=self.request.get('suggestion')).put()
self.redirect('/cursor/')
class SuggestionByCursorPopulate(BaseHandler):
+ """Populates the datastore with some sample suggestions
+
+ Provided so end users can pre-populate with PAGE_SIZE + 1 entities to see
+ how cursor-based paging works.
"""
- Handles populating the datastore with some sample
- Suggestions to see how the paging works.
- """
+
def post(self):
+ """Handles POST requests and adds sample suggestions."""
SuggestionByCursor.populate()
self.redirect('/cursor/')
View
30 suggest_unique.py
@@ -16,13 +16,12 @@
"""Suggestion Box - An example paging application.
-A simple Suggestion Box application that demonstrates
-paging by creating a unique value for each suggestion. The
-uniqueness is created by sharding counters across
-all the users of the system.
-
+A simple Suggestion Box application that demonstrates paging by creating a
+unique value for each suggestion. The uniqueness is created by sharding
+counters across all the users of the system.
"""
+
import datetime
import hashlib
@@ -110,13 +109,21 @@ class Suggestion(SuggestionByCursor):
class SuggestionHandler(BaseHandler):
- """
- Handles the creation of a single Suggestion, and the display
- of suggestions broken into PAGE_SIZE pages.
+ """Handles the insert of a suggestion and display of existing suggestions.
+
+ The GET handler is intended for general display and paging and the POST
+ handler is used for inserting new suggestions.
"""
@login_required
def get(self):
+ """Handles GET requests to the paging by unique values sub-application.
+
+ If there is a bookmark value in the query parameters, uses it to query
+ for suggestions by limiting to creation tokens less than the bookmark.
+ Includes up to PAGE_SIZE results and a link to the next page of results
+ if any more exist.
+ """
bookmark = self.request.get('bookmark')
query = Suggestion.query().order(-Suggestion.creation_token)
if bookmark:
@@ -132,13 +139,20 @@ def get(self):
suggestions=suggestions)
def post(self):
+ """Handles POST requests for inserting a single suggestion."""
Suggestion(suggestion=self.request.get('suggestion')).put()
self.redirect('/unique/')
class SuggestionPopulate(BaseHandler):
+ """Populates the datastore with some sample suggestions
+
+ Provided so end users can pre-populate with PAGE_SIZE + 1 entities to see
+ how unique value-based paging works.
+ """
def post(self):
+ """Handles POST requests and adds sample suggestions."""
Suggestion.populate()
self.redirect('/unique/')
Please sign in to comment.
Something went wrong with that request. Please try again.