<commit_before>from flask import abort, flash, jsonify, render_template, redirect, \
        request, url_for, Response
from flask.ext.csrf import csrf
from urlparse import urljoin
from werkzeug.contrib.atom import AtomFeed

from wuvt import app
from wuvt import db
from wuvt import lib

from wuvt.models import User
from wuvt.blog.models import Article, Category


def make_external(url):
    return urljoin(request.url_root, url)


@app.context_processor
def inject_categories():
    categories = Category.query.filter(Category.parent_id == 0).\
            order_by(Category.name).all()
    return {'categories': categories}


@app.route('/category/<string:slug>')
@app.route('/category/<string:slug>/<int:page>')
def category(slug, page=1):
    category = Category.query.filter(Category.slug == slug).first()
    if not category:
        abort(404)

    categories = Category.query.filter(Category.parent_id == category.id).\
            order_by(Category.name).all()
    articles = Article.query.filter(Article.category_id == category.id).\
            order_by(db.asc(Article.id)).paginate(page,
            app.config['POSTS_PER_PAGE'])
    return render_template('index.html', #categories=categories,
            articles=articles, feedlink=url_for('category_feed', slug=slug))


@app.route('/category/<string:slug>.atom')
def category_feed(slug):
    category = Category.query.filter(Category.slug == slug).first()
    if not category:
        abort(404)

    feed = AtomFeed("WUVT: {0}".format(category.name),
            feed_url=request.url, url=request.url_root)

    articles = Article.query.filter(Article.category_id == category.id).\
            order_by(db.asc(Article.id)).all()
    for article in articles:
        feed.add(article.title, unicode(article.content),
                content_type='html',
                author=article.author.name,
                url=make_external(url_for('article', slug=article.slug)),
                updated=article.datetime,
                published=article.datetime)

    return feed.get_response()


@app.route('/article/<string:slug>')
def article(slug):
    article = Article.query.filter(Article.slug == slug).first()
    if not article:
        abort(404)

    categories = Category.query.\
            filter(Category.parent_id == article.category.parent_id).\
            order_by(Category.name).all()
    return render_template('article.html', categories=categories,
            article=article)


@app.route('/feed.atom')
def all_feed():
    feed = AtomFeed("WUVT: Recent Articles", feed_url=request.url,
            url=request.url_root)<commit_msg>add separate article summary<commit_after>from flask import abort, flash, jsonify, render_template, redirect, \
        request, url_for, Response
from flask.ext.csrf import csrf
from urlparse import urljoin
from werkzeug.contrib.atom import AtomFeed

from wuvt import app
from wuvt import db
from wuvt import lib

from wuvt.models import User
from wuvt.blog.models import Article, Category


def make_external(url):
    return urljoin(request.url_root, url)


@app.context_processor
def inject_categories():
    categories = Category.query.filter(Category.parent_id == 0).\
            order_by(Category.name).all()
    return {'categories': categories}


@app.route('/category/<string:slug>')
@app.route('/category/<string:slug>/<int:page>')
def category(slug, page=1):
    category = Category.query.filter(Category.slug == slug).first()
    if not category:
        abort(404)

    categories = Category.query.filter(Category.parent_id == category.id).\
            order_by(Category.name).all()
    articles = Article.query.filter(Article.category_id == category.id).\
            order_by(db.asc(Article.id)).paginate(page,
            app.config['POSTS_PER_PAGE'])
    return render_template('index.html', #categories=categories,
            articles=articles, feedlink=url_for('category_feed', slug=slug))


@app.route('/category/<string:slug>.atom')
def category_feed(slug):
    category = Category.query.filter(Category.slug == slug).first()
    if not category:
        abort(404)

    feed = AtomFeed("WUVT: {0}".format(category.name),
            feed_url=request.url, url=request.url_root)

    articles = Article.query.filter(Article.category_id == category.id).\
            order_by(db.asc(Article.id)).all()
    for article in articles:
        feed.add(article.title, unicode(article.content),
                content_type='html',
                author=article.author.name,
                url=make_external(url_for('article', slug=article.slug)),
                updated=article.datetime,
                published=article.datetime)

    return feed.get_response()


@app.route('/article/<string:slug>')
def article(slug):
    article = Article.query.filter(Article.slug == slug).first()
    if not article:
        abort(404)

    categories = Category.query.\
            filter(Category.parent_id == article.category.parent_id).\
            order_by(Category.name).all()
    return render_template('article.html', categories=categories,
            article=article)

@app.route('/feed.atom')
def all_feed():
    feed = AtomFeed("WUVT: Recent Articles", feed_url=request.url,
            url=request.url_root)
{'fraction_non_alphanumeric': 0.1299047619047619, 'fraction_numerical': 0.004571428571428572, 'mean_word_length': 3.2795436022819886, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1504060', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1548, 'n_words': 296}