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()

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()

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()

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()

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)

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()

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()

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()

Get dummy facilities.

post()

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()

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()

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')

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='')

GET /.

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

Bases: dokomoforms.handlers.util.BaseHandler

This is the “default” handler according to Tornado.

prepare()

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

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

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)

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

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()

Template functions.

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

num_surveys_for_menu = 20
prepare()

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()

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)

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)

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='')

GET /.

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

Bases: dokomoforms.handlers.util.BaseHandler

This is the “default” handler according to Tornado.

prepare()

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

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

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()

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()

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()

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()

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()

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)

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)

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()

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)

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()

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)

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)

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')

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)

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()

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()

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()

Get dummy facilities.

post()

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()

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()

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()

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()

Clear the ‘user’ cookie.