43 lines
1.2 KiB
Python
43 lines
1.2 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-new.html', )
|
|
|
|
|
|
def helpp(request, help_id):
|
|
return render(request, f'help_{help_id}.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')
|