Esempio n. 1
0
def _get_questions_based_on_filter(batch_id, filter_params):
    filter_params = clean_query_params(filter_params)
    if batch_id:
        filter_params = prepend_to_keys(filter_params, 'question__')
        return BatchQuestionOrder.get_batch_order_specific_questions(
            batch_id, filter_params)
    return Question.objects.filter(
        subquestion=False,
        **filter_params).exclude(group__name='REGISTRATION GROUP')
Esempio n. 2
0
def filter_by_group_and_module(request, batch_id, group_id, module_id):
    filter_params = clean_query_params({
        'group__id': group_id,
        'module__id': module_id
    })
    questions = Question.objects.filter(**filter_params).exclude(
        batches__id=batch_id).values('id', 'text',
                                     'answer_type').order_by('text')
    json_dump = json.dumps(list(questions), cls=DjangoJSONEncoder)
    return HttpResponse(json_dump, mimetype='application/json')
Esempio n. 3
0
def filter_by_group_and_module(request, batch_id, group_id, module_id):
    filter_params = clean_query_params({"group__id": group_id, "module__id": module_id})
    questions = (
        Question.objects.filter(**filter_params)
        .exclude(batches__id=batch_id)
        .values("id", "text", "answer_type")
        .order_by("text")
    )
    json_dump = json.dumps(list(questions), cls=DjangoJSONEncoder)
    return HttpResponse(json_dump, mimetype="application/json")
Esempio n. 4
0
    def test_remove_key_value_when_value_is_ALL(self):
        params = {
            'group__id': 'All',
            'batch__id': 1,
            'module__id': '',
            'question__text': 'haha',
            'survey': None
        }

        self.assertEqual({
            'batch__id': 1,
            'question__text': 'haha'
        }, clean_query_params(params))
Esempio n. 5
0
 def test_remove_key_value_when_value_is_NONE(self):
     params = {'module__id': None, 'group__id': None, 'answer_type': None}
     self.assertEqual({}, clean_query_params(params))
Esempio n. 6
0
 def test_remove_key_value_when_value_is_ALL(self):
     params = {'group__id': 'All', 'batch__id': 1,
               'module__id': '', 'question__text': 'haha', 'survey': None}
     self.assertEqual(
         {'batch__id': 1, 'question__text': 'haha'}, clean_query_params(params))
Esempio n. 7
0
    def test_remove_key_value_when_value_is_NONE(self):
        params = {'module__id': None, 'group__id': None, 'answer_type': None}

        self.assertEqual({}, clean_query_params(params))
Esempio n. 8
0
def _get_questions_based_on_filter(batch_id, filter_params):
    filter_params = clean_query_params(filter_params)
    if batch_id:
        filter_params = prepend_to_keys(filter_params, "question__")
        return BatchQuestionOrder.get_batch_order_specific_questions(batch_id, filter_params)
    return Question.objects.filter(subquestion=False, **filter_params).exclude(group__name="REGISTRATION GROUP")