Exemplo n.º 1
0
def new_entry():
    ''' Add a entry. '''

    error = None
    if request.method == 'POST':
        title = request.form.get('entry-title')
        abstract = request.form.get('entry-abstract')
        tags = request.form.get('entry-tags')
        published = request.form.get('entry-publish', 'off') == 'on'
        body = request.form.get('entry-body')

        entry = db.Entry()
        entry.title = title
        entry.abstract = abstract
        entry.slug = slugify(title)
        # If an entry with this slug already exists, append '2' to make it
        # unique.
        pre_entries = db.Entry.find({'slug': entry.slug})
        if pre_entries.count():
            entry.slug += '-%s' % (pre_entries.count() + 1, )
        entry.body = body
        entry.set_tags(tags)
        entry.published = published

        entry.pub_date = datetime.utcnow()

        entry.save()

        flash('Entry created.')
        return redirect(url_for('blog.entries'))

    return render_template('blog/new.html')
Exemplo n.º 2
0
def edit_entry(slug):
    ''' Edit an existing entry. '''

    error = None
    entry = get_by_slug(slug)
    if request.method == 'POST':

        title = request.form.get('entry-title')
        abstract = request.form.get('entry-abstract')
        tags = request.form.get('entry-tags')
        published = request.form.get('entry-publish', 'off') == 'on'
        body = request.form.get('entry-body')
        # If the title has changed, then change the slug
        if title != entry.title:
            entry.slug = slugify(title)
        entry.title = title
        entry.abstract = abstract
        entry.body = body
        entry.set_tags(tags)
        entry.edit_date = datetime.utcnow()

        entry.published = published

        entry.deleted = request.form.get('entry-delete', 'off') == 'on'

        entry.save()

        flash('Entry edited.')
        return redirect(url_for('blog.entries'))
    return render_template('blog/edit.html', entry=entry)