Esempio n. 1
0
	def get(self):
		user = tusers.get_current_user()

		#Get the institution
		i = self.request.get('i')
		i_key = ndb.Key(urlsafe=i)
		institution = i_key.get()

		reg = i_key.parent().get()

		if institution.authorised(user) and reg.open and institution.teams().count(limit=20)<20:
			if self.request.get('type') == 't':
				#Register a new Team
				team = InstitutionTeam(parent=institution.key)
				team.put()

			if self.request.get('type') == 'j':
				#Register a new judge
				judge = InstitutionJudge(parent=institution.key)
				judge.put()

		self.redirect(self.request.referer)
Esempio n. 2
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:

      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:
          #Check they haven't registered already
          if reg.isRegistered(user):
            self.redirect('/reg?t=' + tid)
            return

          inst = RegisteredInstitution(parent=reg.key)
          inst.user = user.key

        inst.name = form.name.data
        inst.user = user.key

        inst.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)