# Path: src/ctf_gameserver/web/scoring/decorators.py
# def registration_closed_required(view):
#     """
#     View decorator which only allows access to the decorated view if registration is closed from the
#     GameControl object.
#     Format of the response is currently always JSON.
#     """
# 
#     @wraps(view)
#     def func(request, *args, **kwargs):
#         if GameControl.get_instance().registration_open:
#             return JsonResponse({'error': 'Not available yet'}, status=404)
# 
#         return view(request, *args, **kwargs)
# 
#     return func
# 
# def services_public_required(resp_format):
#     """
#     View decorator which prohibits access to the decorated view if information about the services is not
#     public yet.
# 
#     Args:
#         resp_format: Format of the response when the competition has not yet started. Supported options are
#                      'html' and 'json'.
#     """
# 
#     def decorator(view):
#         @wraps(view)
#         def func(request, *args, **kwargs):
#             game_control = GameControl.get_instance()
#             if game_control.are_services_public():
#                 return view(request, *args, **kwargs)
# 
#             if resp_format == 'json':
#                 return JsonResponse({'error': 'Not available yet'}, status=404)
#             else:
#                 messages.error(request, _('Sorry, the page you requested is not available yet.'))
#                 return redirect(settings.HOME_URL)
# 
#         return func
# 
#     return decorator


from collections import defaultdict
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.db.models import Max
from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from . import models, calculations
from .decorators import registration_closed_required, services_public_required
import ctf_gameserver.web.registration.models as registration_models





@services_public_required('html')
def scoreboard(request):

    return render(request, 'scoreboard.html', {
        'services': models.Service.objects.all()
    })


# Short cache timeout only, because there is already caching going on in calculations
@cache_page(5)

# Path: src/ctf_gameserver/web/scoring/decorators.py
# def registration_closed_required(view):
#     """
#     View decorator which only allows access to the decorated view if registration is closed from the
#     GameControl object.
#     Format of the response is currently always JSON.
#     """
# 
#     @wraps(view)
#     def func(request, *args, **kwargs):
#         if GameControl.get_instance().registration_open:
#             return JsonResponse({'error': 'Not available yet'}, status=404)
# 
#         return view(request, *args, **kwargs)
# 
#     return func
# 
# def services_public_required(resp_format):
#     """
#     View decorator which prohibits access to the decorated view if information about the services is not
#     public yet.
# 
#     Args:
#         resp_format: Format of the response when the competition has not yet started. Supported options are
#                      'html' and 'json'.
#     """
# 
#     def decorator(view):
#         @wraps(view)
#         def func(request, *args, **kwargs):
#             game_control = GameControl.get_instance()
#             if game_control.are_services_public():
#                 return view(request, *args, **kwargs)
# 
#             if resp_format == 'json':
#                 return JsonResponse({'error': 'Not available yet'}, status=404)
#             else:
#                 messages.error(request, _('Sorry, the page you requested is not available yet.'))
#                 return redirect(settings.HOME_URL)
# 
#         return func
# 
#     return decorator


# Path: src/ctf_gameserver/web/scoring/views.py
from collections import defaultdict
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.db.models import Max
from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from . import models, calculations
from .decorators import registration_closed_required, services_public_required
import ctf_gameserver.web.registration.models as registration_models






@services_public_required('html')
def scoreboard(request):

    return render(request, 'scoreboard.html', {
        'services': models.Service.objects.all()
    })


# Short cache timeout only, because there is already caching going on in calculations
@cache_page(5)

@services_public_required('json')