Пример #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 get_user_profile():
	try:
		user_id = request.form['user_id']
		user = queries.get_user(user_id)
		return render_template('get_user_profile.json', user=user)
	except Exception, e:
		print e
		return render_template('error.json')
Пример #3
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')