<commit_before>import re
import datetime

from django.shortcuts  import render_to_response, get_object_or_404, redirect
from django.http import Http404
from django.template   import RequestContext
from django.views.generic import TemplateView, DetailView

from pombola.hansard.models import Sitting, Entry
from pombola.core.models import Person

# import models
# from django.shortcuts  import render_to_response, redirect
# from django.template   import RequestContext
#
#
# def default(request):
#     return render_to_response(
#         'hansard/default.html',
#         {
#             'chunks': models.Chunk.objects.all(),
#         },
#         context_instance=RequestContext(request)
#     )
#
# #   /hansard/venue/yyyy/mm/dd/hh:mm
#

"""
Hansard views - possible url structure:

The url to the various hansard pages follow this sort of structure:

  ../venue/yyyy/mm/dd/day_id-slug-that-can-be-ignored

'venue' is the slug of the debating chamber, committee etc that the report is
for.

'yyyy', 'mm', 'dd', 'hh:mm' is the date down to the start of the sitting. It is
assumed that one chamber can only do one thing at a time so there will never be
a conflict.

    ^
    ^(?P<venue>[\w\-]+)/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>)/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>)/(?P<day_id>\d+)-(?P<slug>[\w\-]+)

"""

class IndexView(TemplateView):
    template_name = "hansard/index.html"

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)

        context['sittings'] = Sitting.objects.all() # FIXME - put a limit on here [0:10]

        return context


class SittingView(DetailView):
    model = Sitting

    def get_object(self):
        """Get the object based on venue and start date and time"""

        venue_slug = self.venue_slug
        start_date_and_time = self.start_date_and_time

        query_args = {
            'venue__slug':     venue_slug,
        }

        # add blank HH-MM-SS if needed
        start_time_parts = re.split('-', start_date_and_time)
        if len(start_time_parts) == 3:
            start_time_parts.extend( [ '00','00','00' ] )

        # split the date and time up into the relevant fields
        (year,month,day,hour,minute,second) = [ int(x) for x in start_time_parts ]

        # add start_date to the query
        query_args['start_date'] = datetime.date(year=year,month=month,day=day)

        # if there is a time use it
        if hour or minute or second:
            query_args['start_time__gte'] = datetime.time(hour=hour, minute=minute, second=second)

        # get all matching sittings
        sittings = Sitting.objects.filter( **query_args ).order_by('start_time')

        if not len(sittings):
            raise Http404

        return sittings[0]


# class BaseView ( View ):
#     pass
#
# class VenueMixin( object ):
#
#     def get_venue(self):
#         "Return the venue that should be searched for. 404s if not found."
#         return get_object_or_404(Venue, slug=self.slug)
#
# class IndexView( BaseView ):
#     pass
#
# class VenueView( VenueMixin, BaseView ):
#     pass
#
# class YearView( YearMixin, VenueView ):
#     pass
#
<commit_msg>Revert a change that shouldn't have been introduced<commit_after>import re
import datetime

from django.shortcuts  import render_to_response, get_object_or_404, redirect
from django.http import Http404
from django.template   import RequestContext
from django.views.generic import TemplateView, DetailView

from pombola.hansard.models import Sitting, Entry
from pombola.core.models import Person

# import models
# from django.shortcuts  import render_to_response, redirect
# from django.template   import RequestContext
#
#
# def default(request):
#     return render_to_response(
#         'hansard/default.html',
#         {
#             'chunks': models.Chunk.objects.all(),
#         },
#         context_instance=RequestContext(request)
#     )
#
# #   /hansard/venue/yyyy/mm/dd/hh:mm
#

"""
Hansard views - possible url structure:

The url to the various hansard pages follow this sort of structure:

  ../venue/yyyy/mm/dd/day_id-slug-that-can-be-ignored

'venue' is the slug of the debating chamber, committee etc that the report is
for.

'yyyy', 'mm', 'dd', 'hh:mm' is the date down to the start of the sitting. It is
assumed that one chamber can only do one thing at a time so there will never be
a conflict.

    ^
    ^(?P<venue>[\w\-]+)/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>)/
    ^(?P<venue>[\w\-]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>)/(?P<day_id>\d+)-(?P<slug>[\w\-]+)

"""

class IndexView(TemplateView):
    template_name = "hansard/index.html"

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)

        context['sittings'] = Sitting.objects.all() # FIXME - put a limit on here [0:10]

        return context


class SittingView(DetailView):
    model = Sitting

    def get_object(self):
        """Get the object based on venue and start date and time"""

        venue_slug = self.kwargs['venue_slug']
        start_date_and_time = self.kwargs['start_date_and_time']

        query_args = {
            'venue__slug':     venue_slug,
        }

        # add blank HH-MM-SS if needed
        start_time_parts = re.split('-', start_date_and_time)
        if len(start_time_parts) == 3:
            start_time_parts.extend( [ '00','00','00' ] )

        # split the date and time up into the relevant fields
        (year,month,day,hour,minute,second) = [ int(x) for x in start_time_parts ]

        # add start_date to the query
        query_args['start_date'] = datetime.date(year=year,month=month,day=day)

        # if there is a time use it
        if hour or minute or second:
            query_args['start_time__gte'] = datetime.time(hour=hour, minute=minute, second=second)

        # get all matching sittings
        sittings = Sitting.objects.filter( **query_args ).order_by('start_time')

        if not len(sittings):
            raise Http404

        return sittings[0]


# class BaseView ( View ):
#     pass
#
# class VenueMixin( object ):
#
#     def get_venue(self):
#         "Return the venue that should be searched for. 404s if not found."
#         return get_object_or_404(Venue, slug=self.kwargs['slug'])
#
# class IndexView( BaseView ):
#     pass
#
# class VenueView( VenueMixin, BaseView ):
#     pass
#
# class YearView( YearMixin, VenueView ):
#     pass
#

{'fraction_non_alphanumeric': 0.13965568417928167, 'fraction_numerical': 0.009795191451469279, 'mean_word_length': 3.00653983353151, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '6240611', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2228, 'n_words': 559}