Example #1
0
def change(post_id):
    form = ChangeForm()
    post = Post.query.filter_by(id=post_id).first_or_404()
    if post.author.username != current_user.username:
        abort(404)
    if form.validate_on_submit():
        t = Thread(target=del_image, args=(post, form, current_user.id))
        t.start()
        temp_store = 0
        if request.form.get('temp'):
            temp_store = 1
        origin_id = str(post.cat_id)
        post.title = form.title.data
        post.content = form.content.data
        post.cat_id = form.cat.data
        post.last_modify = datetime.utcnow()
        post.temp_store = temp_store
        db.session.add(post)
        db.session.commit()
        Use_Redis.eval('article', post_id, '*', disable=flag)
        Use_Redis.eval('index', '*', disable=flag)
        Use_Redis.eval('cat', '0', '*', disable=flag)
        Use_Redis.eval('cat', origin_id, '*', disable=flag)
        Use_Redis.eval('cat', str(form.cat.data), '*', disable=flag)
        flash('你的修改已经保存.')
        return redirect(url_for('user', username=current_user.username)), 301
    else:
        flash('修改异常!')
        app.logger.error(form.errors)
    return redirect(url_for('editpost', form=form, post_id=post.id)), 301
Example #2
0
def change(post_id):
    form = ChangeForm()
    post = Post.query.filter_by(id=post_id).first()
    if form.validate_on_submit():
        post.title = form.title.data
        print(post.title, post.content)
        post.content = form.content.data
        db.session.add(post)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user', username=g.user.username))
Example #3
0
def change(rubbish_id):
    form = ChangeForm()
    post = Rubbish.query.filter_by(id=rubbish_id).first()
    if form.validate_on_submit():
        post.type = form.type.data
        post.weight = form.weight.data
        post.community = form.community.data
        print(post.type, post.weight, post.community)
        db.session.add(post)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user', username=g.user.username))
Example #4
0
def editrubbish(rubbish_id):
    form = ChangeForm()
    post = Rubbish.query.filter_by(id=rubbish_id).first()
    form.type.data = post.type
    form.weight.data = post.weight
    form.community.data = post.community
    return render_template('change.html', form=form, post_id=post.id)
Example #5
0
def changep():
    form = ChangeForm()
    username = current_user.username
    user = User.query.filter_by(username=username).first()
    css = user.css
    if form.validate_on_submit():
        if not user.checkPassword(form.oldpassword.data):
            flash('Incorrect password')
            return redirect(url_for('changep'))
        user.setPassword(form.newpassword.data)
        db.session.commit()
        flash('Password changed successfully')
        return redirect(url_for('index'))
    return render_template('changep.html',
                           title='Change Password',
                           form=form,
                           css=css)
Example #6
0
def editpost(post_id):
    form = ChangeForm()
    post = Post.query.filter_by(id=post_id).first_or_404()
    if post.author.username != current_user.username:
        abort(404)
    form.title.data = post.title
    form.content.data = post.content
    form.cat.data = post.cat_id
    return render_template('editpost.html', form=form, post_id=post.id)
Example #7
0
def add_change():
    form = ChangeForm()
    if form.validate_on_submit():
        Event().create(
            user_id=current_user.id,
            child_id=current_user.children[0],
            type='change',
            started_at=str(form.started_at.data),
            ended_at=str(form.started_at.data),
            feed_type=None,
            change_type=form.change_type.data,
            amount=None,
            unit=None,
            side=None,
            notes=form.notes.data)
        flash('Change has been added', 'success')
        return redirect(url_for('view_diary'))
    return render_template('change.html', title='Add change', form=form)
Example #8
0
def edit():
    form = ChangeForm()
    if not current_user.is_authenticated:
        flash('你还没登陆呢')
        redirect('/')
    if request.method == 'POST':
        oldpassword = request.form['oldpassword']
        newpassword = request.form['newpassword']
        confirm = request.form['confirm']
        if not current_user.check_password(oldpassword):
            flash('旧密码不正确')
            return redirect('/change')
        if not confirm == newpassword:
            flash('两次输入密码不一致')
            return redirect('/change')
        current_user.set_password(newpassword)
        db.session.commit()
        flash('修改成功')
    return render_template('change.html', form=form)
Example #9
0
def editpost(post_id):
    form = ChangeForm()
    post = Post.query.filter_by(id=post_id).first()
    form.title.data = post.title
    form.content.data = post.content
    return render_template('change.html', form=form, post_id=post.id)