dokomoforms.handlers.api.v0 package¶
Submodules¶
dokomoforms.handlers.api.v0.base module¶
The base class of the TornadoResource classes in the api module.
-
class
dokomoforms.handlers.api.v0.base.
BaseResource
(*args, **kwargs)[source]¶ Bases:
restless.tnd.TornadoResource
Set up the basics for the model resource.
BaseResource does some basic configuration for the restless resources. - sets the base request handler class which is used by the resources - providing reference to the ORM session via request handler - inserting a serializer for dokomo Models - setting up authentication
-
build_response
(data, status=200)[source]¶ Finish the Tornado response.
This takes into account non-JSON content-types.
-
content_type
¶ The format specified in the request.
-
current_user
¶ The handler’s current_user.
-
current_user_model
¶ The handler’s current_user_model.
-
default_sort_column_name
¶ The default ORDER BY column name for list responses.
-
handle_error
(err)[source]¶ Generate a serialized error message.
If the error came from Tornado, pass it along as such. Otherwise, turn certain expected errors into 400 BAD REQUEST instead of 500 INTERNAL SERVER ERROR.
-
list
(where=None)[source]¶ Return a list of instances of this model.
Given a model class, build up the ORM query based on query params and return the query result.
-
objects_key
¶ The key for list responses.
-
query_modifiers_applied
¶ Whether there were any modifiers applied to the query.
-
resource_type
¶ The model class for the resource.
-
serializer
= <dokomoforms.handlers.api.v0.serializer.ModelJSONSerializer object>¶
-
session
¶ The handler’s session.
-
wrap_list_response
(data)[source]¶ Wrap a list response in a dict.
Takes a list of data & wraps it in a dictionary (within the
objects
key). For security in JSON responses, it’s better to wrap the list results in anobject
(due to the way theArray
constructor can be attacked in Javascript). See http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ & similar for details. Overridable to allow for modifying the key names, adding data (or just insecurely return a plain old list if that’s your thing). :param data: A list of data about to be serialized :type data: list :returns: A wrapping dict :rtype: dict
-
dokomoforms.handlers.api.v0.nodes module¶
TornadoResource class for dokomoforms.models.node.Node subclasses.
-
class
dokomoforms.handlers.api.v0.nodes.
NodeResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Nodes.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
default_sort_column_name
= 'last_update_time'¶
-
objects_key
= 'nodes'¶
-
resource_type
¶ alias of
Node
-
dokomoforms.handlers.api.v0.photos module¶
TornadoResource class for dokomoforms.models.answer.Photo.
dokomoforms.handlers.api.v0.serializer module¶
The restless Serializer for the models.
dokomoforms.handlers.api.v0.submissions module¶
TornadoResource class for dokomoforms.models.submission.Submission.
-
class
dokomoforms.handlers.api.v0.submissions.
SubmissionResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Submissions.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
create
()[source]¶ Create a new submission.
Uses the current_user_model (i.e. logged-in user) as creator.
-
default_sort_column_name
= 'save_time'¶
-
objects_key
= 'submissions'¶
-
resource_type
¶ alias of
Submission
-
dokomoforms.handlers.api.v0.surveys module¶
TornadoResource class for dokomoforms.models.survey.Survey.
-
class
dokomoforms.handlers.api.v0.surveys.
SurveyResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Surveys.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
create
()[source]¶ Create a new survey.
Uses the current_user_model (i.e. logged-in user) as creator.
-
default_sort_column_name
= 'created_on'¶
-
detail
(survey_id)[source]¶ Return the given survey.
Public surveys don’t require authentication. Enumerator-only surveys do required authentication, and the user must be one of the survey’s enumerators or an administrator.
-
http_methods
= {'list': {'POST': 'create', 'PUT': 'update_list', 'DELETE': 'delete_list', 'GET': 'list'}, 'stats': {'GET': 'stats'}, 'activity': {'GET': 'activity'}, 'list_submissions': {'GET': 'list_submissions'}, 'detail': {'POST': 'create_detail', 'PUT': 'update', 'DELETE': 'delete', 'GET': 'detail'}, 'submit': {'POST': 'submit'}, 'activity_all': {'GET': 'activity_all'}}¶
-
objects_key
= 'surveys'¶
-
resource_type
¶ alias of
Survey
-
Module contents¶
Handlers for the API endpoints.
-
class
dokomoforms.handlers.api.v0.
ModelJSONSerializer
[source]¶ Bases:
restless.serializers.JSONSerializer
Drop-in replacement for the restless-supplied JSONSerializer.
Uses dokomo’s ModelJSONEncoder in order to correctly serialize models to JSON.
-
class
dokomoforms.handlers.api.v0.
BaseResource
(*args, **kwargs)[source]¶ Bases:
restless.tnd.TornadoResource
Set up the basics for the model resource.
BaseResource does some basic configuration for the restless resources. - sets the base request handler class which is used by the resources - providing reference to the ORM session via request handler - inserting a serializer for dokomo Models - setting up authentication
-
build_response
(data, status=200)[source]¶ Finish the Tornado response.
This takes into account non-JSON content-types.
-
content_type
¶ The format specified in the request.
-
current_user
¶ The handler’s current_user.
-
current_user_model
¶ The handler’s current_user_model.
-
default_sort_column_name
¶ The default ORDER BY column name for list responses.
-
handle_error
(err)[source]¶ Generate a serialized error message.
If the error came from Tornado, pass it along as such. Otherwise, turn certain expected errors into 400 BAD REQUEST instead of 500 INTERNAL SERVER ERROR.
-
list
(where=None)[source]¶ Return a list of instances of this model.
Given a model class, build up the ORM query based on query params and return the query result.
-
objects_key
¶ The key for list responses.
-
query_modifiers_applied
¶ Whether there were any modifiers applied to the query.
-
resource_type
¶ The model class for the resource.
-
serializer
= <dokomoforms.handlers.api.v0.serializer.ModelJSONSerializer object>¶
-
session
¶ The handler’s session.
-
wrap_list_response
(data)[source]¶ Wrap a list response in a dict.
Takes a list of data & wraps it in a dictionary (within the
objects
key). For security in JSON responses, it’s better to wrap the list results in anobject
(due to the way theArray
constructor can be attacked in Javascript). See http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ & similar for details. Overridable to allow for modifying the key names, adding data (or just insecurely return a plain old list if that’s your thing). :param data: A list of data about to be serialized :type data: list :returns: A wrapping dict :rtype: dict
-
-
class
dokomoforms.handlers.api.v0.
SurveyResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Surveys.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
create
()[source]¶ Create a new survey.
Uses the current_user_model (i.e. logged-in user) as creator.
-
default_sort_column_name
= 'created_on'¶
-
detail
(survey_id)[source]¶ Return the given survey.
Public surveys don’t require authentication. Enumerator-only surveys do required authentication, and the user must be one of the survey’s enumerators or an administrator.
-
http_methods
= {'list': {'POST': 'create', 'PUT': 'update_list', 'DELETE': 'delete_list', 'GET': 'list'}, 'stats': {'GET': 'stats'}, 'activity': {'GET': 'activity'}, 'list_submissions': {'GET': 'list_submissions'}, 'detail': {'POST': 'create_detail', 'PUT': 'update', 'DELETE': 'delete', 'GET': 'detail'}, 'submit': {'POST': 'submit'}, 'activity_all': {'GET': 'activity_all'}}¶
-
objects_key
= 'surveys'¶
-
resource_type
¶ alias of
Survey
-
-
dokomoforms.handlers.api.v0.
get_survey_for_handler
(tornado_handler, survey_id)[source]¶ Maybe a handler needs a survey from the API.
-
class
dokomoforms.handlers.api.v0.
SubmissionResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Submissions.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
create
()[source]¶ Create a new submission.
Uses the current_user_model (i.e. logged-in user) as creator.
-
default_sort_column_name
= 'save_time'¶
-
objects_key
= 'submissions'¶
-
resource_type
¶ alias of
Submission
-
-
dokomoforms.handlers.api.v0.
get_submission_for_handler
(tornado_handler, submission_id)[source]¶ Maybe a handler needs a submission from the API.
-
class
dokomoforms.handlers.api.v0.
UserResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Users.
-
default_sort_column_name
= 'name'¶
-
objects_key
= 'users'¶
-
resource_type
¶ alias of
User
-
-
class
dokomoforms.handlers.api.v0.
NodeResource
(*args, **kwargs)[source]¶ Bases:
dokomoforms.handlers.api.v0.base.BaseResource
Restless resource for Nodes.
BaseResource sets the serializer, which uses the dokomo models’ ModelJSONEncoder for json conversion.
-
default_sort_column_name
= 'last_update_time'¶
-
objects_key
= 'nodes'¶
-
resource_type
¶ alias of
Node
-