示例#1
0
def edit_description(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author and not current_user.can('MODERATE'):
        abort(403)
    form = DescriptionForm()
    if form.validate_on_submit():
        photo.description = form.description.data
        db.session.commit()
        flash('已更新图片描述', 'success')
    flash_errors(form)  #flash表单的错误
    return redirect(url_for('.show_photo', photo_id=photo_id))
示例#2
0
def edit_description(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author:
        abort(403)

    form = DescriptionForm()
    if form.validate_on_submit():
        photo.description = form.description.data
        db.session.commit()
        flash('Description updated', 'success')

    return redirect(url_for('main.show_photo', photo_id=photo_id))
示例#3
0
def edit_description(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author and not current_user.can("MODERATE"):
        abort(403)

    form = DescriptionForm()
    if form.validate_on_submit():
        photo.description = form.description.data
        db.session.commit()
        flash("Description updated.", "success")

    flash_errors(form)
    return redirect(url_for("main.show_photo", photo_id=photo.id))
示例#4
0
def show_photo(photo_id):
	"""
	显示图片详细信息
	:param photo_id: 图片id
	"""
	logger.info('url = ' + str(request.url))
	photo = Photo.query.get_or_404(photo_id)
	page = request.args.get("page", 1, type=int)
	per_page = current_app.config["ALBUMY_COMMENT_PER_PAGE"]
	# 获取该图片下的所有评论
	pagination = (
		Comment.query.with_parent(photo)
			.order_by(Comment.timestamp.asc())
			.paginate(page, per_page)
	)
	comments = pagination.items

	comment_form = CommentForm()
	# 描述
	description_form = DescriptionForm()
	# 标签
	tag_form = TagForm()

	description_form.description.data = photo.description
	return render_template(
		"main/photo.html",
		photo=photo,
		comment_form=comment_form,
		description_form=description_form,
		tag_form=tag_form,
		pagination=pagination,
		comments=comments,
	)
示例#5
0
文件: main.py 项目: dr2us-com/Dr2us
def show_photo(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ALBUMY_COMMENT_PER_PAGE']
    pagination = Comment.query.with_parent(photo).order_by(Comment.timestamp.asc()).paginate(page, per_page)
    comments = pagination.items
    comment_form = CommentForm()
    description_form = DescriptionForm()
    tag_form = TagForm()

    description_form.description.data = photo.description
    if current_user.role.name != 'Doctor':
        doctors_leave_comment = []
        doctor_ids_leave_comment = []
        for comment in photo.comments:
            print(comment.author)
            if not comment.author in doctors_leave_comment:
                if comment.author.role.name == 'Doctor':
                    doctors_leave_comment.append(comment.author)
                    doctor_ids_leave_comment.append(comment.author.id)
        doctors_not_leave_comment = User.query.join(Role).filter(Role.name == 'Doctor').filter(
            ~User.id.in_(doctor_ids_leave_comment)).all()

        return render_template('main/photo.html', photo=photo, comment_form=comment_form,
                               description_form=description_form, tag_form=tag_form,
                               pagination=pagination, comments=comments, doctors_leave_comment=doctors_leave_comment,
                               doctors_not_leave_comment=doctors_not_leave_comment)
    else:
        invite = photo.invites.filter(Invite.user_id == current_user.id, Invite.status == False).first()
        return render_template('main/photo.html', photo=photo, comment_form=comment_form,
                               description_form=description_form, tag_form=tag_form,
                               pagination=pagination, comments=comments, invite=invite)
示例#6
0
def edit_description(photo_id):
	"""
	编辑图片描述
	:param photo_id: 图片id
	"""
	logger.info('url = ' + str(request.url))
	photo = Photo.query.get_or_404(photo_id)
	if current_user != photo.author and not current_user.can("MODERATE"):
		abort(403)

	form = DescriptionForm()
	if form.validate_on_submit():
		photo.description = form.description.data
		logger.info('修改了图片id={}的描述={}'.format(photo_id, photo.description))
		db.session.commit()
		flash("描述更新成功!", "success")

	flash_errors(form)
	return redirect(url_for(".show_photo", photo_id=photo_id))
示例#7
0
def show_photo(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ALBUMY_COMMENT_PER_PAGE']
    pagination = Comment.query.with_parent(photo).order_by(Comment.timestamp.asc()).paginate(page, per_page)
    comments = pagination.items

    comment_form = CommentForm()
    description_form = DescriptionForm()
    tag_form = TagForm()

    description_form.description.data = photo.description
    return render_template('main/photo.html', photo=photo, comment_form=comment_form, description_form=description_form,
                           tag_form=tag_form, pagination=pagination, comments=comments)
示例#8
0
def show_photo(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    description_form = DescriptionForm()
    description_form.description.data = photo.description
    return render_template('main/photo.html', photo=photo, description_form=description_form)