<commit_before>import datetime
import re

from django.contrib.syndication.views import Feed
from django.core import urlresolvers
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.template import Context, loader, RequestContext
from django.template.defaultfilters import date as format_date
from django.views.decorators.vary import vary_on_headers

from parliament.bills.models import Bill, VoteQuestion, MemberVote
from parliament.core.models import Session
from parliament.hansards.models import Statement

def bill_pk_redirect(request, bill_id):
    bill = get_object_or_404(Bill, pk=bill_id)
    return HttpResponsePermanentRedirect(
        urlresolvers.reverse('parliament.bills.views.bill', kwargs={
        'session_id': bill.get_session().id, 'bill_number': bill.number}))

@vary_on_headers('X-Requested-With')
def bill(request, session_id, bill_number):
    PER_PAGE = 10
    bill = get_object_or_404(Bill, sessions=session_id, number=bill_number)
    statements = bill.statement_set.all().order_by('-time', '-sequence').select_related('member', 'member__politician', 'member__riding', 'member__party')
    paginator = Paginator(statements, PER_PAGE)

    try:
        pagenum = int(request.GET.get('page', '1'))
    except ValueError:
        pagenum = 1
    try:
        page = paginator.page(pagenum)
    except (EmptyPage, InvalidPage):
        page = paginator.page(paginator.num_pages)

    c = RequestContext(request, {
        'bill': bill,
        'page': page,
        'votequestions': bill.votequestion_set.all().order_by('-date'),
        'title': ('Bill %s' % bill.number) + (' (Historical)' if bill.session.end else ''), 
        'statements_full_date': True,
        'statements_context_link': True,
    })
    if request.is_ajax():
        t = loader.get_template("hansards/statement_page.inc")
    else:
        t = loader.get_template("bills/bill_detail.html")
    return HttpResponse(t.render(c))
    
def index(request):
    sessions = Session.objects.with_bills()
    len(sessions) # evaluate it
    bills = Bill.objects.filter(sessions=sessions[0])
    votes = VoteQuestion.objects.select_related('bill').filter(session=sessions[0])[:6]

    t = loader.get_template('bills/index.html')
    c = RequestContext(request, {
        'object_list': bills,
        'session_list': sessions,
        'votes': votes,
        'session': sessions[0],<commit_msg>Correct vote order on bill page<commit_after>import datetime
import re

from django.contrib.syndication.views import Feed
from django.core import urlresolvers
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.template import Context, loader, RequestContext
from django.template.defaultfilters import date as format_date
from django.views.decorators.vary import vary_on_headers

from parliament.bills.models import Bill, VoteQuestion, MemberVote
from parliament.core.models import Session
from parliament.hansards.models import Statement

def bill_pk_redirect(request, bill_id):
    bill = get_object_or_404(Bill, pk=bill_id)
    return HttpResponsePermanentRedirect(
        urlresolvers.reverse('parliament.bills.views.bill', kwargs={
        'session_id': bill.get_session().id, 'bill_number': bill.number}))

@vary_on_headers('X-Requested-With')
def bill(request, session_id, bill_number):
    PER_PAGE = 10
    bill = get_object_or_404(Bill, sessions=session_id, number=bill_number)
    statements = bill.statement_set.all().order_by('-time', '-sequence').select_related('member', 'member__politician', 'member__riding', 'member__party')
    paginator = Paginator(statements, PER_PAGE)

    try:
        pagenum = int(request.GET.get('page', '1'))
    except ValueError:
        pagenum = 1
    try:
        page = paginator.page(pagenum)
    except (EmptyPage, InvalidPage):
        page = paginator.page(paginator.num_pages)

    c = RequestContext(request, {
        'bill': bill,
        'page': page,
        'votequestions': bill.votequestion_set.all().order_by('-date', '-number'),
        'title': ('Bill %s' % bill.number) + (' (Historical)' if bill.session.end else ''), 
        'statements_full_date': True,
        'statements_context_link': True,
    })
    if request.is_ajax():
        t = loader.get_template("hansards/statement_page.inc")
    else:
        t = loader.get_template("bills/bill_detail.html")
    return HttpResponse(t.render(c))
    
def index(request):
    sessions = Session.objects.with_bills()
    len(sessions) # evaluate it
    bills = Bill.objects.filter(sessions=sessions[0])
    votes = VoteQuestion.objects.select_related('bill').filter(session=sessions[0])[:6]

    t = loader.get_template('bills/index.html')
    c = RequestContext(request, {
        'object_list': bills,
        'session_list': sessions,
        'votes': votes,
        'session': sessions[0],
{'fraction_non_alphanumeric': 0.11661807580174927, 'fraction_numerical': 0.007774538386783284, 'mean_word_length': 4.197979797979798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6507393', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1546, 'n_words': 327}