Exemple #1
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)
	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)
Exemple #3
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)
Exemple #4
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)