Example #1
0
def index(request, batch_id):
    batch = get_object_or_404(Batch, pk=batch_id)
    questions = batch.questions_inline()
    max_per_page = None
    if request.method == 'GET':
        question_filter_form = QuestionFilterForm(data=request.GET, batch=batch)
        batch_questions = batch.batch_questions.all()
        search_fields = ['identifier', 'group__name', 'text', ]
        if request.GET.has_key('q'):
            questions = get_filterset(batch_questions, request.GET['q'], search_fields)
        relevant_questions = question_filter_form.filter(batch_questions)
        questions = [q for q in questions if q in relevant_questions]
        #now maintain same inline other exclusing questions in
        max_per_page = _max_number_of_question_per_page(request.GET.get('number_of_questions_per_page', 0))
    else:
        question_filter_form = QuestionFilterForm(batch=batch)
    #question_library =  question_filter_form.filter(QuestionTemplate.objects.all())

    question_form = QuestionForm(batch)

    request.breadcrumbs([
        ('Surveys', reverse('survey_list_page')),
        (batch.survey.name, reverse('batch_index_page', args=(batch.survey.pk, ))),
    ])
    context = {'questions': questions, 'request': request, 'batch': batch, 'max_question_per_page':max_per_page,
               'question_filter_form': question_filter_form,
               'placeholder': 'identifier, group name, text',
               }
    return render(request, 'questions/index.html', context)
Example #2
0
def index(request, batch_id):
    batch = get_object_or_404(Batch, pk=batch_id)
    questions = batch.questions_inline()
    max_per_page = None
    if request.method == 'GET':
        question_filter_form = QuestionFilterForm(data=request.GET, batch=batch)
        batch_questions = batch.batch_questions.all()
        search_fields = ['identifier', 'group__name', 'text', ]
        if request.GET.has_key('q'):
            questions = get_filterset(batch_questions, request.GET['q'], search_fields)
        relevant_questions = question_filter_form.filter(batch_questions)
        questions = [q for q in questions if q in relevant_questions]
        #now maintain same inline other exclusing questions in
        max_per_page = _max_number_of_question_per_page(request.GET.get('number_of_questions_per_page', 0))
    else:
        question_filter_form = QuestionFilterForm(batch=batch)
    #question_library =  question_filter_form.filter(QuestionTemplate.objects.all())

    question_form = QuestionForm(batch)

    request.breadcrumbs([
        ('Surveys', reverse('survey_list_page')),
        (batch.survey.name, reverse('batch_index_page', args=(batch.survey.pk, ))),
    ])
    context = {'questions': questions, 'request': request, 'batch': batch, 'max_question_per_page':max_per_page,
               'question_filter_form': question_filter_form,
               'placeholder': 'identifier, group name, text',
               }
    return render(request, 'questions/index.html', context)
Example #3
0
def index(request, qset_id):
    # now I'm gonna call question set a batch of questions.\
        #If there's time, I'll rename them properly
    # So don't get confused :)
    try:
        batch = QuestionSet.get(pk=qset_id)
    except QuestionSet.DoesNotExist:
        raise Http404("No QuestionSet Model matches the given query.")
    questions = batch.questions_inline()
    request_data = request.GET if request.method == 'GET' else request.POST
    question_filter_form = QuestionFilterForm(data=request_data, qset=batch)
    search_fields = ['identifier', 'text', ]
    qset_questions = batch.questions.all()
    if 'q' in request_data:
        questions = get_filterset(qset_questions, request_data['q'], search_fields)
    if 'question_types' in request_data:
        relevant_ids = list(question_filter_form.filter(
            qset_questions).values_list('id', flat=True))
        questions = [q for q in questions if q.id in relevant_ids]
    # now maintain same inline other exclusing questions in
    breadcrumbs = Question.index_breadcrumbs(qset=batch)
    if breadcrumbs:
        request.breadcrumbs(breadcrumbs)
    context = {'questions': questions, 'request': request, 'batch': batch,
               'question_filter_form': question_filter_form,
               'placeholder': 'identifier, text',
               'template_file': 'interviews/answer.html',
               'is_preview': True
               # caution atleast on ODK access
               #  at least on access must exist
               }
    return render(request, 'set_questions/index.html', context)
def filter(request):
    question_lib = QuestionTemplate.objects.all()
    search_fields = ['identifier', 'text', ]
    if request.GET.has_key('q'):
        question_lib = get_filterset(question_lib, request.GET['q'], search_fields)
    question_filter_form = QuestionFilterForm(data=request.GET)
    questions =  question_filter_form.filter(question_lib).values('id', 'text', 'answer_type', 'group', 'module').order_by('text')
    json_dump = json.dumps(list(questions), cls=DjangoJSONEncoder)
    return HttpResponse(json_dump, mimetype='application/json')
def index(request):
    '''
        show all library questions
    '''
    question_filter_form = QuestionFilterForm(data=request.GET or None)
    questions =  question_filter_form.filter(QuestionTemplate.objects.all())
    search_fields = ['identifier', 'group__name', 'text', ]
    if request.GET.has_key('q'):
        questions = get_filterset(questions, request.GET['q'], search_fields)
    context = {'questions': questions, 'request': request,
               'placeholder': 'identifier, group name, text',
               'question_filter_form' : question_filter_form}
    return render(request, 'question_templates/index.html', context)
Example #6
0
def filter(request):
    question_lib = QuestionTemplate.objects.all()
    search_fields = [
        'identifier',
        'text',
    ]
    if 'q' in request.GET:
        question_lib = get_filterset(question_lib, request.GET['q'],
                                     search_fields)
    question_filter_form = QuestionFilterForm(data=request.GET)
    questions = question_filter_form.filter(question_lib).values(
        'id', 'text', 'answer_type', 'module').order_by('text')
    json_dump = json.dumps(list(questions), cls=DjangoJSONEncoder)
    return HttpResponse(json_dump, content_type='application/json')
Example #7
0
def _index(request, batch_id):
    batch = get_object_or_404(Batch, pk=batch_id)
    data = dict(request.GET)
    question_filter_form = QuestionFilterForm(data=data, batch=batch)
    question_library =  question_filter_form.filter(QuestionTemplate.objects.all())
    question_form = QuestionForm(batch)
    question_flow_form = None#QuestionFlowForm()
    question_tree = None
    if batch.start_question:
        question_tree = batch.batch_questions.all()
    context = {'batch': batch, 'batch_question_tree' : question_tree, 'question_form' : question_form, 'button_label' : 'Add',
               'id' : 'question_form', 'action': '#',
               'question_library' : question_library, 'question_filter_form' : question_filter_form,
               'question_flow_form' : question_flow_form}
    return render(request, 'questions/batch_question.html', context)
Example #8
0
def _index(request, batch_id):
    batch = get_object_or_404(Batch, pk=batch_id)
    data = dict(request.GET)
    question_filter_form = QuestionFilterForm(data=data, batch=batch)
    question_library =  question_filter_form.filter(QuestionTemplate.objects.all())
    question_form = QuestionForm(batch)
    question_flow_form = None#QuestionFlowForm()
    question_tree = None
    if batch.start_question:
        question_tree = batch.batch_questions.all()
    context = {'batch': batch, 'batch_question_tree' : question_tree, 'question_form' : question_form, 'button_label' : 'Add',
               'id' : 'question_form', 'action': '#',
               'question_library' : question_library, 'question_filter_form' : question_filter_form,
               'question_flow_form' : question_flow_form}
    return render(request, 'questions/batch_question.html', context)
def index(request, model_class=QuestionTemplate):
    '''
        show all library questions
    '''
    question_filter_form = QuestionFilterForm(data=request.GET or None)
    questions = question_filter_form.filter(model_class.objects.all())
    search_fields = ['identifier', 'text', ]
    if 'q' in request.GET:
        questions = get_filterset(questions, request.GET['q'], search_fields)
    context = {
        'questions': questions,
        'request': request,
        'placeholder': 'identifier, text',
        'question_filter_form': question_filter_form,
        'model_class': model_class}
    if model_class == ParameterTemplate:
        request.breadcrumbs([
            ('Groups', reverse('respondent_groups_page')),
        ])
    return render(request, 'question_templates/index.html', context)
Example #10
0
def index(request):
    '''
        show all library questions
    '''
    question_filter_form = QuestionFilterForm(data=request.GET or None)
    questions = question_filter_form.filter(QuestionTemplate.objects.all())
    search_fields = [
        'identifier',
        'group__name',
        'text',
    ]
    if request.GET.has_key('q'):
        questions = get_filterset(questions, request.GET['q'], search_fields)
    context = {
        'questions': questions,
        'request': request,
        'placeholder': 'identifier, group name, text',
        'question_filter_form': question_filter_form
    }
    return render(request, 'question_templates/index.html', context)
Example #11
0
def index(request, qset_id):
    # now I'm gonna call question set a batch of questions.\
    #If there's time, I'll rename them properly
    # So don't get confused :)
    try:
        batch = QuestionSet.get(pk=qset_id)
    except QuestionSet.DoesNotExist:
        raise Http404("No QuestionSet Model matches the given query.")
    questions = batch.questions_inline()
    request_data = request.GET if request.method == 'GET' else request.POST
    question_filter_form = QuestionFilterForm(data=request_data, qset=batch)
    search_fields = [
        'identifier',
        'text',
    ]
    qset_questions = batch.questions.all()
    if 'q' in request_data:
        questions = get_filterset(qset_questions, request_data['q'],
                                  search_fields)
    if 'question_types' in request_data:
        relevant_ids = list(
            question_filter_form.filter(qset_questions).values_list('id',
                                                                    flat=True))
        questions = [q for q in questions if q.id in relevant_ids]
    # now maintain same inline other exclusing questions in
    breadcrumbs = Question.index_breadcrumbs(qset=batch)
    if breadcrumbs:
        request.breadcrumbs(breadcrumbs)
    context = {
        'questions': questions,
        'request': request,
        'batch': batch,
        'question_filter_form': question_filter_form,
        'placeholder': 'identifier, text',
        'template_file': 'interviews/answer.html',
        'is_preview': True
        # caution atleast on ODK access
        #  at least on access must exist
    }
    return render(request, 'set_questions/index.html', context)
Example #12
0
def index(request, model_class=QuestionTemplate):
    """show all library questions"""
    question_filter_form = QuestionFilterForm(data=request.GET or None)
    questions = question_filter_form.filter(model_class.objects.all())
    search_fields = [
        'identifier',
        'text',
    ]
    if 'q' in request.GET:
        questions = get_filterset(questions, request.GET['q'], search_fields)
    context = {
        'questions': questions,
        'request': request,
        'placeholder': 'identifier, text',
        'question_filter_form': question_filter_form,
        'model_class': model_class
    }
    if model_class == ParameterTemplate:
        request.breadcrumbs([
            ('Groups', reverse('respondent_groups_page')),
        ])
    return render(request, 'question_templates/index.html', context)