Exemplo n.º 1
0
def list():
	lessons = queries.get_all_lessons()
	real_lessons = []
	for lesson in lessons:
#		try:
#		except:
#			pass
		real_lessons.append([lesson, teacher_queries.get_teacher(lesson.teacher_id)])
		
	return render_template('order.html', lessons=real_lessons)
Exemplo n.º 2
0
def modify(teacher_id):
	try:
		teacher = queries.get_teacher(teacher_id)
		if teacher.active == False:
			raise

		if request.method == 'GET':
			name = urldecode(teacher.name)
			birthday = urldecode(teacher.birthday)
			phone = urldecode(teacher.phone)
			company = urldecode(teacher.company)
			certification = urldecode(teacher.certification)
			price = teacher.price
			photo = teacher.photo
			profile = urldecode(teacher.profile)
			url = urldecode(teacher.url)
			errors = []
		else:
			name = request.form['name'].strip()
			birthday = request.form['birthday'].strip()
			phone = request.form['phone'].strip()
			company = request.form['company'].strip()
			certification = request.form['certification'].strip()
			price = request.form['price'].strip()
			profile = request.form['profile'].strip()
			url = request.form['url'].strip()
			
			if 'photo' in request.files and request.files['photo']:
				photo = request.files['photo']
				photo_name = 'teacher_' + str(teacher_id) + '_' + str(get_timestamp()) + '.png'
				photo_path = os.path.join(current_app.config['PROFILE_FOLDER'], photo_name)
				photo.save(photo_path)
				photo = photo_name
			else:
				photo = None

			errors = []

			if name == u'' or name == '':
				errors.append('이름이 빈칸입니다.')
			if birthday == u'' or birthday == '':
				errors.append('생일이 빈칸입니다.')
			if phone == u'' or phone == '':
				errors.append('전화번호가 빈칸입니다.')
			if company == u'' or company == '':
				errors.append('회사이름이 빈칸입니다.')
			if certification == u'' or certification == '':
				errors.append('자격증이 빈칸입니다.')

			try:
				price = int(price)
				if price % 100 != 0:
					errors.append('금액은 100의 배수여야 합니다.')
			except: 
				errors.append('금액은 정수여야합니다.')


			if len(errors) == 0: 
				queries.modify_teacher(teacher, name, birthday, phone, photo, company, \
					certification, True, price, profile, url)
				return redirect(url_for('teacher.list'))

		return render_template('teacher_modify.html', name=name,
			birthday=birthday, phone=phone, company=company,
			certification=certification, price=price, profile=profile, 
			url=url, photo=photo, errors=errors, teacher_id=teacher_id, 
			status=teacher.status)
	except Exception, e:
		print e
		return redirect(url_for('teacher.list'))