lms.djangoapps.survey package#
Submodules#
lms.djangoapps.survey.apps module#
Survey Application Configuration
lms.djangoapps.survey.exceptions module#
Specialized exceptions for the Survey Djangoapp
- exception lms.djangoapps.survey.exceptions.SurveyFormNameAlreadyExists#
Bases:
ExceptionThrown when a SurveyForm is created but that name already exists
- exception lms.djangoapps.survey.exceptions.SurveyFormNotFound#
Bases:
ExceptionThrown when a SurveyForm is not found in the database
lms.djangoapps.survey.models module#
Models to support Course Surveys feature
- class lms.djangoapps.survey.models.SurveyAnswer(*args, **kwargs)#
Bases:
TimeStampedModelModel for the answers that a user gives for a particular form in a course
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- course_key#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod do_survey_answers_exist(form, user)#
Returns whether a user has any answers for a given SurveyForm for a course This can be used to determine if a user has taken a CourseSurvey.
- field_name#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- field_value#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- form#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- form_id#
- classmethod get_answers(form, user=None, limit_num_users=10000)#
Returns all answers a user (or all users, when user=None) has given to an instance of a SurveyForm
Return is a nested dict which are simple name/value pairs with an outer key which is the user id. For example (where ‘field3’ is an optional field):
- results = {
- ‘1’: {
‘field1’: ‘value1’, ‘field2’: ‘value2’,
}, ‘2’: {
‘field1’: ‘value3’, ‘field2’: ‘value4’, ‘field3’: ‘value5’,
:
}
limit_num_users is to prevent an unintentional huge, in-memory dictionary.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- classmethod retire_user(user_id)#
With the parameter user_id, blank out the survey answer values for all survey questions This is to fulfill our GDPR obligations
Return True if there are data to be blanked Return False if there are no matching data
- classmethod save_answers(form, user, answers, course_key)#
Store answers to the form for a given user. Answers is a dict of simple name/value pairs
IMPORTANT: There is no validaton of form answers at this point. All data supplied to this method is presumed to be previously validated
- user#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- user_id#
- class lms.djangoapps.survey.models.SurveyForm(*args, **kwargs)#
Bases:
TimeStampedModelModel to define a Survey Form that contains the HTML form data that is presented to the end user. A SurveyForm is not tied to a particular run of a course, to allow for sharing of Surveys across courses
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- clear_user_answers(user)#
Removes all answers that a user has submitted
- classmethod create(name, form, update_if_exists=False)#
Helper class method to create a new Survey Form.
update_if_exists=True means that if a form already exists with that name, then update it. Otherwise throw an SurveyFormAlreadyExists exception
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- form#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod get(name, throw_if_not_found=True)#
Helper class method to look up a Survey Form, throw FormItemNotFound if it does not exists in the database, unless throw_if_not_found=False then we return None
- get_answers(user=None, limit_num_users=10000)#
Returns all answers for all users for this Survey
- get_field_names()#
Returns a list of defined field names for all answers in a survey. This can be helpful for reporting like features, i.e. adding headers to the reports This is taken from the set of <input> fields inside the form.
- classmethod get_field_names_from_html(html)#
Returns a list of defined field names from a block of HTML
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- has_user_answered_survey(user)#
Returns whether a given user has supplied answers to this survey
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- save(*args, **kwargs)#
Override save method so we can validate that the form HTML is actually parseable
- save_user_answers(user, answers, course_key)#
Store answers to the form for a given user. Answers is a dict of simple name/value pairs
IMPORTANT: There is no validaton of form answers at this point. All data supplied to this method is presumed to be previously validated
- surveyanswer_set#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- classmethod validate_form_html(html)#
Makes sure that the html that is contained in the form field is valid
lms.djangoapps.survey.signals module#
Signal handlers for the survey app
lms.djangoapps.survey.urls module#
URL mappings for the Survey feature
lms.djangoapps.survey.utils module#
Utilities for determining whether or not a survey needs to be completed.
- class lms.djangoapps.survey.utils.SurveyRequiredAccessError#
Bases:
AccessErrorAccess denied because the user has not completed a required survey
- lms.djangoapps.survey.utils.check_survey_required_and_unanswered(user, course_block)#
Checks whether a user is required to answer the survey and has yet to do so.
- Returns:
Either ACCESS_GRANTED or SurveyRequiredAccessError.
- Return type:
- lms.djangoapps.survey.utils.is_survey_required_for_course(course_block)#
Returns whether a Survey is required for this course
lms.djangoapps.survey.views module#
View endpoints for Survey
- lms.djangoapps.survey.views.submit_answers(request, survey_name)#
Form submission post-back endpoint.
NOTE: We do not have a formal definition of a Survey Form, it’s just some authored HTML form fields (via Django Admin site). Therefore we do not do any validation of the submission server side. It is assumed that all validation is done via JavaScript in the survey.html file
- lms.djangoapps.survey.views.view_student_survey(user, survey_name, course=None, redirect_url=None, is_required=False, skip_redirect_url=None)#
Shared utility method to render a survey form NOTE: This method is shared between the Survey and Courseware Djangoapps
- lms.djangoapps.survey.views.view_survey(request, survey_name)#
View to render the survey to the end user