本文整理汇总了Python中survey.models.SurveyForm.get方法的典型用法代码示例。如果您正苦于以下问题:Python SurveyForm.get方法的具体用法?Python SurveyForm.get怎么用?Python SurveyForm.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类survey.models.SurveyForm
的用法示例。
在下文中一共展示了SurveyForm.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_form_not_found_raise_exception
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def test_form_not_found_raise_exception(self):
"""
Asserts that when looking up a form that does not exist
"""
with self.assertRaises(SurveyFormNotFound):
SurveyForm.get(self.test_survey_name)
示例2: view_student_survey
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def 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
"""
redirect_url = redirect_url if redirect_url else reverse('dashboard')
dashboard_redirect_url = reverse('dashboard')
skip_redirect_url = skip_redirect_url if skip_redirect_url else dashboard_redirect_url
survey = SurveyForm.get(survey_name, throw_if_not_found=False)
if not survey:
return HttpResponseRedirect(redirect_url)
# the result set from get_answers, has an outer key with the user_id
# just remove that outer key to make the JSON payload simplier
existing_answers = survey.get_answers(user=user).get(user.id, {})
platform_name = configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME)
context = {
'existing_data_json': json.dumps(existing_answers),
'postback_url': reverse('submit_answers', args=[survey_name]),
'redirect_url': redirect_url,
'skip_redirect_url': skip_redirect_url,
'dashboard_redirect_url': dashboard_redirect_url,
'survey_form': survey.form,
'is_required': is_required,
'mail_to_link': configuration_helpers.get_value('email_from_address', settings.CONTACT_EMAIL),
'platform_name': platform_name,
'course': course,
}
return render_to_response("survey/survey.html", context)
示例3: view_student_survey
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def 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
"""
redirect_url = redirect_url if redirect_url else reverse("dashboard")
dashboard_redirect_url = reverse("dashboard")
skip_redirect_url = skip_redirect_url if skip_redirect_url else dashboard_redirect_url
survey = SurveyForm.get(survey_name, throw_if_not_found=False)
if not survey:
return HttpResponseRedirect(redirect_url)
# the result set from get_answers, has an outer key with the user_id
# just remove that outer key to make the JSON payload simplier
existing_answers = survey.get_answers(user=user).get(user.id, {})
context = {
"existing_data_json": json.dumps(existing_answers),
"postback_url": reverse("submit_answers", args=[survey_name]),
"redirect_url": redirect_url,
"skip_redirect_url": skip_redirect_url,
"dashboard_redirect_url": dashboard_redirect_url,
"survey_form": survey.form,
"is_required": is_required,
"mail_to_link": microsite.get_value("email_from_address", settings.CONTACT_EMAIL),
"course": course,
}
return render_to_response("survey/survey.html", context)
示例4: is_survey_required_for_course
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def is_survey_required_for_course(course_descriptor):
"""
Returns whether a Survey is required for this course
"""
# check to see that the Survey name has been defined in the CourseDescriptor
# and that the specified Survey exists
return course_descriptor.course_survey_required and \
SurveyForm.get(course_descriptor.course_survey_name, throw_if_not_found=False)
示例5: is_survey_required_for_course
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def is_survey_required_for_course(course_descriptor):
"""
Returns whether a Survey is required for this course
"""
# Check to see that the survey is required in the CourseDescriptor.
if not getattr(course_descriptor, 'course_survey_required', False):
return False
# Check that the specified Survey for the course exists.
return SurveyForm.get(course_descriptor.course_survey_name, throw_if_not_found=False)
示例6: test_create_new_form
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def test_create_new_form(self):
"""
Make sure we can create a new form a look it up
"""
survey = self._create_test_survey()
self.assertIsNotNone(survey)
new_survey = SurveyForm.get(self.test_survey_name)
self.assertIsNotNone(new_survey)
self.assertEqual(new_survey.form, self.test_form)
示例7: test_create_form_update_existing
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def test_create_form_update_existing(self):
"""
Make sure we can update an existing form
"""
survey = self._create_test_survey()
self.assertIsNotNone(survey)
survey = SurveyForm.create(self.test_survey_name, self.test_form_update, update_if_exists=True)
self.assertIsNotNone(survey)
survey = SurveyForm.get(self.test_survey_name)
self.assertIsNotNone(survey)
self.assertEquals(survey.form, self.test_form_update)
示例8: must_answer_survey
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def must_answer_survey(course_descriptor, user):
"""
Returns whether a user needs to answer a required survey
"""
if not is_survey_required_for_course(course_descriptor):
return False
# this will throw exception if not found, but a non existing survey name will
# be trapped in the above is_survey_required_for_course() method
survey = SurveyForm.get(course_descriptor.course_survey_name)
has_staff_access = has_access(user, "staff", course_descriptor)
# survey is required and it exists, let's see if user has answered the survey
# course staff do not need to answer survey
answered_survey = SurveyAnswer.do_survey_answers_exist(survey, user)
return not answered_survey and not has_staff_access
示例9: submit_answers
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def 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
"""
survey = SurveyForm.get(survey_name, throw_if_not_found=False)
if not survey:
return HttpResponseNotFound()
answers = {}
for key in request.POST.keys():
# support multi-SELECT form values, by string concatenating them with a comma separator
array_val = request.POST.getlist(key)
answers[key] = request.POST[key] if len(array_val) == 0 else ','.join(array_val)
# the URL we are supposed to redirect to is
# in a hidden form field
redirect_url = answers['_redirect_url'] if '_redirect_url' in answers else reverse('dashboard')
course_key = CourseKey.from_string(answers['course_id']) if 'course_id' in answers else None
allowed_field_names = survey.get_field_names()
# scrub the answers to make sure nothing malicious from the user gets stored in
# our database, e.g. JavaScript
filtered_answers = {}
for answer_key in answers.keys():
# only allow known input fields
if answer_key in allowed_field_names:
filtered_answers[answer_key] = escape(answers[answer_key])
survey.save_user_answers(request.user, filtered_answers, course_key)
response_params = json.dumps({
# The HTTP end-point for the payment processor.
"redirect_url": redirect_url,
})
return HttpResponse(response_params, content_type="text/json")
示例10: is_survey_required_and_unanswered
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def is_survey_required_and_unanswered(user, course_descriptor):
"""
Returns whether a user is required to answer the survey and has yet to do so.
"""
if not is_survey_required_for_course(course_descriptor):
return False
# anonymous users do not need to answer the survey
if user.is_anonymous():
return False
# course staff do not need to answer survey
has_staff_access = has_access(user, 'staff', course_descriptor)
if has_staff_access:
return False
# survey is required and it exists, let's see if user has answered the survey
survey = SurveyForm.get(course_descriptor.course_survey_name)
answered_survey = SurveyAnswer.do_survey_answers_exist(survey, user)
if not answered_survey:
return True
示例11: test_form_not_found_none
# 需要导入模块: from survey.models import SurveyForm [as 别名]
# 或者: from survey.models.SurveyForm import get [as 别名]
def test_form_not_found_none(self):
"""
Asserts that when looking up a form that does not exist
"""
self.assertIsNone(SurveyForm.get(self.test_survey_name, throw_if_not_found=False))