dokomoforms.handlers package

Submodules

dokomoforms.handlers.auth module

Authentication handlers.

class dokomoforms.handlers.auth.CheckLoginStatus(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

An endpoint for the application to check login status.

post()[source]

2xx good, 5xx bad.

class dokomoforms.handlers.auth.GenerateToken(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

GET your token here. GETting twice resets the token.

get()[source]

Set a new token for the logged in user and return the token.

class dokomoforms.handlers.auth.Login(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

POST here to verify the assertion generated by Mozilla Persona.

post()[source]

POST to Mozilla’s verifier service.

Accepts: { “assertion”: <assertion> }

Then, POSTS to https://verifier.login.persona.org/verify to verify that the assertion is valid. If so, attempts to log the user in by e-mail.

Responds with: 200 OK { “email”: <e-mail address> }

Raises tornado.web.HTTPError:
 400 Bad Request if the assertion is not verified 422 Unprocessable Entity if the e-mail address is not associated with a user account.
class dokomoforms.handlers.auth.Logout(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

POST here to log out.

post()[source]

Delete the “user” cookie.

Note that this can’t be done in JavaScript because the user cookie is httponly.

dokomoforms.handlers.debug module

Pages pertaining to debug-specific functionality.

class dokomoforms.handlers.debug.DebugLoginHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Use this page to log in as any existing user.

get(email='test@test_email.com', created=False)[source]

Log in by supplying an e-mail address.

class dokomoforms.handlers.debug.DebugLogoutHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Log out by visiting this page.

get()[source]

Clear the ‘user’ cookie.

class dokomoforms.handlers.debug.DebugPersonaHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For testing purposes there’s no need to hit the real URL.

No need for this...

post()[source]

The test user has logged in.

class dokomoforms.handlers.debug.DebugRevisitHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For testing purposes there’s no need to hit Revisit proper.

Debug endpoint.

get()[source]

Get dummy facilities.

post()[source]

Add a facility.

class dokomoforms.handlers.debug.DebugToggleRevisitHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For turning the fake Revisit endpoint off and on.

get()[source]

Toggle the ‘online’ state of the GET endpoint.

class dokomoforms.handlers.debug.DebugToggleRevisitSlowModeHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For toggling slow mode.

get()[source]

Toggle the ‘slow’ state of the GET endpoint.

class dokomoforms.handlers.debug.DebugUserCreationHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Use this page to create a user.

get(email='test@test_email.com')[source]

Log in for any user (creating one if necessary).

dokomoforms.handlers.debug.revisit_debug()[source]

dokomoforms.handlers.root module

Administrative handlers.

class dokomoforms.handlers.root.Index(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The root URL.

get(msg='')[source]

GET /.

class dokomoforms.handlers.root.NotFound(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

This is the “default” handler according to Tornado.

prepare()[source]

Raise a 404 for any URL without an explicitly defined handler.

Raises tornado.web.HTTPError:
 404 Not Found
write_error(*args, **kwargs)[source]

Serve the custom 404 page.

dokomoforms.handlers.util module

Useful reusable functions for handlers, plus the BaseHandler.

class dokomoforms.handlers.util.BaseAPIHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The Tornado handler class for API resource classes.

api_root_path

The API URL up to the version number.

api_version

The API version.

Do not check XSRF for an API request (usually).

class dokomoforms.handlers.util.BaseHandler(application, request, **kwargs)[source]

Bases: tornado.web.RequestHandler

The base class for handlers.

Makes the database session and current user available.

current_user_model

Return the current logged in User, or None.

get(*args, **kwargs)[source]

404 unless this method is overridden.

The presence of this GET method means that endpoints which only accept POST are hidden from browsers.

Raises tornado.web.HTTPError:
 404 Not Found
get_current_user() → str[source]

Make current_user accessible.

You probably shouldn’t override this method. It makes {{ current_user }} accessible to templates and self.current_user accessible to handlers.

Returns:a string containing the user name.
get_template_namespace()[source]

Template functions.

TODO: Find a way to get rid of this. @jmwohl

num_surveys_for_menu = 20
prepare()[source]

Default behavior before any HTTP method.

By default, just sets up the XSRF token.

session

The SQLAlchemy session for interacting with the models.

Returns:the SQLAlchemy session
set_default_headers()[source]

Add some security-flavored headers.

https://news.ycombinator.com/item?id=10143082

user_default_language

Return the logged-in User’s default language, or None.

user_survey_language(survey)[source]

Return the logged-in User’s selected language for the given survey, or None if they do not have one.

write_error(status_code, **kwargs)[source]

Deal with 404 errors.

dokomoforms.handlers.util.auth_redirect(self)[source]

The URL redirect logic extracted from tornado.web.authenticated.

dokomoforms.handlers.util.authenticated_admin(method)[source]

A copy of tornado.web.authenticated for Administrator access.

Module contents

All the Tornado RequestHandlers used in Dokomo Forms.

class dokomoforms.handlers.Index(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The root URL.

get(msg='')[source]

GET /.

class dokomoforms.handlers.NotFound(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

This is the “default” handler according to Tornado.

prepare()[source]

Raise a 404 for any URL without an explicitly defined handler.

Raises tornado.web.HTTPError:
 404 Not Found
write_error(*args, **kwargs)[source]

Serve the custom 404 page.

class dokomoforms.handlers.Login(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

POST here to verify the assertion generated by Mozilla Persona.

post()[source]

POST to Mozilla’s verifier service.

Accepts: { “assertion”: <assertion> }

Then, POSTS to https://verifier.login.persona.org/verify to verify that the assertion is valid. If so, attempts to log the user in by e-mail.

Responds with: 200 OK { “email”: <e-mail address> }

Raises tornado.web.HTTPError:
 400 Bad Request if the assertion is not verified 422 Unprocessable Entity if the e-mail address is not associated with a user account.
class dokomoforms.handlers.Logout(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

POST here to log out.

post()[source]

Delete the “user” cookie.

Note that this can’t be done in JavaScript because the user cookie is httponly.

class dokomoforms.handlers.GenerateToken(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

GET your token here. GETting twice resets the token.

get()[source]

Set a new token for the logged in user and return the token.

class dokomoforms.handlers.AdminHomepageHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for the main Administrator interface.

get()[source]

GET the admin interface.

class dokomoforms.handlers.CheckLoginStatus(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

An endpoint for the application to check login status.

post()[source]

2xx good, 5xx bad.

class dokomoforms.handlers.ViewSurveyHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for getting a single survey’s admin page.

get(survey_id: str)[source]

GET the admin page for a survey.

class dokomoforms.handlers.ViewSurveyDataHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for getting a single survey’s data page.

get(survey_id: str)[source]

GET the data page.

class dokomoforms.handlers.ViewUserAdminHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for getting the user administration admin page.

get()[source]

GET the user admin page.

class dokomoforms.handlers.ViewSubmissionHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for viewing a submission.

get(submission_id: str)[source]

GET the visualization page.

class dokomoforms.handlers.EnumerateHomepageHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

The endpoint for the main Enumerator interface.

get()[source]

GET the enumerate interface.

class dokomoforms.handlers.Enumerate(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

View and submit to a survey.

get(survey_id)[source]

GET the main survey view.

Render survey page for given survey id, embed JSON into to template so browser can cache survey in HTML.

Raises tornado http error.

@survey_id: Requested survey id.

class dokomoforms.handlers.EnumerateTitle(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

View and submit to a survey identified by title.

get(title)[source]

GET the main survey view.

Render survey page for given survey title, embed JSON into to template so browser can cache survey in HTML.

Checks for Survey.url_slug

Raises tornado http error.

class dokomoforms.handlers.DebugUserCreationHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Use this page to create a user.

get(email='test@test_email.com')[source]

Log in for any user (creating one if necessary).

class dokomoforms.handlers.DebugLoginHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Use this page to log in as any existing user.

get(email='test@test_email.com', created=False)[source]

Log in by supplying an e-mail address.

class dokomoforms.handlers.DebugLogoutHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Log out by visiting this page.

get()[source]

Clear the ‘user’ cookie.

class dokomoforms.handlers.DebugPersonaHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For testing purposes there’s no need to hit the real URL.

No need for this...

post()[source]

The test user has logged in.

class dokomoforms.handlers.DebugRevisitHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For testing purposes there’s no need to hit Revisit proper.

Debug endpoint.

get()[source]

Get dummy facilities.

post()[source]

Add a facility.

class dokomoforms.handlers.DebugToggleRevisitHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For turning the fake Revisit endpoint off and on.

get()[source]

Toggle the ‘online’ state of the GET endpoint.

class dokomoforms.handlers.DebugToggleRevisitSlowModeHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

For toggling slow mode.

get()[source]

Toggle the ‘slow’ state of the GET endpoint.

class dokomoforms.handlers.DemoUserCreationHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Use this page to log in as the demo user.

get()[source]

Create the demo account (if necessary) and log in.

class dokomoforms.handlers.DemoLogoutHandler(application, request, **kwargs)[source]

Bases: dokomoforms.handlers.util.BaseHandler

Log out by visiting this page.

get()[source]

Clear the ‘user’ cookie.