Ejemplo n.º 1
0
 def test_saves_survey_with_sample_size_from_form_if_has_sampling_is_true(self):
     form_data = {
         'name': 'survey rajni',
         'description': 'survey description rajni',
         'has_sampling': True,
         'sample_size': 10,
         'type': True,
     }
     survey_form = SurveyForm(data=form_data)
     Survey.save_sample_size(survey_form)
     saved_survey = Survey.objects.filter(name=form_data['name'], has_sampling=form_data['has_sampling'])
     self.failUnless(saved_survey)
     self.assertEqual(form_data['sample_size'], saved_survey[0].sample_size)
Ejemplo n.º 2
0
 def test_saves_survey_with_sample_size_zero_if_has_sampling_is_false(self):
     form_data = {
         'name': 'survey rajni',
         'description': 'survey description rajni',
         'has_sampling': False,
         'sample_size': 10,
         'type': True,
     }
     survey_form = SurveyForm(data=form_data)
     Survey.save_sample_size(survey_form)
     saved_survey = Survey.objects.filter(
         name=form_data['name'], has_sampling=form_data['has_sampling'])
     self.failUnless(saved_survey)
     self.assertEqual(0, saved_survey[0].sample_size)
Ejemplo n.º 3
0
def edit(request, survey_id):
    survey = Survey.objects.get(id=survey_id)
    survey_form = SurveyForm(instance=survey)
    if request.method == 'POST':
        survey_form = SurveyForm(instance=survey, data=request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully edited.')
            return HttpResponseRedirect('/surveys/')

    context = {'survey_form': survey_form,
               'title': "Edit Survey",
               'button_label': 'Save',
               'id': 'edit-survey-form',
               'cancel_url': '/surveys/',
               'action': '/surveys/%s/edit/' %survey_id
               }
    return render(request, 'surveys/new.html', context)
Ejemplo n.º 4
0
def edit(request, survey_id):
    survey = Survey.objects.get(id=survey_id)
    survey_form = SurveyForm(instance=survey)
    if request.method == 'POST':
        survey_form = SurveyForm(instance=survey, data=request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully edited.')
            return HttpResponseRedirect('/surveys/')

    context = {
        'survey_form': survey_form,
        'title': "Edit Survey",
        'button_label': 'Save',
        'id': 'edit-survey-form',
        'cancel_url': '/surveys/',
        'action': '/surveys/%s/edit/' % survey_id
    }
    return render(request, 'surveys/new.html', context)
Ejemplo n.º 5
0
def new(request):
    response = None
    survey_form = SurveyForm()

    if request.method == 'POST':
        survey_form = SurveyForm(request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully added.')
            response = HttpResponseRedirect('/surveys/')

    context = {'survey_form': survey_form,
               'title': "New Survey",
               'button_label': 'Create',
               'id': 'add-survey-form',
               'action': "/surveys/new/",
               'cancel_url': '/surveys/',
               }

    return response or render(request, 'surveys/new.html', context)
Ejemplo n.º 6
0
def new(request):
    response = None
    survey_form = SurveyForm()

    if request.method == 'POST':
        survey_form = SurveyForm(request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully added.')
            response = HttpResponseRedirect('/surveys/')

    context = {
        'survey_form': survey_form,
        'title': "New Survey",
        'button_label': 'Create',
        'id': 'add-survey-form',
        'action': "/surveys/new/",
        'cancel_url': '/surveys/',
    }

    return response or render(request, 'surveys/new.html', context)