コード例 #1
0
def new_mark():
    form = MarkForm()
    if form.validate_on_submit():
        m = Mark()
        form.populate_obj(m)
        m.owner_id = g.user.id
        m.created = datetime.utcnow()
        if form.tags.data:
            m.tags = ' '.join([t.strip()
                              for t in form.tags.data.strip().split(',')])\
                        .lower()
        m.clicks = 0
        if not form.title.data:
            soup = BSoup(urlopen(form.url.data))
            m.title = soup.title.string
        db.session.add(m)
        db.session.commit()
        flash('New mark %s added' % (m.title), category='info')
        return redirect(url_for('marks'))
    if request.args.get('url'):
        form.url.data = request.args.get('url')
    if request.args.get('title'):
        form.title.data = request.args.get('title')
    if request.args.get('type') == 'feed':
        form.type.data = 'feed'
    return render_template('mark/new.html', title='New mark', form=form)
コード例 #2
0
ファイル: views.py プロジェクト: Cuahutli/Flaskmarks
def new_mark():
    form = MarkForm()
    if form.validate_on_submit():
        m = Mark()
        form.populate_obj(m)
        m.owner_id = g.user.id
        m.created = datetime.utcnow()
        if form.tags.data:
            m.tags = ' '.join([t.strip()
                              for t in form.tags.data.strip().split(',')])\
                        .lower()
        m.clicks = 0
        if not form.title.data:
            soup = BSoup(urlopen(form.url.data))
            m.title = soup.title.string
        db.session.add(m)
        db.session.commit()
        flash('New mark %s added' % (m.title), category='info')
        return redirect(url_for('marks'))
    if request.args.get('url'):
        form.url.data = request.args.get('url')
    if request.args.get('title'):
        form.title.data = request.args.get('title')
    if request.args.get('type') == 'feed':
        form.type.data = 'feed'
    return render_template('mark/new.html',
                           title='New mark',
                           form=form)
コード例 #3
0
def edit_mark(id):
    m = g.user.mid(id)
    form = MarkForm(obj=m)
    if not m:
        abort(403)
    if form.validate_on_submit():
        form.populate_obj(m)
        m.updated = datetime.utcnow()
        db.session.add(m)
        db.session.commit()
        flash('Mark %s updated' % (form.title.data), category='info')
        if form.referrer.data and is_safe_url(form.referrer.data):
            return redirect(form.referrer.data)
        return redirect(url_for('marks'))
    form.referrer.data = request.referrer
    return render_template('mark/edit.html',
                           title='Edit mark - %s' % m.title,
                           form=form)
コード例 #4
0
ファイル: views.py プロジェクト: Cuahutli/Flaskmarks
def edit_mark(id):
    m = g.user.mid(id)
    form = MarkForm(obj=m)
    if not m:
        abort(403)
    if form.validate_on_submit():
        form.populate_obj(m)
        m.updated = datetime.utcnow()
        db.session.add(m)
        db.session.commit()
        flash('Mark %s updated' % (form.title.data), category='info')
        if form.referrer.data and is_safe_url(form.referrer.data):
            return redirect(form.referrer.data)
        return redirect(url_for('marks'))
    form.referrer.data = request.referrer
    return render_template('mark/edit.html',
                           title='Edit mark - %s' % m.title,
                           form=form)