/tournament/views.py
Python | 161 lines | 65 code | 59 blank | 37 comment | 7 complexity | cea3d5e87743a22301cf9117e4205015 MD5 | raw file
- #!/usr/bin/env python
- #
- # Copyright 2010 David J Siu
- #
- # Source Code: https://bitbucket.org/davidsiu/nextagsl
- # Website: http://nextagsl.appspot.com/
- #
- # -----------------------------------------------------------------------------
- __author__ = 'David J Siu <davidsiu@gmail.com>'
- # -----------------------------------------------------------------------------
- import os
- import logging
- import time
- import userutils
- from tournament.models import Tournament
- from tournament.models import Registration
- from match.models import Match
- from django.views.generic.simple import direct_to_template
- from django.forms.models import modelformset_factory
- from django.http import HttpResponseRedirect
- from django.shortcuts import get_object_or_404
- # -----------------------------------------------------------------------------
- def tournamentlist(request):
- # Start the performance timer
- startTime = time.time()
-
-
- # The model to pass into the view
- model = {}
-
- # Get the current user data and populate the model
- userutils.getCurrentUserData(request, model)
-
- # Get a list of all the current tournaments
- all_tournaments = Tournament.objects.filter()
- model['all_tournaments'] = all_tournaments
-
-
- # Calculate the performance of the request
- endTime = time.time()
- model['elapsed_time'] = round(endTime - startTime, 5)
-
-
- return direct_to_template(request, 'tournament/tournament.html', model)
- # -----------------------------------------------------------------------------
- def tournamentregister(request, tournament_id):
- # The model to pass into the view
- model = {}
-
- # Get the current user data and populate the model
- userutils.getCurrentUserData(request, model)
-
- # Get a list of all the current tournaments
- current_tournament = get_object_or_404(Tournament, id=tournament_id)
- model['tournament'] = current_tournament
- # Register this user if they are not already registered
- if not current_tournament.is_registration_locked:
- current_member = model['current_member']
- if current_member:
- current_registration = Registration.objects.filter(tournament=tournament_id, member=current_member)
- if not current_registration:
- current_registration = Registration(tournament=current_tournament, member=current_member)
- current_registration.save()
-
-
- return HttpResponseRedirect('/tournament/' + str(tournament_id))
- # -----------------------------------------------------------------------------
- def tournamentdetails(request, tournament_id):
- # Start the performance timer
- startTime = time.time()
-
-
- # The model to pass into the view
- model = {}
-
- # Get the current user data and populate the model
- userutils.getCurrentUserData(request, model)
-
- # Get a list of all the current tournaments
- model['tournament'] = get_object_or_404(Tournament, id=tournament_id)
- # Get a list of all the registrations for this tournament
- registrations = Registration.objects.filter(tournament=tournament_id)
- model['registrations'] = registrations
- # Determine if we need to show the registration link for current user
-
- if 'current_member' in model:
- current_member = model['current_member']
- try:
- current_registration = Registration.objects.get(tournament=tournament_id, member=current_member)
- model['is_signed_up'] = True
- except Registration.DoesNotExist:
- model['is_signed_up'] = False
- # Get the list of matches for the Ro8
- model['ro8_matches'] = Match.objects.filter(tournament=tournament_id, match_type="Round of 8").order_by('match_number')
-
- # Get the list of matches for the Semi-Final
- model['semi_matches'] = Match.objects.filter(tournament=tournament_id, match_type="Semi Finals").order_by('match_number')
-
- # Get the match for the Final
- final_match = Match.objects.filter(tournament=tournament_id, match_type="Final")
- if final_match:
- model['final_match'] = final_match[0]
- # Calculate the performance of the request
- endTime = time.time()
- model['elapsed_time'] = round(endTime - startTime, 5)
-
-
- return direct_to_template(request, 'tournament/tournamentdetails.html', model)
- # -----------------------------------------------------------------------------
- def registrationlist(request):
- # Start the performance timer
- startTime = time.time()
-
-
- # The model to pass into the view
- model = {}
-
- # Get the current user data and populate the model
- userutils.getCurrentUserData(request, model)
-
- # Get a list of all the current registrations
- all_registrations = Registration.objects.filter()
- model['all_registrations'] = all_registrations
-
-
- # Calculate the performance of the request
- endTime = time.time()
- model['elapsed_time'] = round(endTime - startTime, 5)
-
-
- return direct_to_template(request, 'tournament/registration.html', model)