def new(request, survey_id): batch = Batch(survey=Survey.objects.get(id=survey_id)) response, batchform = _process_form(request=request, batchform=(BatchForm(instance=batch)), action_str='added') context = {'batchform': batchform, 'button_label': "Create", 'id': 'add-batch-form', 'title': 'New Batch', 'action': '/surveys/%s/batches/new/' % survey_id, 'cancel_url': '/surveys/'} return response or render(request, 'batches/new.html', context)
def get_next_batch(self): open_ordered_batches = Batch.open_ordered_batches(self.get_location()) for batch in open_ordered_batches: if not self.completed_member_batches.filter(batch=batch) and batch.has_unanswered_question(self): return batch return None
def test_form_should_be_invalid_if_name_already_exists_on_the_same_survey(self): survey = Survey.objects.create(name="very fast") Batch.objects.create(survey=survey, name='Batch A', description='description') form_data = { 'name': 'Batch A', 'description': 'description goes here', } batch_form = BatchForm(data=form_data, instance=Batch(survey=survey)) self.assertFalse(batch_form.is_valid())
def index(request, survey_id): survey = Survey.objects.get(id=survey_id) batches = Batch.objects.filter(survey__id=survey_id) if request.is_ajax(): batches = batches.values('id', 'name').order_by('name') json_dump = json.dumps(list(batches), cls=DjangoJSONEncoder) return HttpResponse(json_dump, mimetype='application/json') context = {'batches': batches, 'survey': survey, 'request': request, 'batchform': BatchForm(instance=Batch(survey=survey)), 'action': '/surveys/%s/batches/new/' % survey_id, } return render(request, 'batches/index.html', context)
def test_form_should_be_valid_if_name_already_exists_on_a_different_survey( self): survey = Survey.objects.create(name="very fast") form_data = { 'name': 'Batch A', 'description': 'description goes here', } Batch.objects.create(survey=survey, name=form_data['name'], description='description') different_survey = Survey.objects.create(name="different") batch_form = BatchForm(data=form_data, instance=Batch(survey=different_survey)) self.assertTrue(batch_form.is_valid())
def has_answered_non_response(self): open_batch = Batch.currently_open_for(self.household.location) return self.multichoiceanswer.filter(question__group__name="NON_RESPONSE", batch=open_batch).count() > 0
def has_answered_non_response(self): open_batch = Batch.currently_open_for(self.location) has_answered_non_response = self.multichoiceanswer.filter(question__group__name="NON_RESPONSE", batch=open_batch, householdmember=None) return has_answered_non_response.exists()