Created
January 16, 2018 09:56
-
-
Save maxtortime/30599da2708882a734292d87bf23a7b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@space.route('/write', methods=['GET', 'POST']) | |
@login_required | |
@roles_required('member') | |
def write(): | |
form = BoardWriteForm() | |
if not current_user.has_role('admin'): | |
form.type_.choices = form.type_.choices[1:] | |
if form.validate_on_submit(): | |
post = Board(form.title.data, form.content.data, form.type_.data, | |
current_user.id) | |
db.session.add(post) | |
db.session.commit() | |
for file_ in form.files.raw_data: | |
if file_.filename: | |
user_file = UserFile(board_id=post.id, publication_id=None, | |
original_file_name=secure_filename( | |
file_.filename)) | |
db.session.add(user_file) | |
db.session.commit() | |
file_.save(os.path.join(app.config['UPLOADS_DEFAULT_DEST'], | |
user_file.hashed_file_name)) | |
return redirect(url_for('space.index')) | |
return render_template('space/write.html', form=form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BoardWriteForm 코드는 어떻게 되나요?