Exemple #1
0
	def post(self):
		user = tusers.get_current_user()
		form = JudgeForm(self.request.POST)

		j = self.request.get('j')
		j_key = ndb.Key(urlsafe=j)
		judge = j_key.get()

		reg = None
		institution = None

		if judge.authorised(user):


			if isinstance(judge, InstitutionJudge):
				institution = j_key.parent().get()
				reg = institution.key.parent().get()

				form.email.data = institution.email
				form.phone.data = institution.phone

			elif isinstance(judge, RegisteredIndependentJudge):
				reg = j_key.parent().get()

			t = reg.key.parent().get()

			if (form.validate()):

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

				judge.put()

				self.redirect('/reg_control?t=' + str(t.key.id()))
			else:
				template_values = {
					'user' : user,
					't' : t,
					'logout' : tusers.create_logout_url('/'),
					'login' : tusers.create_login_url('/mod/judge?j=' + j),
					'r' : reg,
					'form' : form,
					'institution' : institution,
				}
				template = JINJA_ENVIRONMENT.get_template('view/modjudge.html')
				self.response.write(template.render(template_values))
		else:
			self.redirect(self.request.referer)
Exemple #2
0
def enter_judge(request):
    if request.method == 'POST':
        form = JudgeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response(
                    'error.html', {
                        'error_type': "Judge",
                        'error_name': "[" + cd['name'] + "]",
                        'error_info': "Judge Cannot Validate!"
                    },
                    context_instance=RequestContext(request))
            return render_to_response(
                'thanks.html', {
                    'data_type': "Judge",
                    'data_name': "[" + form.cleaned_data['name'] + "]",
                    'data_modification': "CREATED",
                    'enter_again': True
                },
                context_instance=RequestContext(request))
    else:
        form = JudgeForm(first_entry=True)
    return render_to_response('data_entry.html', {
        'form': form,
        'title': "Create Judge"
    },
                              context_instance=RequestContext(request))
Exemple #3
0
def view_judge(request, judge_id):
    judge_id = int(judge_id)
    try:
        judge = Judge.objects.get(pk=judge_id)
    except Judge.DoesNotExist:
        return render_to_response('error.html', 
                                 {'error_type': "View Judge",
                                  'error_name': str(judge_id),
                                  'error_info':"No such judge"}, 
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = JudgeForm(request.POST,instance=judge)
        if form.is_valid():
            try:
               form.save()
            except ValueError:
                return render_to_response('error.html', 
                                         {'error_type': "Judge",
                                          'error_name': "["+form.cleaned_data['name']+"]",
                                          'error_info':"Judge information cannot be validated."}, 
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html', 
                                     {'data_type': "Judge",
                                      'data_name': "["+form.cleaned_data['name']+"]",
                                      'data_modification': "EDIT"}, 
                                      context_instance=RequestContext(request))
        else :
            return render_to_response('error.html', 
                                     {'error_type': "Judge",
                                      'error_name': "",
                                      'error_info': form.errors}, 
                                      context_instance=RequestContext(request))
    else:
        form = JudgeForm(instance=judge)
        base_url = '/judge/'+str(judge_id)+'/'
        scratch_url = base_url + 'scratches/view/'
        delete_url =  base_url + 'delete/'
        links = [(scratch_url,'Scratches for '+str(judge.name),False),
                 (delete_url,'Delete', True)]
        return render_to_response('data_entry.html', 
                                 {'form': form,
                                  'links': links,
                                  'title': "Viewing Judge: %s" %(judge.name)}, 
                                  context_instance=RequestContext(request))
Exemple #4
0
def enter_judge(request):
    if request.method == 'POST':
        form = JudgeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response('error.html',
                                         {'error_type': "Judge",
                                          'error_name': "["+cd['name']+"]",
                                          'error_info': "Judge Cannot Validate!"},
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html',
                                     {'data_type': "Judge",
                                      'data_name': "["+form.cleaned_data['name']+"]",
                                      'data_modification': "CREATED",
                                      'enter_again': True},
                                      context_instance=RequestContext(request))
    else:
        form = JudgeForm(first_entry=True)
    return render_to_response('data_entry.html',
                              {'form': form, 'title': "Create Judge"},
                              context_instance=RequestContext(request))
Exemple #5
0
def view_judge(request, judge_id):
    judge_id = int(judge_id)
    try:
        judge = Judge.objects.get(pk=judge_id)
    except Judge.DoesNotExist:
        return render_to_response('error.html', {
            'error_type': "View Judge",
            'error_name': str(judge_id),
            'error_info': "No such judge"
        },
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = JudgeForm(request.POST, instance=judge)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response(
                    'error.html', {
                        'error_type': "Judge",
                        'error_name': "[" + form.cleaned_data['name'] + "]",
                        'error_info': "Judge information cannot be validated."
                    },
                    context_instance=RequestContext(request))
            return render_to_response(
                'thanks.html', {
                    'data_type': "Judge",
                    'data_name': "[" + form.cleaned_data['name'] + "]",
                    'data_modification': "EDIT"
                },
                context_instance=RequestContext(request))
        else:
            return render_to_response('error.html', {
                'error_type': "Judge",
                'error_name': "",
                'error_info': form.errors
            },
                                      context_instance=RequestContext(request))
    else:
        form = JudgeForm(instance=judge)
        base_url = '/judge/' + str(judge_id) + '/'
        scratch_url = base_url + 'scratches/view/'
        delete_url = base_url + 'delete/'
        links = [(scratch_url, 'Scratches for ' + str(judge.name), False),
                 (delete_url, 'Delete', True)]
        return render_to_response('data_entry.html', {
            'form': form,
            'links': links,
            'title': "Viewing Judge: %s" % (judge.name)
        },
                                  context_instance=RequestContext(request))
Exemple #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 = "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)
Exemple #7
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)