Exemplo n.º 1
0
def test_page(request, unit, section, test_id):
    created = create_user_info(
        request)  # Создать информацию о пользователе, в случае её отсутствия

    unit = unit_list[unit]
    section = unit['section'].objects.get(variable=section)

    element = Test.objects.get(pk=test_id).questions.all()[0]
    element_id = element.id
    title = Test.objects.get(pk=test_id).name
    total = len(Test.objects.get(pk=test_id).questions.all())

    test_type = element.test_type
    options = element.options.split(';')
    random.shuffle(options)

    data = {
        'test_type': test_type,
        'unit': unit['variable'],
        'section': section.variable,
        'test_id': test_id,
        'element_id': element_id
    }

    return render(request, 'test/test.html', locals())
Exemplo n.º 2
0
def unit_page(request, unit):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    unit = unit_list[unit]

    section_list = unit['section'].objects.all()
    return render(request, 'content/unit.html', locals())
Exemplo n.º 3
0
def section_article_page(request, unit, section, id):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    unit = unit_list[unit]
    section = unit['section'].objects.get(variable=section)

    article = Article.objects.get(pk=id)
    return render(request, 'content/article.html', locals())
Exemplo n.º 4
0
def start_page(request):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    articles = Article.objects.filter(is_main=True)
    last_articles = list()
    for article in articles:
        last_articles.append(article)
    last_articles.reverse()
    last_articles = last_articles[0:6]
    return render(request, 'start.html', locals())
Exemplo n.º 5
0
def articles_page(request, theme):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    themes = ArticleTheme.objects.all()
    articles = Article.objects.filter(is_main=True)
    if not(theme == 'all'):
        theme = ArticleTheme.objects.get(variable=theme)
        articles = articles.filter(theme=theme)
    article_list = list()
    for article in articles:
        article_list.append(article)
    article_list.reverse()
    return render(request, 'content/articles.html', locals())
Exemplo n.º 6
0
def section_page(request, unit, section):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    unit = unit_list[unit]
    section = unit['section'].objects.get(variable=section)

    if request.user.is_authenticated:
        user_info = UserInfo.objects.get(user=request.user)
        if user_info.data:
            user_data = user_info.get_data()
        else:
            user_data = dict()

    elements = list()
    for element in section.get_content():
        if element['type'] == 'article':
            article = Article.objects.get(pk=element['id'])
            elements.append({'name': article.title, 'type': 'article',
                             'url': article.id, 'description': article.description,
                             'image': article.image})
        elif element['type'] == 'test':
            test = Test.objects.get(pk=element['id'])

            total = len(test.questions.all())
            if request.user.is_authenticated:
                if not (unit['variable'] + "_" + section.variable + "_" + str(test.id) in user_data.keys()):
                    user_data[unit['variable'] + "_" + section.variable + "_" + str(test.id)] = {'correct': 0, 'incorrect': 0,
                                                                                          'incorrect_list': []}
                    user_info.set_data(user_data)
                    user_info.save()
                correct = user_data[unit['variable'] + "_" + section.variable + "_" + str(test.id)]['correct']
                incorrect = user_data[unit['variable'] + "_" + section.variable + "_" + str(test.id)]['incorrect']
                correct_percent = round((int(correct) / total) * 100)
                incorrect_percent = round((int(incorrect) / total) * 100)
            else:
                correct_percent = 0
                incorrect_percent = 0
            elements.append({'name': test.name, 'type': 'test',
                             'url': test.id, 'description': test.description,
                             'image': test.image,
                             'correct': correct_percent, 'incorrect': incorrect_percent})

    return render(request, 'content/section.html', locals())
Exemplo n.º 7
0
def stat_page(request, unit, section, test_id):
    created = create_user_info(
        request)  # Создать информацию о пользователе, в случае её отсутствия

    unit = unit_list[unit]
    section = unit['section'].objects.get(variable=section)
    test_name = Test.objects.get(pk=test_id).name

    # Если пользователь зарегистрирован, то загрузить статистику
    if request.user.is_authenticated:
        user_info = UserInfo.objects.get(user=request.user)
        user_data = user_info.get_data()

        if not (unit['variable'] + "_" + section.variable + "_" + test_id
                in user_data.keys()):
            user_data[unit['variable'] + "_" + section.variable + "_" +
                      test_id] = {
                          'correct': 0,
                          'incorrect': 0,
                          'incorrect_list': []
                      }

        element_class = Question
        total = len(Test.objects.get(pk=test_id).questions.all())

        correct = user_data[unit['variable'] + "_" + section.variable + "_" +
                            test_id]['correct']
        incorrect = user_data[unit['variable'] + "_" + section.variable + "_" +
                              test_id]['incorrect']
        incorrect_list = list()
        for e in user_data[unit['variable'] + "_" + section.variable + "_" +
                           test_id]['incorrect_list']:
            incorrect_list.append(element_class.objects.get(pk=e))

        correct_percent = round((int(correct) / total) * 100)
        incorrect_percent = 100 - correct_percent

    return render(request, 'test/stat.html', locals())
Exemplo n.º 8
0
def article_page(request, id):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    article = Article.objects.get(pk=id)
    return render(request, 'content/article.html', locals())
Exemplo n.º 9
0
def license_page(request):
    created = create_user_info(request)  # Создать информацию о пользователе, в случае её отсутствия

    return render(request, 'content/license.html', locals())