def modify_event(event, start_datetime, end_datetime, image=None): event.start_datetime = start_datetime event.end_datetime = end_datetime if image is not None: event.image = 'event_' + str(event.id) + '_' + str(get_timestamp()) + '.png' god_db.session.commit() return event
def add_event(start_datetime, end_datetime, image): event = Event() event.start_datetime = start_datetime event.end_datetime = end_datetime god_db.session.add(event) god_db.session.commit() event.image = 'event_' + str(event.id) + '_' + str(get_timestamp()) + '.png' god_db.session.commit() return event
def add_teacher(name, birthday, phone, photo=None, company="", \ certification="", video_available=True, price=0, profile="", url=""): teacher = Teacher() teacher.name = urllib.quote(name.encode('utf8')) teacher.birthday = urllib.quote(birthday.encode('utf8')) teacher.phone = urllib.quote(phone.encode('utf8')) teacher.photo = None teacher.pushtoken = None teacher.company = urllib.quote(company.encode('utf8')) teacher.certification = urllib.quote(certification.encode('utf8')) teacher.video_available = video_available teacher.price = price teacher.profile = urllib.quote(profile.encode('utf8')) teacher.url = urllib.quote(url.encode('utf8')) teacher.push_active = True god_db.session.add(teacher) god_db.session.commit() if photo is not None: teacher.photo = 'teacher_' + str(teacher.id) + '_' + str(get_timestamp()) + '.png' god_db.session.commit() return teacher
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'))