コード例 #1
0
def send_posts():
    form = Posts()
    if not current_user.is_authenticated:
        flash('您还没有登录 请先登录在发表')
    elif form.validate_on_submit():
        p = MPosts(title=form.title.data,
                   content=form.content.data,
                   user=current_user)
        p.save()
        flash('发表成功!去首页进行查看')
        return redirect(url_for('posts.send_posts'))
    return render_template('posts/send_posts.html', form=form)
コード例 #2
0
ファイル: posts.py プロジェクト: riverstation/project-all
def send_posts():
    form = FormPosts()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            u = current_user._get_current_object()  #拿到真正的当前用户对象 u
            p = Posts(content=form.content.data, user=u)
            db.session.add(p)
            flash('发表成功!! 请前往首页查看')
            return redirect(url_for('posts.send_posts'))
        else:
            flash('您还没有登录 请前去登录')
            return redirect(url_for('user.login'))
    return render_template('posts/send_posts.html', form=form)
コード例 #3
0
def edit_blog(pid):
    form = Posts()
    posts = MPosts.query.get(pid)
    if form.validate_on_submit():
        posts.title = request.form.get('title')
        posts.content = request.form.get('content')
        posts.timestamp = datetime.utcnow()
        posts.save()
        flash('博客更新成功')
        cache.clear()
        return redirect(url_for('center.blog_manage'))
    # 给表单添加默认值
    form.title.data = posts.title
    form.content.data = posts.content
    return render_template('owncenter/edit_blog.html',form=form,posts=posts,pid=pid)
コード例 #4
0
def send_posts():
    form = PostsForm()

    if form.validate_on_submit():
        if current_user.is_authenticated:
            shuffix = os.path.splitext(form.file.data.filename)[-1]
            #生成随机的图片名
            while True:
                newName = new_name(shuffix)
                if not os.path.exists(
                        os.path.join(
                            current_app.config['UPLOADED_PHOTOS_DEST'],
                            newName)):
                    break
            file.save(form.file.data, name=newName)
            #判断用户更改头像 原头像是否为默认 不是则将原图片删除

            #执行缩放
            img = Image.open(
                os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'],
                             newName))
            img.thumbnail((300, 300))
            #保存新的图片名称为新的图片的s_newname
            img.save(
                os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'],
                             's_' + newName))

            #拿到真正实例化的user对象
            u = current_user._get_current_object()
            file.save(form.file.data, name=newName)
            p = Posts(selfread=form.selfread.data,
                      content=form.content.data,
                      image=newName,
                      user=u,
                      title=form.title.data,
                      director=form.director.data,
                      characters=form.characters.data)
            db.session.add(p)
            flash('电影发表成功!!!')
            return redirect(url_for('main.index'))
        else:
            flash('您还没有登录 请前去登录在发表')
            return redirect(url_for('user.login'))
    return render_template('posts/send_posts.html', form=form)
コード例 #5
0
def posts_detail(pid):
    form = Posts()  #作为评论和回复的表单类样式
    data = MPosts.query.get(pid)
    comment = MPosts.query.filter(MPosts.path.contains(str(pid))).order_by(
        MPosts.path.concat(MPosts.id))
    #select * from posts where path like '%pid%' order by concat(path,id)
    return render_template('posts/posts_detail.html',
                           data=data,
                           comment=comment,
                           form=form)
コード例 #6
0
def posts_detail(pid):
    form = Posts()
    data = MPosts.query.get(pid)
    comment = MPosts.query.filter(MPosts.path.contains(str(pid))).order_by(
        MPosts.path.concat(MPosts.id))
    # 访问量
    data.visit = data.visit + 1
    data.save()
    cache.clear()
    return render_template('posts/posts_detail.html',
                           data=data,
                           form=form,
                           comment=comment)