Beispiel #1
0
def final_page_c(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__FINAL_PAGE)):
	id_utente = request.session[project_util.SESSION_KEY__ID_UTENTE]
	# leggo dal db
	connection_database = apri_connessione_db()
	choices = connection_database.select_choices_menu(id_utente)
	connection_database.close_conn()
	# elaboro le scelte
	images_payoff = []
	for choice in choices:
		tipo_test = choice['tipo_test']
		# choice e' la riga della tabella, per selezionare una colonna usare le parentesi quadre come un array
		num_choice = choice['choice']
		menu = choice['menu']
		if menu is not None:
			menu = json.loads(menu)
			image_chosen = menu[num_choice]
			image_chosen = os.path.join(project_util.from_tipo_test_to_cartella_immagini(tipo_test), image_chosen)
			images_payoff.append(image_chosen)
	# scelgo un'immagine a caso
	images_payoff1 = images_payoff[0:10]
	images_payoff2 = images_payoff[11:21]
	image_payoff3 = images_payoff[22]
	image_payoff1 = random.choice(images_payoff1)
	image_payoff2 = random.choice(images_payoff2)
	
	model_map = util.init_modelmap(request, None)
	model_map['page_title'] = 'Fine'
	model_map['image_payoff1'] = image_payoff1
	model_map['image_payoff2'] = image_payoff2
	model_map['image_payoff3'] = image_payoff3
	
	return TemplateResponse(request, template_name, model_map)
Beispiel #2
0
def logic_test(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__LOGIC_TEST)):
	last_page = 0
	id_utente = request.session[project_util.SESSION_KEY__ID_UTENTE]
	
	num_page = int(request.GET.get('num_page', '1'))
	
	# I go and take different images for each num_page in the language test
	immagini = util.LOGIC_IMAGES[num_page - 1]
	
	if num_page < last_page:
		num_page = last_page
		response = redirect('{}?num_page={}'.format(reverse('logic_test'), num_page))
		return response
	last_page = num_page
	
	model_map = util.init_modelmap(request, None)
	model_map['num_page'] = num_page
	model_map['immagini'] = immagini
	model_map['page_title'] = "Scegli il pezzo mancante"
	
	connection_database = apri_connessione_db()
	connection_database.insert_logic_test(id_utente, num_page, None)
	
	connection_database.conn_db.commit()
	connection_database.close_conn()
	
	return TemplateResponse(request, template_name, model_map)
Beispiel #3
0
def video(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__VIDEO)):
	num_page = int(request.GET.get('num_page', '0'))
	next_page = num_page + 1
	
	next_url_page = '{}?num_page={}'.format(reverse('choice_image'), next_page)
	model_map = util.init_modelmap(request, None)
	model_map['video'] = project_util.URL_VIDEO + '/' + util.VIDEOS[num_page]
	model_map['next_url_page'] = next_url_page
	return TemplateResponse(request, template_name, model_map)
Beispiel #4
0
def choice_image(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__CHOICE)):
	num_page = int(request.GET.get('num_page', '1'))
	images_powerset = request.session[project_util.SESSION_KEY__POWERSET]
	images_powerset2 = request.session[project_util.SESSION_KEY__POWERSET2]
	
	images_choice3 = request.session[project_util.SESSION_KEY__IMAGES_CHOICE3]
	
	model_map = util.init_modelmap(request, None)
	model_map['num_page'] = num_page
	
	cartella_img = None
	tipo_test = None
	images = None
	
	id_utente = request.session[project_util.SESSION_KEY__ID_UTENTE]
	
	if num_page < len(images_powerset) + 1:
		tipo_test = 0
		if (id_utente % 2) == 0:
			images = images_powerset[num_page - 1]
			cartella_img = 'images_choice'
			model_map['page_title'] = 'Quale matita ti piace tra queste?'
		else:
			images = images_powerset2[num_page - 1]
			model_map['page_title'] = 'Quale penna ti piace tra queste?'
			cartella_img = 'images_bibite'
	elif (num_page >= len(images_powerset) + 1) and (num_page < 2 * len(images_powerset) + 1):
		tipo_test = 1
		if (id_utente % 2) == 0:
			images = images_powerset2[num_page - 1 - 11]
			cartella_img = 'images_bibite'
			model_map['page_title'] = 'Quale penna ti piace tra queste?'
		else:
			images = images_powerset[num_page - 1 - 11]
			model_map['page_title'] = 'Quale matita ti piace tra queste?'
			cartella_img = 'images_choice'
	elif num_page == 2 * len(images_powerset) + 1:
		images = images_choice3
		model_map['page_title'] = 'Quale astuccio ti piace tra questi?'
		cartella_img = 'images_snack'
		tipo_test = 2
	
	model_map['images'] = images
	model_map['cartella_img'] = cartella_img
	model_map['tipo_test'] = tipo_test
	
	# inserisco una riga vuota per calcolo response time
	connection_database = apri_connessione_db()
	connection_database.insert_choices_menu(id_utente, tipo_test, None, None)
	
	connection_database.conn_db.commit()
	connection_database.close_conn()
	
	return TemplateResponse(request, template_name, model_map)
Beispiel #5
0
def index(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__INDEX)):
	images_powerset = modulo_functions.powerset(util.IMAGES_CHOICE, True)
	images_powerset = modulo_functions.shuffle_powerset(images_powerset)
	images_powerset2 = modulo_functions.powerset(util.IMAGES_CHOICE2, True)
	images_powerset2 = modulo_functions.shuffle_powerset(images_powerset2)
	
	images_choice3 = util.IMAGES_CHOICE3
	random.shuffle(images_choice3)
	
	request.session[project_util.SESSION_KEY__POWERSET] = images_powerset
	request.session[project_util.SESSION_KEY__POWERSET2] = images_powerset2
	
	request.session[project_util.SESSION_KEY__IMAGES_CHOICE3] = images_choice3
	
	model_map = util.init_modelmap(request, None)
	return TemplateResponse(request, template_name, model_map)
Beispiel #6
0
def slider2(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__SLIDER2)):
	id_utente = request.session[project_util.SESSION_KEY__ID_UTENTE]
	if (id_utente % 2) == 0:
		slider_images = util.IMAGES_CHOICE2
		cartella_img = 'images_bibite'
	else:
		slider_images = util.IMAGES_CHOICE
		cartella_img = 'images_choice'
		
	emoji_images = util.EMOJI
	
	model_map = util.init_modelmap(request, None)
	model_map['cartella_img'] = cartella_img
	model_map['images'] = slider_images
	model_map['emoji'] = emoji_images
	
	connection_database = apri_connessione_db()
	connection_database.insert_choices_slider2(id_utente, None)
	
	connection_database.conn_db.commit()
	connection_database.close_conn()
	
	return TemplateResponse(request, template_name, model_map)
Beispiel #7
0
def questionnaire_kids(request, template_name=os.path.join(CARTELLA_CORRENTE, util.TEMPLATE_NAME__QUESTIONARIO_KIDS)):
	model_map = util.init_modelmap(request, None)
	return TemplateResponse(request, template_name, model_map)