本文整理汇总了Python中survey.models.SurveyForm类的典型用法代码示例。如果您正苦于以下问题:Python SurveyForm类的具体用法?Python SurveyForm怎么用?Python SurveyForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SurveyForm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_form_with_malformed_html
def test_create_form_with_malformed_html(self):
"""
Make sure that if a SurveyForm is saved with unparseable html
an exception is thrown
"""
with self.assertRaises(ValidationError):
SurveyForm.create('badform', '<input name="oops" /><<<>')
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例2: test_form_not_found_raise_exception
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)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例3: test_create_form_with_no_fields
def test_create_form_with_no_fields(self):
"""
Make sure that if a SurveyForm is saved without any named fields
an exception is thrown
"""
with self.assertRaises(ValidationError):
SurveyForm.create('badform', '<p>no input fields here</p>')
with self.assertRaises(ValidationError):
SurveyForm.create('badform', '<input id="input_without_name" />')
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:10,代码来源:test_models.py
示例4: test_create_form_update_existing
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)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:13,代码来源:test_models.py
示例5: view_student_survey
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)
开发者ID:akbargumbira,项目名称:Labster.EdX,代码行数:31,代码来源:views.py
示例6: setUp
def setUp(self):
"""
Set up the test data used in the specific tests
"""
super(SurveyModelsTests, self).setUp()
self.client = Client()
# Create two accounts
self.password = 'abc'
self.student = User.objects.create_user('student', 'studen[email protected]', self.password)
self.student2 = User.objects.create_user('student2', '[email protected]', self.password)
self.staff = User.objects.create_user('staff', '[email protected]', self.password)
self.staff.is_staff = True
self.staff.save()
self.test_survey_name = 'TestSurvey'
self.test_form = '<input name="foo"></input>'
self.student_answers = OrderedDict({
'field1': 'value1',
'field2': 'value2',
})
self.student2_answers = OrderedDict({
'field1': 'value3'
})
self.course = CourseFactory.create(
course_survey_required=True,
course_survey_name=self.test_survey_name
)
self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:35,代码来源:test_utils.py
示例7: setUp
def setUp(self):
"""
Set up the test data used in the specific tests
"""
super(SurveyViewsTests, self).setUp()
self.test_form = '<input name="field1"></input>'
self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
self.student_answers = OrderedDict({
u'field1': u'value1',
u'field2': u'value2',
})
# Create student accounts and activate them.
for i in range(len(self.STUDENT_INFO)):
email, password = self.STUDENT_INFO[i]
username = 'u{0}'.format(i)
self.create_account(username, email, password)
self.activate_user(email)
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
self.enroll(self.course_without_survey, True)
self.enroll(self.course_with_bogus_survey, True)
self.user = User.objects.get(email=email)
self.view_url = reverse('view_survey', args=[self.test_survey_name])
self.postback_url = reverse('submit_answers', args=[self.test_survey_name])
开发者ID:mreyk,项目名称:edx-platform,代码行数:31,代码来源:test_course_survey.py
示例8: setUp
def setUp(self):
"""
Set up the test data used in the specific tests
"""
super(SurveyViewsTests, self).setUp()
self.client = Client()
# Create two accounts
self.password = 'abc'
self.student = User.objects.create_user('student', 'stud[email protected]', self.password)
self.test_survey_name = 'TestSurvey'
self.test_form = '<input name="field1" /><input name="field2" /><select name="ddl"><option>1</option></select>'
self.student_answers = OrderedDict({
u'field1': u'value1',
u'field2': u'value2',
u'ddl': u'1',
})
self.course = CourseFactory.create(
course_survey_required=True,
course_survey_name=self.test_survey_name
)
self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
self.view_url = reverse('view_survey', args=[self.test_survey_name])
self.postback_url = reverse('submit_answers', args=[self.test_survey_name])
self.client.login(username=self.student.username, password=self.password)
开发者ID:189140879,项目名称:edx-platform,代码行数:32,代码来源:test_views.py
示例9: view_student_survey
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)
开发者ID:cmscom,项目名称:edx-platform,代码行数:34,代码来源:views.py
示例10: is_survey_required_for_course
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)
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:10,代码来源:utils.py
示例11: manage_survey
def manage_survey(request, survey_id=None):
UserQuestionForm = user_question_form(request.user.id)
SurveyQuestionFormset = inlineformset_factory(Survey, SurveyQuestion, form=UserQuestionForm)
if survey_id is not None:
survey = get_object_or_404(Survey, id__exact=int(survey_id))
if survey.user != request.user:
return HttpResponseForbidden()
else:
survey = None
if request.POST:
survey_form = SurveyForm(request.POST, instance=survey)
if not survey_form.is_valid():
messages.error(request, 'Please complete required fields.')
return HttpResponseRedirect('/survey/create/')
survey_instance = survey_form.save(commit=False)
survey_instance.user_id = request.user.id
survey_instance.save()
survey_question_formset = SurveyQuestionFormset(request.POST, instance=survey)
if survey_question_formset.is_valid():
survey_question_instance = survey_question_formset.save(commit=False)
for sqi in survey_question_instance:
sqi.survey_id = survey_instance.id
sqi.save()
if survey_id is None:
messages.success(request, 'New survey successfully created.')
else:
messages.success(request, 'Survey successfully updated.')
return HttpResponseRedirect('/survey/')
else:
survey_form = SurveyForm(instance=survey)
survey_question_formset = SurveyQuestionFormset(instance=survey)
ctx = {
'survey_form': survey_form,
'survey_question_formset': survey_question_formset
}
return render(request, 'survey/manage_survey.html', ctx)
开发者ID:CenterForTheBuiltEnvironment,项目名称:right_now,代码行数:42,代码来源:views.py
示例12: test_create_new_form
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)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:11,代码来源:test_models.py
示例13: is_survey_required_for_course
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)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:11,代码来源:utils.py
示例14: must_answer_survey
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
开发者ID:ahmadiga,项目名称:min_edx,代码行数:17,代码来源:utils.py
示例15: setUp
def setUp(self):
"""
Set up the test data used in the specific tests
"""
super(SurveyViewsTests, self).setUp()
self.test_survey_name = 'TestSurvey'
self.test_form = '<input name="field1"></input>'
self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
self.student_answers = OrderedDict({
u'field1': u'value1',
u'field2': u'value2',
})
self.course = CourseFactory.create(
display_name='<script>alert("XSS")</script>',
course_survey_required=True,
course_survey_name=self.test_survey_name
)
self.course_with_bogus_survey = CourseFactory.create(
course_survey_required=True,
course_survey_name="DoesNotExist"
)
self.course_without_survey = CourseFactory.create()
# Create student accounts and activate them.
for i in range(len(self.STUDENT_INFO)):
email, password = self.STUDENT_INFO[i]
username = 'u{0}'.format(i)
self.create_account(username, email, password)
self.activate_user(email)
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
self.enroll(self.course_without_survey, True)
self.enroll(self.course_with_bogus_survey, True)
self.view_url = reverse('view_survey', args=[self.test_survey_name])
self.postback_url = reverse('submit_answers', args=[self.test_survey_name])
开发者ID:sigberto,项目名称:edx-platform,代码行数:44,代码来源:test_course_survey.py
示例16: submit_answers
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")
开发者ID:cmscom,项目名称:edx-platform,代码行数:43,代码来源:views.py
示例17: is_survey_required_and_unanswered
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
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:22,代码来源:utils.py
示例18: clean_form
def clean_form(self):
"""Validate the HTML template."""
form = self.cleaned_data["form"]
SurveyForm.validate_form_html(form)
return form
开发者ID:PiyushDeshmukh,项目名称:edx-platform,代码行数:5,代码来源:admin.py
示例19: _create_test_survey
def _create_test_survey(self):
"""
Helper method to set up test form
"""
return SurveyForm.create(self.test_survey_name, self.test_form)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:5,代码来源:test_models.py
示例20: test_form_not_found_none
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))
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:6,代码来源:test_models.py
注:本文中的survey.models.SurveyForm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论