SOITA/config/views.py
2022-05-15 22:12:32 +02:00

38 lines
1.1 KiB
Python

from django.shortcuts import render, redirect
from django.template import loader
from django.contrib.auth.decorators import login_required
from trials.models import Test
import operator
@login_required
def home(request):
context = {}
# TODO replace
#context['tests'] = Test.objects.filter(owner=request.user)
#context['tests'] = Test.objects.all
context['tests'] = Test.objects.filter(visible=True)
return render(request, 'home.html', context)
@login_required
def help(request):
return render(request, 'help.html', )
@login_required
def popular(request):
context = {}
context['tests'] = Test.objects.filter(avg_rating__gt=0)
context['tests'] = sorted(context['tests'], key=operator.attrgetter('avg_rating'), reverse=True)
return render(request, 'popular.html', context)
@login_required
def hard(request):
context = {}
context['tests'] = Test.objects.filter(difficulty_label__gt=0)
context['tests'] = sorted(context['tests'], key=operator.attrgetter('difficulty_label'), reverse=True)
return render(request, 'hard.html', context)
def welcome(request):
return render(request, 'welcome.html')