Exemple #1
0
def play():
    user: User = current_user
    if not (1 <= user.week <= 7):
        flash(f"Invalid week {user.week}")
        return redirect(url_for("home"))
    match: Match = get_next_match(user.season, user.week)
    if match is None and user.week == 7:
        flash("All 7 weeks completed. Please review the standings. Game Over")
        return redirect(url_for("standings", region=Config.APAC))
    if match is None:
        prepare_for_next_week()
        flash(
            f"Week {user.week} completed. You have been logged out. Login again to start next week"
        )
        return redirect(url_for("logout"))
    form = MatchForm(match)
    if not form.validate_on_submit():
        return render_template("play.html",
                               match=match,
                               form=form,
                               title="Play")
    update_winner(match, winner=form.match_radio.data)
    url = url_for("play")
    if match.type in Config.REGION_CHANGE or \
            (match.type in Config.GROUP_REGION_CHANGE and match.group == Config.GROUP_D):
        url = url_for("results", region=match.region, week=match.week)
    return redirect(url)
Exemple #2
0
def newmatch():
    cancer_suggestion = 'cancer'
    drug_suggestion = 'aspirin'
    form = MatchForm()
    if form.validate_on_submit():
        return redirect(url_for('index'))
    return render_template('newmatch.html', title='New Match', form=form)
Exemple #3
0
 def post(self, request, *args, **kwargs):
     form = MatchForm(request.POST)
     if form.is_valid():
         match = self.get_object()
         values = (float(request.POST.get('p1result')),
               float(request.POST.get('p2result')))
         if match.is_valid_results(values):
             match.update_results(values)
     return HttpResponseRedirect(self.get_object().get_absolute_url())
Exemple #4
0
def match():
    form = MatchForm()
    if form.validate_on_submit():
        session['match_number'] = form.match_number.data
        session['name_number'] = form.name_number.data
        session['match_row'] = form.match_row.data
        session['robot_number'] = form.robot_number.data
        return redirect(url_for('match2'))
    return render_template('match.html', form=form, num=0)
Exemple #5
0
def createamatch():
    formpage = MatchForm()
    if formpage.validate_on_submit():
        match = Match(private_match=formpage.private_match.data,
                      date=formpage.date.data)
        db.session.add(match)
        db.session.commit()
        return redirect(url_for('fieldselection'))
    return render_template('createamatch.html',
                           formpage=formpage,
                           title='Create a match')
Exemple #6
0
def insert(request):
    if request.method == 'POST':  # If the form has been submitted...
        form = MatchForm(request.POST)
        if form.is_valid():
            print('validform')
            post = form.save(commit=True)
            post.save()
            return HttpResponseRedirect('/Match/')
        else:
            print('not valid')
            return HttpResponseRedirect('/Match/')
Exemple #7
0
def insert(request):
    if request.method == 'POST': # If the form has been submitted...
        #postCompetition = Competition.objects.get(pk=request.POST["competition"])
        #postHomeTeam= Team.objects.get(pk=request.POST["homeTeam"])
        #postAwayTeam = Team.objects.get(pk=request.POST["awayTeam"])
        #m = Match(
        #    competition = postCompetition, homeTeam = postHomeTeam, awayTeam = postAwayTeam)
        #m.save()
        form = MatchForm(request.POST)
        if form.is_valid():
            post = form.save(commit=True)
            post.save()
        return HttpResponseRedirect('/Match/')
def match():
    form = MatchForm()
    if form.validate_on_submit():

        # this is the query called NANI 
        result = getMatch(form.preferredPosition.data, form.rankRangeBot.data, form.rankRangeTop,  form.queType.data, current_user.name)
        #result = getMatchedUserInfo(form.)
        print("test")
        print(result)
        if not result:
            flash(f'failed')
        else:    
            flash(f'succesffuly matched')
            print("match type result:")
            print(type(result))
            return redirect(url_for('matchingPage', result = result))
    return render_template('match.html', title='Match', form=form)
def get_match(request):
    match_form = modelform_factory(Match, fields='__all__')
    if request.method == 'POST':
        match_form = MatchForm(request.POST, request.FILES)
        if match_form.is_valid():
            match_form.save()
            return render(request, 'confirmation.html', {'match_form': match_form})
        else:
            print match_form.errors
    else:
        match_form = MatchForm()
    return render(request, 'match.html', {'match_form': match_form})
Exemple #10
0
def new(request):
    form = MatchForm()
    return render(request, 'match/new.html', {'form': form})
Exemple #11
0
def addmatch(request,idfixture):
	try:
		usuario = UserProfile.objects.get(user=request.user)
	except Exception:
		usuario = None
	if request.user.is_anonymous():
		return HttpResponseRedirect('/login')
	if usuario.userType=='PR':
		try:
			publish_one = Publicity.objects.all().order_by('?').first()
		except Exception:
			publish_one = False
		try:
			publish_second = Publicity.objects.all().exclude(id=publish_one.id).order_by('?').last()
		except Exception:
			publish_second = False
		if request.POST:
			mform = MatchForm(request.POST)
			fixture_id = request.GET.get('idfixture')
			if mform.is_valid(): #if the information in the form its correct
				#First, save the default User model provided by Django
				match = Match(
                		day=mform.cleaned_data['day'],
						hour=mform.cleaned_data['hour'],
						minutes=mform.cleaned_data['minutes'],
						teamlocal=mform.cleaned_data['teamlocal'],
						teamVisitant=mform.cleaned_data['teamVisitant'],
						fixture = Fixture.objects.get(id=idfixture),
						court = mform.cleaned_data['court']
                		)
				try:
					f = Fixture.objects.get(id=idfixture)
				except Exception, e:
					message = """
							  Oops!!!, ha ocurrido un inconveniente, el fixture al que intenta agregar un
							  partido aún no ha sido creado.Si el inconveniente persiste contactese.
							  """
					sendmail = True
					return render_to_response('404.html',{'message':message,'sendmail':sendmail})
				if mform.cleaned_data['day']<f.date and mform.cleaned_data['teamlocal']!=mform.cleaned_data['teamVisitant']:
					mform = MatchForm()
					fixture_id = Fixture.objects.get(id=idfixture)
					message_day_incorrect = "La fecha debe ser mayor o igual a "+str(object=f.date)
					return render_to_response('matches/addmatch.html', {'publish_one':publish_one,'publish_second':publish_second,'mform': mform, 'fixture_id':fixture_id,'message_day_incorrect':message_day_incorrect}, RequestContext(request, {}))
				if mform.cleaned_data['teamlocal']==mform.cleaned_data['teamVisitant'] and mform.cleaned_data['day']>=f.date:
					mform = MatchForm()
					fixture_id = Fixture.objects.get(id=idfixture)
					message_teams_incorrect = "el equipo local no pude ser igual al visitante"
					return render_to_response('matches/addmatch.html', {'publish_one':publish_one,'publish_second':publish_second,'mform': mform, 'fixture_id':fixture_id,'message_teams_incorrect':message_teams_incorrect}, RequestContext(request, {}))

				if mform.cleaned_data['teamlocal']==mform.cleaned_data['teamVisitant'] and mform.cleaned_data['day']<f.date:
					mform = MatchForm()
					fixture_id = Fixture.objects.get(id=idfixture)
					message_teams_incorrect = "el equipo local no pude ser igual al visitante"
					message_day_incorrect = "La fecha debe ser mayor o igual a "+str(object=f.date)
					return render_to_response('matches/addmatch.html', {'publish_one':publish_one,'publish_second':publish_second,'mform': mform, 'fixture_id':fixture_id,'message_teams_incorrect':message_teams_incorrect, 'message_day_incorrect':message_day_incorrect}, RequestContext(request, {}))
				if usuario.userType == 'PR':
					match.save()
			else:
				return HttpResponseRedirect('/addmatch/'+str(object=idfixture))
			return HttpResponseRedirect('/fixtures')
		else:
			mform = MatchForm()
			#la sig variable y el if verifica si el fixture es propiedad del usuario logueado
			verify_fixture = Fixture.objects.filter(id=idfixture ,tournament=Tournament.objects.filter(complex=Complex.objects.filter(user=request.user))).count()
			if verify_fixture == 0:
				message = """
						  Oops!!!, ha ocurrido un inconveniente, el fixture al que intenta agregar un
						  partido aún no ha sido creado o no es de su propiedad.Si el inconveniente persiste contactese.
						  """
				sendmail = True
				return render_to_response('404.html',{'message':message,'sendmail':sendmail})
			else:
				fixture_id = Fixture.objects.get(id=idfixture)

		return render_to_response('matches/addmatch.html', {'publish_one':publish_one,'publish_second':publish_second,'mform': mform, 'fixture_id':fixture_id}, RequestContext(request, {}))