2021-12-08 19:28:56 +01:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.template import loader
|
2021-12-20 19:40:24 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2021-12-23 14:03:12 +01:00
|
|
|
from trials.models import Test
|
2022-05-15 16:01:52 +02:00
|
|
|
import operator
|
2021-12-08 19:28:56 +01:00
|
|
|
|
|
|
|
|
2021-12-20 19:40:24 +01:00
|
|
|
@login_required
|
|
|
|
def home(request):
|
2021-12-23 14:03:12 +01:00
|
|
|
context = {}
|
2022-01-17 17:38:53 +01:00
|
|
|
# TODO replace
|
|
|
|
#context['tests'] = Test.objects.filter(owner=request.user)
|
2022-03-30 23:01:39 +02:00
|
|
|
#context['tests'] = Test.objects.all
|
2022-04-09 13:02:21 +02:00
|
|
|
context['tests'] = Test.objects.filter(visible=True)
|
2022-01-19 20:56:00 +01:00
|
|
|
return render(request, 'home.html', context)
|
2021-12-20 19:40:24 +01:00
|
|
|
|
|
|
|
|
2022-01-19 21:17:45 +01:00
|
|
|
@login_required
|
|
|
|
def help(request):
|
2022-06-05 17:38:05 +02:00
|
|
|
return render(request, 'help-new.html', )
|
2022-01-19 21:17:45 +01:00
|
|
|
|
2022-06-08 23:24:17 +02:00
|
|
|
|
|
|
|
def helpp(request, help_id):
|
|
|
|
return render(request, f'help_{help_id}.html', )
|
|
|
|
|
|
|
|
|
2022-05-15 16:01:52 +02:00
|
|
|
@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)
|
|
|
|
|
2021-12-20 19:40:24 +01:00
|
|
|
def welcome(request):
|
|
|
|
return render(request, 'welcome.html')
|