示例#1
0
文件: views.py 项目: Calvin-CS/csweb
def display_news_article(name):
    '''This routine displays a single news article.'''
    article = check_unit(News.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('news', name),
        title=article.get('title'),
        subtitle=article.get('date').strftime('%B %d, %Y'),
        primary='<p>' + article.get('content') + '</p>',
        current=get_name('news', name),
        editable=True,
        editableUrl=url_for('web.update_news_article', name=name)
    )
示例#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'))