示例#1
0
文件: views.py 项目: Calvin-CS/csweb
def create_news_article():
    '''This routine does one of two things: if the user has asked to create a
    news article (GET), it displays an empty form for the user to use to
    create the new article; if the user has filled and submitted the creation
    form (POST), it writes the (new) form contents into the database entry
    under a new, unique id.
    '''
    form = News()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            name = News.create_unit(form)
            return redirect(url_for('web.display_news_article', name=name))
        else:
            return redirect(url_for('web.display_admin_news'))
    else:
        form.initialize(action='create')
        return display_content(
            form=form,
            title='Create Article',
            breadcrumbs=get_breadcrumbs('news', 'create')
        )
示例#2
0
文件: views.py 项目: Calvin-CS/csweb
def update_news_article(name):
    '''This routine does one of two things: if the user has asked to edit a
    news article (GET), it displays an editing form for the given article
    id, populated with the current database content; if the user has filled
    and submitted the editing form (POST), it writes the (modified) form
    contents into the database entry for the given article id.
    '''
    form = News()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            News.update_unit(form)
            return redirect(url_for('web.display_news_article', name=name))
    else:
        article = News.read_unit(name)
        if article:
            form.initialize(action='edit', unit=article)
            return display_content(
                form=form,
                title='Edit: ' + name,
                breadcrumbs=get_breadcrumbs('news', name, 'edit')
            )
    return redirect(url_for('web.display_admin_news'))