예제 #1
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)
예제 #2
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)