Example #1
0
def index(groupKey=None):
	if groupKey=='favicon.ico': abort(404)

	#세션리셋
	session.clear()

	#ip = socket.gethostbyname(socket.gethostname())
	ip = request.remote_addr

	#https://pypi.python.org/pypi/user-agents/ #pip install user-agents
	from user_agents import parse
	user_agent = parse(request.user_agent.string)
	if user_agent.is_mobile==True : platform = "mobile"
	else : platform = "web"

	accessLog = AccessLog(ip, platform)
	db_session.add(accessLog)
	try:
		db_session.commit()
	except exc.IntegrityError as e:
		db_session.rollback()

	debug = request.args.get('debug', '')
	email = request.args.get('email', '')
	
	resp = make_response( render_template('index.html', groupKey=groupKey) )
	if email!='': 
		resp.set_cookie('email', email)
	if debug!='': 
		resp.set_cookie('debug', debug)
	if groupKey!=None:
		resp.set_cookie('groupKey', groupKey)

	return resp
Example #2
0
def finishPage():
	if request.method == 'POST':
		app.logger.debug(request.form)#

		userId = session['userId']

		'''DB저장 - ImmutableMultiDict => dict'''
		#answerDict = dict(request.form)
		#del answerDict["sum1"]
		answerDict = { key: request.form[key] for key in request.form if not key.startswith('sum') }
		answer = Answer(userId, **answerDict)
		db_session.add(answer)
		try:
			db_session.commit()
		except exc.IntegrityError as e:
			db_session.rollback()
			abort(500)

		resultDict = { key: request.form[key] for key in request.form if key.startswith('sum') }
		resultDict.update( { key: session.get(key) for key in ["userId","jobClass","gender","age","jobType","workYear","workMonth","jobTitle","groupKey"] } )
		resultDict.update({"answerId":answer.id})
		result = Result(**resultDict)
		db_session.add(result)
		try:
			db_session.commit()
		except exc.IntegrityError as e:
			db_session.rollback()
			abort(500)

		try:
			return render_template('finish.html')
		except TemplateNotFound:
			abort(404)
	else:
		abort(403)
		return None
Example #3
0
def surveyPage():
	if request.method == 'POST':
		
		app.logger.debug(request.form)#
		
		#ip = socket.gethostbyname(socket.gethostname())
		ip = request.remote_addr
		birth = datetime.date( int0(request.form['birthYear']), int0(request.form['birthMonth']), 1 )

		#DB저장/세션저장
		user = User(request.form['email'], request.form['jobClass'], request.form['gender'],\
				birth, request.form['jobType'], int0(request.form['workYear']),\
				int0(request.form['workMonth']), int0(request.form['jobTitle']), ip, request.form.get('groupKey'))
		db_session.add(user)
		try:
			db_session.commit()
		except exc.IntegrityError as e:
			db_session.rollback()
			abort(500)

		session['userId'] = user.id
		session['jobClass'] = user.jobClass
		session['gender'] = user.gender
		session['age'] = datetime.date.today().year - user.birth.year
		session['jobType'] = user.jobType
		session['workYear'] = user.workYear
		session['workMonth'] = user.workMonth
		session['jobTitle'] = user.jobTitle
		session['groupKey'] = user.groupKey

		##문항 셔플
		# tmpA = ["a1","a2","a3","a4","a5","a6","a7","a8"]
		# shuffle(tmpA)
		# tmpB = ["b1","b2","b3","b4","b5","b6","b7","b8"]
		# shuffle(tmpB)
		# tmpC = ["c1","c2","c3","c4","c5","c6","c7","c8"]
		# shuffle(tmpC)
		# tmpD = ["d1","d2","d3","d4","d5","d6","d7","d8"]
		# shuffle(tmpD)
		# tmpE = ["e1","e2","e3","e4","e5","e6","e7","e8"]
		# shuffle(tmpE)
		# tmpF = ["f1"]
		# data = [tmpA, tmpB, tmpC, tmpD, tmpE, tmpF]

		##문항 셔플 - 첫문항 고정형
		# tmpHead = ["a1","b1","c1","d1","e1"]
		# tmpBody = ["a2","a3","a4","a5","a6","a7","a8","b2","b3","b4","b5","b6","b7","b8","c2","c3","c4","c5","c6","c7","c8","d2","d3","d4","d5","d6","d7","d8","e2","e3","e4","e5","e6","e7","e8"]
		# shuffle(tmpBody)
		# data = list()
		# for i in range(5):
		# 	data.append(list())
		# 	data[i].append(tmpHead[i])
		# 	for j in range(7):
		# 		data[i].append(tmpBody[j+i*7])
		# 	if i==4 :
		# 		data[i].append("f1")
		
		#문항 고정
		data = [["c2","d1","a1","e1","b1","c1","d2","a2"],["e2","b2","c3","d3","a3","e3","b3","c4"],["d4","a4","e4","b4","c5","d5","a5","e5"],["b5","c6","d6","a6","e6","b6","c7","d7"],["a7","e7","b7","c8","d8","a8","e8","b8","f1"]]

		debug = request.cookies.get('debug')

		try:
			return render_template('survey.html', data=data, debug=debug)
		except TemplateNotFound:
			abort(404)
	else:
		abort(403)
		return None