Skip to content

Commit

Permalink
Make separate news blueprint
Browse files Browse the repository at this point in the history
Furthermore, redirect the index page to `/news/`
  • Loading branch information
lukasjuhrich committed Apr 22, 2015
1 parent 37a01e7 commit 6fc51ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
23 changes: 3 additions & 20 deletions sipa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from babel import Locale
from .babel import babel, possible_locales
from sipa.blueprints.news import bp_news
from sipa.flatpages import cf_pages
from sipa.blueprints import bp_usersuite, bp_pages, bp_documents, \
bp_features
Expand All @@ -42,6 +43,7 @@ def init_app():
app.register_blueprint(bp_usersuite)
app.register_blueprint(bp_pages)
app.register_blueprint(bp_documents)
app.register_blueprint(bp_news)

# global jinja variables
app.jinja_env.globals.update(
Expand Down Expand Up @@ -136,26 +138,7 @@ def set_language(lang='de'):
@app.route('/index.php')
@app.route('/')
def index():
"""Get all markdown files from 'news/', parse them and put
them in a list for the template.
The format is like this (Pelican compatible):
Title: ABC
Author: userX
Date: 1970-01-01
[Type: alert]
Message
The type field does not need to be used. If you use it, check what types
are available. For now, it's only 'alert' which colors the news entry red.
"""
cf_pages.reload()
latest = cf_pages.get_articles_of_category('news')
latest = sorted(latest, key=lambda a: a.date, reverse=True)
latest = latest[0:10]
return render_template("index.html", articles=latest)
return redirect(url_for("news.display"))


@app.route("/login", methods=['GET', 'POST'])
Expand Down
25 changes: 25 additions & 0 deletions sipa/blueprints/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Blueprint providing features regarding the news entries.
"""

from flask import Blueprint, render_template
from sipa.flatpages import cf_pages

bp_news = Blueprint('news', __name__, url_prefix='/news')


@bp_news.route("/")
def display():
"""Get all markdown files from 'content/news/', parse them and put
them in a list for the template.
The formatting of these files is described in the readme.
"""
cf_pages.reload()
latest = cf_pages.get_articles_of_category('news')
latest = sorted(latest, key=lambda a: a.date, reverse=True)
latest = latest[0:10]
return render_template("index.html", articles=latest)

0 comments on commit 6fc51ec

Please sign in to comment.