Exemplo n.º 1
0
def send_posts():
    form = SendPosts()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            p = Posts(title=form.articletitle.data,
                      article=form.article.data,
                      user=current_user,
                      timestamp=datetime.utcnow() + timedelta(hours=8))
            print(p.timestamp)
            p.save()
            flash('发表成功')
            cache.clear()  #因为数据库更新,页面也需要更新,所以需要清除所有缓存
            return redirect(url_for('posts.send_posts'))
        else:
            print(1)
            flash('您还没登录')
            return redirect(url_for('user.login'))
    if not current_user.is_authenticated:
        print(2)
        flash('您还没登录 请登录后发表')
    c = Course.query.filter_by(pid=0)
    c1 = Course.query.filter(and_(Course.path.endswith(','), Course.pid != 0))
    c2 = Course.query.filter(
        and_(not_(Course.path.endswith(',')), Course.pid != 0))
    return render_template('posts/send_posts.html',
                           form=form,
                           course=c,
                           course1=c1,
                           course2=c2)
Exemplo n.º 2
0
def send_posts():
    form = SendPosts()
    ctgs = Categorys.query.all()
    # 判断登录后在进行发表
    if not current_user.is_authenticated:
        flash('您还没有登录  请登录后再发表')
    if current_user.id == 1:
        if form.validate_on_submit():
            # md格式
            article = request.form['article']
            ctgs = request.form['ctgs']
            tags = Categorys.query.filter_by(categorys=ctgs).first()
            # 图片上传
            img = request.files.get('img')  # 获取上传对象
            ex = os.path.splitext(img.filename)[1]
            filename = datetime.now().strftime('%Y%m%d%H%M%S') + ex
            file = img.stream.read()
            qiniu_store.save(file, filename)
            post = Posts(title=form.title.data,
                         user=current_user,
                         article=article,
                         img=qiniu_store.url(filename),
                         tags=[tags])
            post.save()
            flash('博客发表成功')
            return redirect(url_for('main.index'))
    else:
        flash('您没有发表博客的权限!')
        return redirect(url_for('main.index'))
    return render_template('posts/send_posts.html', form=form, ctgs=ctgs)
Exemplo n.º 3
0
def send_posts():
    form = SendPosts()
    if form.validate_on_submit():
        print(form.article.data)
        p = Posts(title=form.articletitle.data,
                  article=form.article.data,
                  user=current_user)
        p.save()
    return render_template('posts/send_posts.html', form=form)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def send_posts():
    form = SendPosts()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            p = Posts(title=form.articletitle.data,
                      article=form.article.data,
                      user=current_user)
            p.save()
            flash('发表成功')
            return redirect(url_for('posts.send_posts'))
        else:
            flash('您还没有登录,请先登录再发表')
    if not current_user.is_authenticated:
        flash('您还没有登录,请登录后再发表')
    return render_template('posts/send_posts.html', form=form)
Exemplo n.º 6
0
def cposts(request,id):
    if request.method == 'POST':
        p = Posts.objects.filter(id=id)[0]
        u = User.objects.filter(username=request.session.get('user'))[0]
        cpost = Posts()
        cpost.puser = u
        cpost.pcontent = request.POST.get('content')
        cpost.rid = p.id
        cpost.save()
        return HttpResponseRedirect(reverse('blog:detail',args=[p.id]))
Exemplo n.º 7
0
def discuss(posts):
    c = Course.query.filter_by(pid=0)
    c1 = Course.query.filter(and_(Course.path.endswith(','), Course.pid != 0))
    c2 = Course.query.filter(
        and_(not_(Course.path.endswith(',')), Course.pid != 0))
    ##########################################################################
    form = SendDiscuss()
    id = posts.split(' ')[1].split('>')[0]
    parent = Posts.query.filter_by(id=id).first()
    title = '回复' + parent.user.username + ':'
    grandparent = Posts.query.filter_by(id=parent.pid).first()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            p = Posts(pid=id,
                      path=parent.path + id + ',',
                      title=title,
                      article=form.article.data,
                      user=current_user,
                      timestamp=datetime.utcnow() + timedelta(hours=8))
            p.save()
            flash('发表成功')
            cache.clear()  #因为数据库更新,页面也需要更新,所以需要清除所有缓存
            if grandparent:
                return redirect(
                    url_for('details.get_details', posts=grandparent, page=1))
            else:
                return redirect(
                    url_for('details.get_details', posts=parent, page=1))

        else:
            flash('您还没登录')
            return redirect(url_for('user.login'))
    if not current_user.is_authenticated:
        flash('您还没登录 请登录后发表')
    return render_template('posts/discuss.html',
                           form=form,
                           course=c,
                           course1=c1,
                           course2=c2)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
def sendposts(request):
    if request.method == 'POST':
        username = request.session.get('user')
        u = User.objects.filter(username=username)[0]
        post = Posts()
        post.ptitle = request.POST.get('title')
        post.pcontent = request.POST.get('content')
        post.puser = u
        post.save()
        return HttpResponseRedirect(reverse('blog:index',args=[1]))
    return render(request,'sendposts.html',context={'title':'登录'})
Exemplo n.º 10
0
def send_posts():
    form = SendPosts()
    # 判断登录后在进行发表
    if not current_user.is_authenticated:
        flash('您还没有登录  请登录后在发表')
    elif form.validate_on_submit():
        # 保存发表博客的数据
        Posts(title=form.title.data,
              article=form.article.data,
              user=current_user).save()
        flash('博客发表成功')
        return redirect(url_for('main.index'))
    return render_template('posts/send_posts.html', form=form)
Exemplo n.º 11
0
def comment():
    pid = request.form.get('pid')
    rid = request.form.get('rid')
    # 判断当前是评论还是回复 如果为评论则为假 否则为真
    if rid:
        id = rid
    else:
        id = pid
    p = Posts.query.get(int(id))
    Posts(article=request.form.get('article'),
          pid=id,
          path=p.path + id + ',',
          user=current_user).save()
    return redirect(url_for('posts.posts_detail', pid=pid))
Exemplo n.º 12
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)