示例#1
0
文件: views.py 项目: Calvin-CS/csweb
def display_news():
    '''This routine displays the main news list page.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('news'),
        title='Computing News',
        primaryList=create_full_news_list(News.read_units()),
        primaryListHr=True,
        editable=True,
        editableUrl=url_for('web.display_admin_news')
    )
示例#2
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)
    )
示例#3
0
文件: views.py 项目: Calvin-CS/csweb
def display_admin_news():
    '''This routine displays the administration tools for news.
    We'll eventually use CIT's news tools.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'news'),
        title='Administration: News Articles',
        primary=create_hyperlink(url_for('web.create_news_article'),
                                 'Create a news article'),
        primaryList=create_newsarticle_list(News.read_units()),
        primaryListHr=True,
        editable=False
    )
示例#4
0
文件: views.py 项目: Calvin-CS/csweb
def display_index():
    '''Configure and display the main index page, with an appropriate image,
    the department short description and a list of current news articles.
    '''
    department = check_unit(Departments.read_unit('cs'))
    return display_content(
        image=Images.read_tagged_unit('departments.cs'),
        title=department.get('title'),
        subtitle=department.get('tagline'),
        primary=department.get('shortDescription'),
        sideTitle='Computing News',
        sideList=create_brief_news_list(News.read_units(limit=2 + TechNews.TECH_NEWS_LIMIT)),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
示例#5
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'))
示例#6
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')
        )
示例#7
0
文件: views.py 项目: Calvin-CS/csweb
def delete_news_article(name):
    '''This routine deletes the given news article. This is not restful;
    the system should accept only DELETE requests on /news/<name>.
    '''
    News.delete_unit(name)
    return redirect(url_for('web.display_admin_news'))