Exemple #1
0
def recoverAccount(request):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/my-tournaments/')

	try:
		lang = strLang()
	except:
		lang = ''

	# Info about user
	user_me = request.user

	if request.method == 'POST':
		recoverUserForm = RecoverUserForm(request.POST, request=request) # A form bound to the POST data
		if recoverUserForm.is_valid():
			user = User.objects.get(username=request.POST['username'], email=request.POST['email'])
			rkey = "".join(random.sample(string.letters+string.digits, 16))
			
			recoverUser = RecoverUser(user=user,code=rkey)
			recoverUser.save()
			# We show a notification user
			try:
 				box = setBox('success_recover_account_email_sent')
			except:
				box = ''
				
			recoverUserForm = RecoverUserForm()
			
			notify_user(user, 'recover_user', recoverUser)

			return render_to_response('recoveruser.html', {
				'user_me': user_me,
				'recoverUserForm': recoverUserForm,
				'box': box,
				'lang': lang,				
			})
		else:
			return render_to_response('recoveruser.html', {
				'user_me': user_me,
				'recoverUserForm': recoverUserForm,
				'lang': lang,	
			})
	else: # If get request, generate a new form
		recoverUserForm = RecoverUserForm()

		# Must we show a notification user?
		try:
	 		if request.GET['status']:
	 			box = setBox(request.GET['status'])
		except:
			box = ''

		return render_to_response('recoveruser.html', {
			'user_me': user_me,
			'recoverUserForm': recoverUserForm,
			'lang': lang,		
			'box': box,	
		})
Exemple #2
0
def questionReview(request,qrid):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/register')

	if request.user.has_perm('fleq.quizbowl.add_tournament'):
		admin_user = True
	else:
		admin_user = False

	# Check if exists
	try:
		questionReview = Question_review.objects.get(pk = qrid)
	except:
		questionReview = ''

	# SIDEBAR INFO
	myTournaments = myActiveTournaments(request)
	myAdmnTournaments = myAdminTournaments(request)
	todayGames = myTodayGames(request)
	nextGames = myNextGames(request)
	user_me = UserProfile.objects.get(user=request.user)
	pendingQR = myAdminPendingQuestionReviews(request.user)

	# Load strings language to template questionreviews.html
	try:
		lang = strLang()
	except:
		lang = ''
	
	# Only for admin reply
	if request.method == "POST" and request.POST['resolution']:
		questionReview.resolution = request.POST['resolution']
		questionReview.save()
		notify_user(questionReview.player, 'review_closed', questionReview)
		return HttpResponseRedirect('/question-review/' + qrid + '?status=success_resolution')	
	else:
		# Must we show a notification user?
		try:
	 		if request.GET['status']:
	 			box = setBox(request.GET['status'])
		except:
			box = ''
	
		return render_to_response('questionreview.html', {
			'user_me': user_me,
			'questionReview': questionReview,
			'lang': lang,
			'box': box,
			'myTournaments': myTournaments,
			'myAdminTournaments': myAdmnTournaments,
			'todayGames': todayGames,
			'nextGames': nextGames,
			'admin_user': admin_user,	
			'pendingQR': pendingQR,	
		})
Exemple #3
0
def selectStartTime(request, gid):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/register')

	game = Game.objects.get(id = gid)
	print "VIEWGAMES"
	pst = Preferred_start_time.objects.get(game = game, player = request.user)
  	print pst
	dateNow = datetime.datetime.now()

	if request.method == 'POST' and pst: # If the form has been submitted... save hour
		gameDate = pst.game.start_time.date()
		for time in request.POST.getlist('time'):
			hourSelected =  int(time)
			dateSelected = request.POST['date'].split('/')
			date = datetime.datetime(int(dateSelected[0]), int(dateSelected[1]), int(dateSelected[2]), hourSelected, 0, 0)

			# Check if dateTime exists in our database
			checkDate = Date_time.objects.filter(date_time = date, preferred_start_time = pst)
			if not checkDate and date > dateNow:
				print date.hour
				print dateNow.hour
				if date.date() == dateNow.date() and date.hour - dateNow.hour <= 1:
					return HttpResponseRedirect('/my-next-games/?status=error_datetime_selected_too_soon') # Redirect after POST
				else:
					dateTime = Date_time(date_time = date, preferred_start_time = pst)
					dateTime.save()
					pst.committed = True
					pst.save()
			else:
				if date <= dateNow or checkDate:
					return HttpResponseRedirect('/my-next-games/?status=error_datetime_selected_before') # Redirect after POST
      
      # Check if players saved the same hour to play
		pst = Preferred_start_time.objects.filter(game = pst.game)
		if pst[0].committed and pst[1].committed:
			d_t1 = Date_time.objects.filter(preferred_start_time = pst[0])
			d_t2 = Date_time.objects.filter(preferred_start_time = pst[1])
			for d_t_player1 in d_t1:
				for d_t_player2 in d_t2:
					if d_t_player1.date_time == d_t_player2.date_time and not game.start_time_committed:
						game.start_time = d_t_player1.date_time
						game.start_time_committed = True
						game.save()
						notify_user(game.player1, 'time_commited', game)
						notify_user(game.player2, 'time_commited', game)
						return HttpResponseRedirect('/my-next-games/?status=success_datetime_committed') # Redirect after POST
           
		return HttpResponseRedirect('/my-next-games/?status=success_datetime_selected') # Redirect after POST
	else:
		HttpResponseRedirect('/my-tournaments/')
Exemple #4
0
def SelectStartTime(request, gid):

	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')


	game = Game.objects.get(id = gid)
	pst = Preferred_start_time.objects.get(game = game, player = request.user)

	if request.user != game.player1 and request.user != game.player2 and request.user.username == "FLEQBOT":
		return HttpResponseRedirect('/')

	if game.is_over():
		return HttpResponseRedirect('/')

	if game.start_time_committed:
		return HttpResponseRedirect('/game-room/' + gid)

	now = datetime.datetime.now()

	g = game

	# Save all dates of my uncommitted games to select date and time to play
	myUncommittedGamesDate = [] # Contains all options to select in my next games

	startDate = g.round.start_date
	finishDate = g.round.finish_date
	
	while startDate <= finishDate:
		
		# Si hoy pertenece a la ronda...
		if startDate >= datetime.datetime.now().date():
						
			hour = now.hour
			hour += 2
			while hour < 24:
				d = {}
				d['gid'] = g.pk
				d['date'] = datetime.datetime(startDate.year, startDate.month, startDate.day, hour, 0)
				d['dateslashed'] = str(hour) + "/" + str(startDate.day) + "/" + str(startDate.month) + "/" + str(startDate.year)
				hour += 1
				myUncommittedGamesDate.append(d)
		
		# Si hoy no pertenece a la ronda, mostramos las 24 horas
		else:
			for hour in range(0,24):
				d = {}
				d['gid'] = g.pk
				d['date'] = datetime.datetime(startDate.year, startDate.month, startDate.day, hour, 0)
				d['dateslashed'] = str(hour) + str(startDate.day) + "/" + str(startDate.month) + "/" + str(startDate.year)
				hour += 1
				myUncommittedGamesDate.append(d)			

		startDate = startDate + timedelta(days=1)


	# Horas del dia siguiente hasta las 8 (UTC)
	hour = 0
	for hour in range(0, 8):
		d = {}
		d['gid'] = g.pk
		d['date'] = datetime.datetime(startDate.year, startDate.month, startDate.day, hour, 0)
		d['dateslashed'] = str(hour) + "/" + str(startDate.day) + "/" + str(startDate.month) + "/" + str(startDate.year)
		hour += 1
		myUncommittedGamesDate.append(d)		



	if request.method == "GET":
		hour = now.hour

		# Extract all dates and times selected by user to show them
		mySelectedGamesDate = [] # Contains all options selected by user to each game
		opponentSelectedGamesDate = [] # Contains all options selected by opponent to each game

		# Select game preferences by user
		mySelection = Preferred_start_time.objects.filter(Q(player = request.user), Q(game = g))
		for selection in mySelection:
			# Extract all datetimes selected by user to show them
			myDateTimesSelected = Date_time.objects.filter(Q(preferred_start_time = selection)).order_by('date_time')			
			for dateSelected in myDateTimesSelected:
				s = {}
				s['gid'] = g.pk
				s['date'] = dateSelected
				mySelectedGamesDate.append(s)
				
		# Select game preferences by opponent
		if g.player1 == request.user:
			opponent = g.player2
		else:
			opponent = g.player1

		opponentSelection = Preferred_start_time.objects.filter(Q(player = opponent), Q(game = g))

		firstDateSinceNow = datetime.datetime.now()

		if firstDateSinceNow.hour < 22:
			firstDateSinceNow = datetime.datetime(now.year, now.month, now.day, now.hour + 2, 0, 0)
		else:
			firstDateSinceNow = firstDateSinceNow + datetime.timedelta(minutes=120)

		for selection in opponentSelection:
			# Extract all datetimes selected by opponent to show them
			myDateTimesSelected = Date_time.objects.filter(Q(preferred_start_time = selection)).order_by('date_time')			
			for dateSelected in myDateTimesSelected:
				s = {}
				s['gid'] = g.pk
				s['date'] = dateSelected
				
				if dateSelected.date_time >= firstDateSinceNow:			
					opponentSelectedGamesDate.append(s)


		#template = 'custom/select-time.html'
		template = get_template('custom/select-time.html')
	
		if request.mobile:
			#template = 'mobile/select-time.html'
			template = get_template('mobile/select-time.html')
			
		up = UserProfile.objects.get(user=request.user)
		timezone = up.timezone
		
 		return HttpResponse(template.render(RequestContext(request, {
				'timezone': timezone,
 				'myUncommittedGamesDate': myUncommittedGamesDate,
 				'mySelectedGamesDate': mySelectedGamesDate,
 				'opponentSelectedGamesDate': opponentSelectedGamesDate,
 				'player1': game.player1.username,
 				'player2': game.player2.username,
 				'date': now,
 				'user_me': request.user,
 			})))



	elif request.method == "POST":

		pst = Preferred_start_time.objects.get(player=request.user, game=game)
		gameDate = pst.game.start_time.date()

		for date in request.POST.getlist('hours'):
			pst = Preferred_start_time.objects.get(player=request.user, game=game)
			date = date.split("/")
			date = datetime.datetime(int(date[3]), int(date[2]), int(date[1]), int(date[0]), 0, 0)
			checkDate = Date_time.objects.filter(date_time = date, preferred_start_time = pst)

			if not checkDate:
				dateTime = Date_time(date_time = date, preferred_start_time = pst)
				dateTime.save()
				pst.committed = True
				pst.save()


			pst = Preferred_start_time.objects.filter(game = pst.game)

			if pst[0].committed and pst[1].committed:
				d_t1 = Date_time.objects.filter(preferred_start_time = pst[0])
				d_t2 = Date_time.objects.filter(preferred_start_time = pst[1])
				for d_t_player1 in d_t1:
					for d_t_player2 in d_t2:
						if d_t_player1.date_time == d_t_player2.date_time and not game.start_time_committed:
							game.start_time = d_t_player1.date_time
							game.start_time_committed = True
							game.save()
							notify_user(game.player1, 'time_commited', game)
							notify_user(game.player2, 'time_commited', game)
							return HttpResponseRedirect('/next-games')



		# Check if players saved the same hour to play
		for date in request.POST.getlist('hourselected'):

			checkDate = Date_time.objects.filter(date_time = date, preferred_start_time = pst)

			if not checkDate:
				dateTime = Date_time(date_time = date, preferred_start_time = pst)
				dateTime.save()
				pst.committed = True
				pst.save()


			pst = Preferred_start_time.objects.filter(game = pst.game)

			if pst[0].committed and pst[1].committed:
				d_t1 = Date_time.objects.filter(preferred_start_time = pst[0])
				d_t2 = Date_time.objects.filter(preferred_start_time = pst[1])
				for d_t_player1 in d_t1:
					for d_t_player2 in d_t2:
						if d_t_player1.date_time == d_t_player2.date_time and not game.start_time_committed:
							game.start_time = d_t_player1.date_time
							game.start_time_committed = True
							game.save()
							notify_user(game.player1, 'time_commited', game)
							notify_user(game.player2, 'time_commited', game)
							return HttpResponseRedirect('/next-games')


		return HttpResponseRedirect('/game-room/' + gid + "/select-time")
Exemple #5
0
def SelectStartTime(request, gid):

	if not request.user.is_authenticated():
		return HttpResponseRedirect('/mobile')


	game = Game.objects.get(id = gid)
	pst = Preferred_start_time.objects.get(game = game, player = request.user)

	if request.user != game.player1 and request.user != game.player2 and request.user.username == "FLEQBOT":
		return HttpResponseRedirect('/mobile')

	if game.is_over():
		return HttpResponseRedirect('/mobile')

	if game.start_time_committed:
		return HttpResponseRedirect('/mobile/game-room/' + gid)

	now = datetime.datetime.now()

	g = game

	# Save all dates of my uncommitted games to select date and time to play
	myUncommittedGamesDate = [] # Contains all options to select in my next games

	startDate = g.round.start_date
	finishDate = g.round.finish_date
	while startDate <= finishDate:
		# Check to show only valid dates
		if startDate >= datetime.datetime.now().date():
			d = {}
			d['gid'] = g.pk
			print startDate
			d['date'] = startDate
			d['dateslashed'] = str(startDate.day) + "/" + str(startDate.month) + "/" + str(startDate.year)

			myUncommittedGamesDate.append(d)

		startDate = startDate + timedelta(days = 1)



	if request.method == "GET":
		hour = now.hour

		# Extract all dates and times selected by user to show them
		mySelectedGamesDate = [] # Contains all options selected by user to each game
		opponentSelectedGamesDate = [] # Contains all options selected by opponent to each game

		# Select game preferences by user
		mySelection = Preferred_start_time.objects.filter(Q(player = request.user), Q(game = g))
		for selection in mySelection:
			# Extract all datetimes selected by user to show them
			myDateTimesSelected = Date_time.objects.filter(Q(preferred_start_time = selection)).order_by('date_time')			
			for dateSelected in myDateTimesSelected:
				s = {}
				s['gid'] = g.pk
				s['date'] = dateSelected
				mySelectedGamesDate.append(s)
				
		# Select game preferences by opponent
		if g.player1 == request.user:
			opponent = g.player2
		else:
			opponent = g.player1

		opponentSelection = Preferred_start_time.objects.filter(Q(player = opponent), Q(game = g))
		firstDateSinceNow = datetime.datetime(now.year, now.month, now.day, now.hour + 2, 0, 0)

		print firstDateSinceNow

		for selection in opponentSelection:
			# Extract all datetimes selected by opponent to show them
			myDateTimesSelected = Date_time.objects.filter(Q(preferred_start_time = selection)).order_by('date_time')			
			for dateSelected in myDateTimesSelected:
				s = {}
				s['gid'] = g.pk
				s['date'] = dateSelected
				
				if dateSelected.date_time >= firstDateSinceNow:			
					opponentSelectedGamesDate.append(s)


		return render_to_response('mobile/select-time.html', {
				'myUncommittedGamesDate': myUncommittedGamesDate,
				'mySelectedGamesDate': mySelectedGamesDate,
				'opponentSelectedGamesDate': opponentSelectedGamesDate,
				'player1': game.player1.username,
				'player2': game.player2.username,
				'date': now,
			})




	elif request.method == "POST":

		pst = Preferred_start_time.objects.get(player=request.user, game=game)
		gameDate = pst.game.start_time.date()

		for date in request.POST.getlist('hours'):
			date = date.split("/")
			date = datetime.datetime(int(date[3]), int(date[2]), int(date[1]), int(date[0]), 0, 0)
			checkDate = Date_time.objects.filter(date_time = date, preferred_start_time = pst)

			if not checkDate:
				dateTime = Date_time(date_time = date, preferred_start_time = pst)
				dateTime.save()
				pst.committed = True
				pst.save()


		# Check if players saved the same hour to play
		for date in request.POST.getlist('hourselected'):

			checkDate = Date_time.objects.filter(date_time = date, preferred_start_time = pst)

			if not checkDate:
				dateTime = Date_time(date_time = date, preferred_start_time = pst)
				dateTime.save()
				pst.committed = True
				pst.save()


			pst = Preferred_start_time.objects.filter(game = pst.game)

			if pst[0].committed and pst[1].committed:
				d_t1 = Date_time.objects.filter(preferred_start_time = pst[0])
				d_t2 = Date_time.objects.filter(preferred_start_time = pst[1])
				for d_t_player1 in d_t1:
					for d_t_player2 in d_t2:
						if d_t_player1.date_time == d_t_player2.date_time and not game.start_time_committed:
							game.start_time = d_t_player1.date_time
							game.start_time_committed = True
							game.save()
							notify_user(game.player1, 'time_commited', game)
							notify_user(game.player2, 'time_commited', game)
							return HttpResponseRedirect('/mobile/next-games')


		return HttpResponseRedirect('/mobile/game-room/' + gid + "/select-time")
Exemple #6
0
def newQuestionReview(request, gid):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/register')

	if request.user.has_perm('fleq.quizbowl.add_tournament'):
		admin_user = True
	else:
		admin_user = False

	# SIDEBAR INFO
	myTournaments = myActiveTournaments(request)
	myAdmnTournaments = myAdminTournaments(request)
	todayGames = myTodayGames(request)
	nextGames = myNextGames(request)
	pendingQR = myAdminPendingQuestionReviews(request.user)

	# Info about user
	user_me = UserProfile.objects.get(user=request.user)

	# Load strings language to template newquestionreview.html
	try:
		lang = strLang()
	except:
		lang = ''

	if request.method == 'POST': # If the form has been submitted...
		form = QuestionReviewForm(request.POST) # A form bound to the POST data
		if form.is_valid():
			try:
				question = Question.objects.get(pk = request.POST['question'])
				game = Game.objects.get(pk = gid)
			except:
				return HttpResponseRedirect('/games/' + str(gid) + '?status=error_question_no_exists')
			qr = Question_review(arguments = request.POST['arguments'],question = question, game = game, player = request.user)
			qr.save()
			notify_user(game.round.tournament.admin, 'new_review', qr)
			return HttpResponseRedirect('/games/' + str(gid) + '?status=success_added_question_review')
		else:
			return render_to_response('newquestionreview.html', {
				'user_me': user_me,
				'form': form,
				'lang': lang,
				'myTournaments': myTournaments,
				'myAdminTournaments': myAdmnTournaments,
				'todayGames': todayGames,
				'nextGames': nextGames,
				'admin_user': admin_user,
				'pendingQR': pendingQR,
			})
	else: # If get request, generate a new form
		# Only can do question reviews player1 and player2
		try:
			game = Game.objects.get(pk = gid)
		except:
			return HttpResponseRedirect('/games/' + str(gid) + '?status=error_question_no_exists')

		if user_me.user == game.player1 or user_me.user == game.player2:
	 		form = QuestionReviewForm()

			# Must we show a notification user?
			try:
		 		if request.GET['status']:
		 			box = setBox(request.GET['status'])
			except:
				box = ''
	 
			return render_to_response('newquestionreview.html', {
				'user_me': user_me,
				'form': form,
				'lang': lang,
				'box': box,
				'myTournaments': myTournaments,
				'myAdminTournaments': myAdmnTournaments,
				'todayGames': todayGames,
				'nextGames': nextGames,
				'game': game,
				'admin_user': admin_user,
				'pendingQR': pendingQR,
			})
		else:
			return HttpResponseRedirect('/my-tournaments')