예제 #1
0
def profile():
	try:
		profile = request.files['profile']
		photo_path = ''
		if 'user_id' in request.form:
			user_id = request.form['user_id']
			user = queries.get_user(user_id)
			photo_path = func.get_user_photo_path(user_id)

			profile_path = os.path.join(current_app.config['PROFILE_FOLDER'], photo_path)
			profile.save(profile_path)
			queries.update_user_photo(user_id, photo_path)
		elif 'teacher_id' in request.form:
			teacher_id = request.form['teacher_id']
			teacher = queries.get_teacher(teacher_id)
			photo_path = func.get_teacher_photo_path(teacher_id)

			profile_path = os.path.join(current_app.config['PROFILE_FOLDER'], photo_path)
			profile.save(profile_path)
			queries.update_teacher_photo(teacher_id, photo_path)
		else:
			raise
		return render_template('profile.json', photo_path=photo_path)
	except Exception, e:
		print e
		return render_template('error.json')
예제 #2
0
def revenue():
	teacher_id = int(request.args.get('teacher_id', 0))
	teacher = auth_queries.get_teacher(teacher_id)
	return render_template('lesson_revenue.json', teacher=teacher)
예제 #3
0
def answer():
	try:
		lesson_id = int(request.form['lesson_id'])
		teacher_id = int(request.form['teacher_id'])
		image_count = int(request.form['image_count'])
		score1 = int(request.form['score0'])
		score2 = int(request.form['score1'])
		score3 = int(request.form['score2'])
		score4 = int(request.form['score3'])
		score5 = int(request.form['score4'])
		score6 = int(request.form['score5'])
		score7 = int(request.form['score6'])
		score8 = int(request.form['score7'])
		cause = int(request.form['cause'])
		# recommend1 = int(request.form['recommend1'])
		# recommend2 = int(request.form['recommend2'])
		recommend1 = 0
		recommend2 = 0

		lesson_question = queries.get_lesson_question(lesson_id)

		# DB에 남아있는거 잘 업데이트하기 
		if lesson_question.teacher_id != None and lesson_question.teacher_id != teacher_id:
			return render_template('error.json')
		lesson_question.status = False
		if lesson_question.status:
			return render_template('error.json')

		teacher = auth_queries.get_teacher(teacher_id)

		# TODO: this rountines muste be in queries.py
		lesson_question.teacher_id = teacher_id
		lesson_question.status = True
		teacher.revenue += lesson_question.price
		# END TODO

		lesson_answer = Lesson_Answer(lesson_id, score1, score2, score3,
			score4, score5, score6, score7, score8, '', cause, recommend1, recommend2)
		queries.add_lesson_answer(lesson_answer)

		file = request.files['audio']
		file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], 
			lesson_answer.sound)
		file.save(file_path)

		for i in xrange(image_count):
			file = request.files['image' + str(i)]
			file_name = str(lesson_answer.id) + '_image_' + str(i) + '.png'
			file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], file_name)
			file.save(file_path)

			line = request.form['line' + str(i)]
			timing = request.form['timing' + str(i)]

			lesson_answer_image = Lesson_Answer_Image(i, 
					lesson_answer.id, file_name, line, timing)
			queries.add_lesson_answer_image(lesson_answer_image)

		# 회원에게 레슨 처리됨을 푸시로 알리기
		gcm = GCM(current_app.config['GCM_APIKEY'])
		try:
			user_id = queries.get_lesson_user_id(lesson_id)
			reg_id = auth_queries.get_reg_id(user_id)
			if reg_id is not None and reg_id != '':
				gcm.plaintext_request(registration_id=reg_id, 
					data={'title':'싱글로', 'message':'신청한 레슨 강습이 완료되었습니다.'})
		except:
			pass

		return render_template('success.json')
	except Exception, e:
		print e
		return render_template('error.json')
예제 #4
0
def ask_slow_solo():
	gcm = GCM(current_app.config['GCM_APIKEY'])
	msg = ''
	try:
		user_id = int(request.form['user_id'])
		teacher_id = int(request.form['teacher_id'])
		lesson_type = False
		video = None
		club_type = int(request.form['club_type'])
		question = request.form['question']

		if 'lesson_id' in request.form:
			before_lesson = queries.get_lesson_question(request.form['lesson_id'])
			video = before_lesson.video
		elif 'video' not in request.files or not request.files['video']:
			raise

		user = auth_queries.get_user(user_id)
		teacher = auth_queries.get_teacher(teacher_id)
		if user.point < teacher.price / 100:
			msg = '골프공이 부족합니다'
			raise

		user.point -= teacher.price / 100
			
		lesson_question = Lesson_Question(
			user_id, teacher_id, False, lesson_type, 
			video, club_type, question, teacher.price / 100)

		if video is None:
			lesson_question = queries.add_lesson_question_video(lesson_question)
			thumbnail = lesson_question.thumbnail
			#TODO: 파일 처리 완료 후 DB에 들어가게 설정

			# Video Processing
			temp_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], 
				'temp_' + lesson_question.video)
			file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], lesson_question.video)
			file = request.files['video']
			file.save(temp_file_path)

			try:
				os.system('/usr/local/bin/MP4Box -hint %s' % temp_file_path)
				rotation = get_video_rotation(temp_file_path)

				option = 'setpts=4.0*PTS,scale=iw/2:-1'
				os.system("/usr/local/bin/ffmpeg -i %s -vpre singlo -filter:v '%s' -an -f mp4 %s" % (temp_file_path, option, file_path))
			except:
				pass

			try:
				with open(file_path): pass
			except:
				os.system("mv %s %s" % (temp_file_path, file_path))

			get_video_capture(file_path, 0, thumbnail)
		else:
			lesson_question.thumbnail = before_lesson.thumbnail
			lesson_question = queries.add_lesson_question(lesson_question)

		reg_id = teacher_queries.get_teacher_reg_id(teacher_id)
		if reg_id is not None:
			gcm.plaintext_request(registration_id=reg_id, 
				data={'message':'새로운 레슨 신청이 들어왔습니다.'})

		return render_template('ask.json', lesson=lesson_question, userPoint=user.point)
	except Exception, e:
		print e
		return render_template('error.json')