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') )
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) )
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 )
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') )
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'))
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') )
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'))