示例#1
0
    def wrapper(request, *args, **kwargs):
        """
                :param kwargs:
                :param args:
                :param request:
                """
        # if current path is the 'testing_app' path, allow navigation
        if request.path == reverse('testing_app'):
            return func(request, *args, **kwargs)

        #check if the current page is a valid successor for the test pages

        test_id = kwargs.get('test_id', None)
        page_id = kwargs.get('page_id', None)
        test_session = TestSession(request.session)
        last_test_id, last_page_id = test_session.get_last_test_page()

        if test_id is not None and page_id is not None:
            if is_page_sequence_valid(test_id, page_id, last_test_id,
                                      last_page_id):
                result = func(request, *args, **kwargs)
                return result
            else:
                return render_default_page(request)
        else:
            return HttpResponseRedirect(reverse('testing_app'))
示例#2
0
 def wrapper(request, *args, **kwargs):
     """Decorator func wrapper
     """
     test_session = TestSession(request.session)
     if test_session.can_display_results():
         return func(request, *args, **kwargs)
     else:
         return render_default_page(request)
示例#3
0
    def wrapper(request, *args, **kwargs):
        """Wraps the function to be decorated

        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        test_id = kwargs.get('test_id', None)
        page_id = kwargs.get('page_id', None)
        test_session = TestSession(request.session)
        test_session.test_id = test_id
        test_session.update_results(request.POST, test_id, page_id)
        return func(request, *args, **kwargs)
示例#4
0
def show_result_view(request, test_id):
    """Shows the results page for the corresponding test_id

    :param test_id: id of the testing_app.models.Test
    :param request:
    """
    #TODO: this also needs to be tested with django-webtest
    context = {}
    test_session = TestSession(request.session)
    test_result = test_session.get_test_result(test_id)
    context['result'] = test_result
    context['home_url'] = request.build_absolute_uri(reverse('testing_app'))

    if test_result is None:
        return render(request, 'testing_app/results_unavailable.html', context)
    else:
        return render(request, 'testing_app/results.html', context)
示例#5
0
def home_view(request):
    #instantiate the template in the dir given (project dir - cuz
    # of TEMPLATES_DIR ) name in the settings module of the project
    #create the context for the view - just fill the list of crap here
    """The view for the testing_app page

    :param request:
    """
    all_tests = Test.objects.all()
    test_session = TestSession(request.session)
    test_session.clear_session()

    paginator = TestPaginator(request.session, all_tests, 3)
    next_page = request.GET.get('next_page', False)
    previous_page = request.GET.get('previous_page', False)
    last_page = request.GET.get('last_page', False)
    first_page = request.GET.get('first_page', False)

    page = paginator.goto_page(next_page, previous_page, first_page, last_page)
    context = {'tests': page.object_list, 'page': page}
    result = render(request, 'testing_app/index.html', context)
    return result