Beispiel #1
0
	def get(self):
		user = tusers.get_current_user()
		
		if user:
			
			#Get a list of tournaments that the user owns
			owner_q = Tournament.query(Tournament.owner == user.key)

			#Get a list of tournaments that the user is attending
			attend_q = Attending.query(ancestor=user.key)


			#Build a list of tournaments to pass to the view
			tournaments = []
			for a in attend_q:
				tournament = tournament_bean()
				tournament.tournament = a.tournament.get()
				tournament.role = a.role
				tournaments.append(tournament)


			template_values = {
				'user' : user,
				'tournaments' : owner_q,
				'attending' : tournaments,
				'logout' : tusers.create_logout_url('/'),
			}
			template = JINJA_ENVIRONMENT.get_template('view/tournaments.html')
			self.response.write(template.render(template_values))
		else:
			self.redirect(tusers.create_login_url(self.request.uri))
Beispiel #2
0
	def post(self):
		user = tusers.get_current_user()

		#Get the requested tournament
		key = ndb.Key(urlsafe=self.request.get('institution'))
		institution = key.get()

		if institution.authorised(user):
			#Remove the attendance record
			q = Attending.query(ancestor=user.key)
			q.filter(Attending.tournament == key.parent().parent())
			q.get(keys_only=True).delete()

			institution.destroy()

		self.redirect(self.request.referer)
Beispiel #3
0
	def post(self):
		user = tusers.get_current_user()

		#Check if the t_key parameter is un use
		if self.request.get('t_key', default_value=False):
			key = ndb.Key(urlsafe=self.request.get('t_key'))
			t = key.get()

			if t.authorised(user):

				#Remove the attendance record
				q = Attending.query(ancestor=user.key)
				q.filter(Attending.tournament == key.parent().parent())
				q.get(keys_only=True).delete()

				key.delete()
		self.redirect(self.request.referer)
Beispiel #4
0
	def post(self):
		user = tusers.get_current_user()

		#Check if the j_key parameter is in use.
		if self.request.get('j_key', default_value=False):
			key = ndb.Key(urlsafe=self.request.get('j_key'))
			j = key.get()

			#Delete from the database
			if j.authorised(user):
				if key.kind() == 'RegisteredIndependentJudge':
					#Remove the attendance record
					q = Attending.query(ancestor=user.key)
					q.filter(Attending.tournament == key.parent().parent())
					q.get(keys_only=True).delete()

				key.delete()

		self.redirect(self.request.referer)
Beispiel #5
0
	def post(self):
		user = tusers.get_current_user()
		#Get the requested tournament
		tid = self.request.get('t')
		key = ndb.Key('Tournament', int(tid))
		t = key.get()
		reg = t.preRegRecord().get()

					
		if user:

			#Check they haven't registered already
			if reg.isRegistered(user):
				self.redirect('/reg?t=' + tid)
				return

			form = JudgeForm(self.request.POST)

			#If valid, create the new judge object
			if (form.validate()):
				
				#Check if we are updating an existing judge
				if not self.request.get('j'):
					judge = RegisteredIndependentJudge(parent=reg.key)
					judge.user = user.key

				else:
					judge = ndb.Key('Tournament', int(tid), 'PreRegRecord', reg.key.id(), 'RegisteredIndependentJudge', int(self.request.get('j'))).get()

				#Check we are authorised
				if not ((judge.user == user.key) or (user.key in t.owner)):
					judge = None
					self.redirect('/')

				judge.name = form.name.data
				judge.phone = form.phone.data
				judge.email = form.email.data
				judge.cv = form.cv.data

				judge.put()

				#Add an attendance record
				attending = Attending(parent=user.key)
				attending.role = "Judge"
				attending.tournament = t.key
				attending.put()

				
				self.redirect('/reg?t=' + tid)
			else:
				template_values = {
					'user' : user,
					't' : t,
					'logout' : tusers.create_logout_url('/'),
					'login' : tusers.create_login_url('/reg/judge?t=' + tid),
					'r' : reg,
					'form' : form,
				}
				template = JINJA_ENVIRONMENT.get_template('view/regjudge.html')
				self.response.write(template.render(template_values))
		else:
			self.redirect('/reg?t=' + tid)
Beispiel #6
0
    def post(self):
        user = tusers.get_current_user()
        # Get the requested tournament
        tid = self.request.get("t")
        key = ndb.Key("Tournament", int(tid))
        t = key.get()
        reg = t.preRegRecord().get()

        if user:

            # Check they haven't registered already
            if reg.isRegistered(user):
                self.redirect("/reg?t=" + tid)
                return

            form = JudgeForm(self.request.POST)

            # If valid, create the new judge object
            if form.validate():

                # Check if we are updating an existing judge
                if not self.request.get("j"):
                    judge = RegisteredIndependentJudge(parent=reg.key)
                    judge.user = user.key

                else:
                    judge = ndb.Key(
                        "Tournament",
                        int(tid),
                        "PreRegRecord",
                        reg.key.id(),
                        "RegisteredIndependentJudge",
                        int(self.request.get("j")),
                    ).get()

                    # Check we are authorised
                if not ((judge.user == user.key) or (user.key in t.owner)):
                    judge = None
                    self.redirect("/")

                judge.name = form.name.data
                judge.phone = form.phone.data
                judge.email = form.email.data
                judge.cv = form.cv.data

                judge.put()

                # Add an attendance record
                attending = Attending(parent=user.key)
                attending.role = "Institution"
                attending.tournament = t.key
                attending.put()

                self.redirect("/reg?t=" + tid)
            else:
                template_values = {
                    "user": user,
                    "t": t,
                    "logout": tusers.create_logout_url("/"),
                    "login": tusers.create_login_url("/reg/judge?t=" + tid),
                    "r": reg,
                    "form": form,
                }
                template = JINJA_ENVIRONMENT.get_template("view/regjudge.html")
                self.response.write(template.render(template_values))
        else:
            self.redirect("/reg?t=" + tid)
	def post(self):
		user = tusers.get_current_user()
		#Get the requested tournament
		tid = self.request.get('t')
		key = ndb.Key('Tournament', int(tid))
		t = key.get()
		reg = t.preRegRecord().get()
		
		if user:
			#Check they haven't registered already
			if reg.isRegistered(user):
				self.redirect('/reg?t=' + tid)
				return

			form = InstRegForm(self.request.POST)
			if (form.validate()):
				
				#If we are updating an existing registration, update it.
				if 'instkey' in self.request.arguments():
					instkey = (self.request.get('instkey'))
					inst = ndb.Key(urlsafe=instkey).get()
					
					#Check they own it
					if inst.user != user.key:
						self.redirect('/reg?t=' + tid)
				
				#Otherwise, make a new institution registration
				else:
					inst = RegisteredInstitution(parent=reg.key)
				
				inst.leadName = form.leadName.data
				inst.phone = form.phone.data
				inst.email = form.email.data
				inst.name = form.name.data
				inst.user = user.key
				
				inst.put()

				#Add an attendance record
				attending = Attending(parent=user.key)
				attending.role = "Institution"
				attending.tournament = t.key
				attending.put()
				
				#Add teams and judges
				if 'nTeams' in self.request.arguments():
					nTeams = int(self.request.get('nTeams'))
					if nTeams > MAX_REG:
						nTeams = MAX_REG
					for i in range(nTeams):
						team = InstitutionTeam(parent=inst.key)
						team.put()
						
				if 'nJudges' in self.request.arguments():
					nJudges = int(self.request.get('nJudges'))
					if nJudges > MAX_REG:
						nJudges = MAX_REG
					for i in range(nJudges):
						judge = InstitutionJudge(parent=inst.key)
						judge.put()
					
				self.redirect('/reg?t=' + tid)
				
			#If the form is invalid, show it again with errors.
			else:
				logging.info('invalid form')
				template_values = {
					'user' : user,
					't' : t,
					'logout' : tusers.create_logout_url('/'),
					'login' : tusers.create_login_url('/reg/team?t=' + tid),
					'r' : reg,
					'form' : form		
				}
				template = JINJA_ENVIRONMENT.get_template('view/reginstitution.html')
				self.response.write(template.render(template_values))
			
			
		else:
			self.redirect('/reg?t=' + tid)
Beispiel #8
0
	def post(self):
		user = tusers.get_current_user()
		#Get the requested tournament
		tid = self.request.get('t')
		key = ndb.Key('Tournament', int(tid))
		t = key.get()
		reg = t.preRegRecord().get()
					
		if user:

			#Check they haven't registered already
			if reg.isRegistered(user):
				self.redirect('/reg?t=' + tid)
				return

			form = TeamForm(self.request.POST)
			if (form.validate()):
				
				#If we are updating an existing registration, update it.
				if 'teamkey' in self.request.arguments():
					teamkey = (self.request.get('teamkey'))
					team = ndb.Key(urlsafe=teamkey).get()
					
					#Check they own it
					if team.user != user.key:
						self.redirect('/reg?t=' + tid)
				
				#Otherwise, make a new team registration
				else:
					team = RegisteredOpenTeam(parent=reg.key)
				
				team.leadName = form.leadName.data
				team.phone = form.phone.data
				team.email = form.email.data
				team.teamName = form.teamName.data
				team.sp1Name = form.sp1Name.data
				team.sp2Name = form.sp2Name.data
				team.sp1ESL = form.sp1ESL.data
				team.sp2ESL = form.sp2ESL.data
				team.sp1Novice = form.sp1Novice.data
				team.sp2Novice = form.sp2Novice.data
				team.leadname = form.leadName.data
				team.user = user.key
				
				team.put()

				#Add an attendance record
				attending = Attending(parent=user.key)
				attending.role = "Open Team"
				attending.tournament = t.key
				attending.put()

				
				self.redirect('/reg?t=' + tid)
			else:
				logging.info('invalid form')
				template_values = {
					'user' : user,
					't' : t,
					'logout' : tusers.create_logout_url('/'),
					'login' : tusers.create_login_url('/reg/team?t=' + tid),
					'r' : reg,
					'form' : form		
				}
				template = JINJA_ENVIRONMENT.get_template('view/regteam.html')
				self.response.write(template.render(template_values))
			
			
		else:
			self.redirect('/reg?t=' + tid)