<commit_before>from datetime import datetime
from flask import (
    abort,
    redirect,
    render_template,
    request,
    Response,
    url_for,
    )

from hasjob import app
from hasjob.models import JobCategory, JobPost, JobType, POSTSTATUS
from hasjob.search import do_search
from hasjob.views import newlimit
from hasjob.views.helper import getposts, getallposts
from hasjob.uploads import uploaded_logos

@app.route('/')
def index(basequery=None, type=None, category=None, md5sum=None, domain=None):
    now = datetime.utcnow()
    posts = list(getposts(basequery, sticky=True))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'
    return render_template('index.html', posts=posts, now=now, newlimit=newlimit,
                           jobtype=type, jobcategory=category, md5sum=md5sum,
                           domain=domain, employer_name=employer_name)


@app.route('/type/<slug>')
def browse_by_type(slug):
    if slug == 'all':
        return redirect(url_for('index'))
    ob = JobType.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(type_id=ob.id)
    return index(basequery=basequery, type=ob)


@app.route('/at/<domain>')
def browse_by_domain(domain):
    if not domain:
        abort(404)
    basequery = JobPost.query.filter_by(email_domain=domain)
    return index(basequery=basequery, domain=domain)


@app.route('/category/<slug>')
def browse_by_category(slug):
    if slug == 'all':
        return redirect(url_for('index'))
    ob = JobCategory.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(category_id=ob.id)
    return index(basequery=basequery, category=ob)


@app.route('/by/<md5sum>')
def browse_by_email(md5sum):
    if not md5sum:
        abort(404)
    basequery = JobPost.query.filter_by(md5sum=md5sum)
    return index(basequery=basequery, md5sum=md5sum)


@app.route('/feed')
def feed(basequery=None, type=None, category=None, md5sum=None, domain=None):
    title = "All jobs"
    if type:
        title = type.title
    elif category:
        title = category.title
    elif md5sum or domain:
        title = u"Jobs at a single employer"
    posts = list(getposts(basequery))
    if posts: # Can't do this unless posts is a list
        updated = posts[0].datetime.isoformat()+'Z'
        if md5sum:
            title = posts[0].company_name
    else:
        updated = datetime.utcnow().isoformat()+'Z'
    return Response(render_template('feed.xml', posts=posts, updated=updated, title=title),
                           content_type = 'application/atom+xml; charset=utf-8')


@app.route('/type/<slug>/feed')
def feed_by_type(slug):
    if slug == 'all':
        return redirect(url_for('feed'))
    ob = JobType.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(type_id=ob.id)
    return feed(basequery=basequery, type=ob)


@app.route('/category/<slug>/feed')
def feed_by_category(slug):
    if slug == 'all':
        return redirect(url_for('feed'))
    ob = JobCategory.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(category_id=ob.id)
    return feed(basequery=basequery, category=ob)


@app.route('/by/<md5sum>/feed')
def feed_by_email(md5sum):
    if not md5sum:
        abort(404)
    basequery = JobPost.query.filter_by(md5sum=md5sum)
    return feed(basequery=basequery, md5sum=md5sum)


@app.route('/at/<domain>')
def browse_by_domain(domain):
    if not domain:
        abort(404)
    basequery = JobPost.query.filter_by(email_domain=domain)
    return index(basequery=basequery, domain=domain)


@app.route('/archive')
def archive():
    def sortarchive(order_by):
        current_order_by = request.args.get('order_by')
        reverse = request.args.get('reverse')
        if order_by == current_order_by:
            if reverse is None:
                reverse = False
            try:
                reverse = bool(int(reverse))
            except ValueError:
                reverse = False
            reverse = int(not reverse)
        return url_for('archive', order_by=order_by,
            reverse=reverse,
            start=request.args.get('start'),
            limit=request.args.get('limit'))
<commit_msg>Fix function name<commit_after>from datetime import datetime
from flask import (
    abort,
    redirect,
    render_template,
    request,
    Response,
    url_for,
    )

from hasjob import app
from hasjob.models import JobCategory, JobPost, JobType, POSTSTATUS
from hasjob.search import do_search
from hasjob.views import newlimit
from hasjob.views.helper import getposts, getallposts
from hasjob.uploads import uploaded_logos

@app.route('/')
def index(basequery=None, type=None, category=None, md5sum=None, domain=None):
    now = datetime.utcnow()
    posts = list(getposts(basequery, sticky=True))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'
    return render_template('index.html', posts=posts, now=now, newlimit=newlimit,
                           jobtype=type, jobcategory=category, md5sum=md5sum,
                           domain=domain, employer_name=employer_name)


@app.route('/type/<slug>')
def browse_by_type(slug):
    if slug == 'all':
        return redirect(url_for('index'))
    ob = JobType.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(type_id=ob.id)
    return index(basequery=basequery, type=ob)


@app.route('/at/<domain>')
def browse_by_domain(domain):
    if not domain:
        abort(404)
    basequery = JobPost.query.filter_by(email_domain=domain)
    return index(basequery=basequery, domain=domain)


@app.route('/category/<slug>')
def browse_by_category(slug):
    if slug == 'all':
        return redirect(url_for('index'))
    ob = JobCategory.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(category_id=ob.id)
    return index(basequery=basequery, category=ob)


@app.route('/by/<md5sum>')
def browse_by_email(md5sum):
    if not md5sum:
        abort(404)
    basequery = JobPost.query.filter_by(md5sum=md5sum)
    return index(basequery=basequery, md5sum=md5sum)


@app.route('/feed')
def feed(basequery=None, type=None, category=None, md5sum=None, domain=None):
    title = "All jobs"
    if type:
        title = type.title
    elif category:
        title = category.title
    elif md5sum or domain:
        title = u"Jobs at a single employer"
    posts = list(getposts(basequery))
    if posts: # Can't do this unless posts is a list
        updated = posts[0].datetime.isoformat()+'Z'
        if md5sum:
            title = posts[0].company_name
    else:
        updated = datetime.utcnow().isoformat()+'Z'
    return Response(render_template('feed.xml', posts=posts, updated=updated, title=title),
                           content_type = 'application/atom+xml; charset=utf-8')


@app.route('/type/<slug>/feed')
def feed_by_type(slug):
    if slug == 'all':
        return redirect(url_for('feed'))
    ob = JobType.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(type_id=ob.id)
    return feed(basequery=basequery, type=ob)


@app.route('/category/<slug>/feed')
def feed_by_category(slug):
    if slug == 'all':
        return redirect(url_for('feed'))
    ob = JobCategory.query.filter_by(slug=slug).first_or_404()
    basequery = JobPost.query.filter_by(category_id=ob.id)
    return feed(basequery=basequery, category=ob)


@app.route('/by/<md5sum>/feed')
def feed_by_email(md5sum):
    if not md5sum:
        abort(404)
    basequery = JobPost.query.filter_by(md5sum=md5sum)
    return feed(basequery=basequery, md5sum=md5sum)


@app.route('/at/<domain>')
def feed_by_domain(domain):
    if not domain:
        abort(404)
    basequery = JobPost.query.filter_by(email_domain=domain)
    return index(basequery=basequery, domain=domain)


@app.route('/archive')
def archive():
    def sortarchive(order_by):
        current_order_by = request.args.get('order_by')
        reverse = request.args.get('reverse')
        if order_by == current_order_by:
            if reverse is None:
                reverse = False
            try:
                reverse = bool(int(reverse))
            except ValueError:
                reverse = False
            reverse = int(not reverse)
        return url_for('archive', order_by=order_by,
            reverse=reverse,
            start=request.args.get('start'),
            limit=request.args.get('limit'))

{'fraction_non_alphanumeric': 0.12310207895351553, 'fraction_numerical': 0.011212333566923615, 'mean_word_length': 3.2538499751614505, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4500623', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2784, 'n_words': 544}