# Path: legislature/models.py
# class Action(models.Model):
#     description = models.TextField()
#     date = models.DateField(blank=True, null=True)
#     text = models.TextField(blank=True, null=True)
#     bill = models.ForeignKey(Bill, blank=True, null=True)  # had to be NULL for migration
# 
#     class Meta:
#         ordering = ['date']
#         unique_together = ('bill', 'description')
# 
#     def __str__(self):
#         return self.description
# 
# class Bill(models.Model):
#     STATUS_CHOICES = (
#         ('1st', 'First Reading'),
#         ('2nd', 'Second Reading'),
#         ('LA', 'Law Amendments Committee'),
#         ('PL', 'Private & Local Bills Committee'),
#         ('WH', 'Committee of the Whole House'),
#         ('3rd', 'Third Reading'),
#         ('RA', 'Royal Assent'),
#     )
# 
#     identifier = models.PositiveIntegerField()
#     title = models.TextField()
#     description = models.TextField()
#     classification = models.TextField()
#     creator = models.ForeignKey(Speaker, blank=True, null=True, on_delete=models.SET_NULL)
#     modified = models.DateField()
#     status = models.CharField(max_length=3, choices=STATUS_CHOICES)
#     slug = models.TextField()
#     url = models.URLField()
#     law_amendments_committee_submissions_url = models.URLField()
# 
#     def __str__(self):
#         return self.title
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('legislature:bill-view', (), {'slug': self.slug})


import calendar
import json
import re
from collections import defaultdict
from heapq import nlargest
from operator import itemgetter
from django import forms
from django.db.models import Count
from django.shortcuts import get_object_or_404, render_to_response
from django.utils.html import strip_tags
from django.views.generic import ListView, DetailView
from django.views.generic.dates import ArchiveIndexView, YearArchiveView, MonthArchiveView
from haystack.forms import SearchForm
from haystack.query import RelatedSearchQuerySet
from haystack.views import SearchView
from popolo.models import Organization
from speeches.models import Section, Speaker, Speech
from speeches.search import SpeakerForm
from legislature.models import Action, Bill
        return context


class DebateArchiveIndexView(ArchiveIndexView):
    queryset = Section.objects.filter(parent=None)
    date_field = 'start_date'
    template_name = 'section_archive.html'
debates = DebateArchiveIndexView.as_view()


class DebateYearArchiveView(TitleAdder, YearArchiveView):
    queryset = Section.objects.filter(parent=None).order_by('start_date')
    date_field = 'start_date'
    template_name = 'section_archive_year.html'
    make_object_list = True
    page_title = lambda self: 'Debates from %s' % self.get_year()
debates_by_year = DebateYearArchiveView.as_view()


class DebateMonthArchiveView(TitleAdder, MonthArchiveView):
    queryset = Section.objects.filter(parent=None).order_by('start_date')
    date_field = 'start_date'
    template_name = 'section_archive_month.html'
    make_object_list = True
    page_title = lambda self: 'Debates from %s %s' % (calendar.month_name[int(self.get_month())], self.get_year())
    month_format = '%m'  # Use integers in paths.
debates_by_month = DebateMonthArchiveView.as_view()


class SpeakerListView(ListView):

# Path: legislature/models.py
# class Action(models.Model):
#     description = models.TextField()
#     date = models.DateField(blank=True, null=True)
#     text = models.TextField(blank=True, null=True)
#     bill = models.ForeignKey(Bill, blank=True, null=True)  # had to be NULL for migration
# 
#     class Meta:
#         ordering = ['date']
#         unique_together = ('bill', 'description')
# 
#     def __str__(self):
#         return self.description
# 
# class Bill(models.Model):
#     STATUS_CHOICES = (
#         ('1st', 'First Reading'),
#         ('2nd', 'Second Reading'),
#         ('LA', 'Law Amendments Committee'),
#         ('PL', 'Private & Local Bills Committee'),
#         ('WH', 'Committee of the Whole House'),
#         ('3rd', 'Third Reading'),
#         ('RA', 'Royal Assent'),
#     )
# 
#     identifier = models.PositiveIntegerField()
#     title = models.TextField()
#     description = models.TextField()
#     classification = models.TextField()
#     creator = models.ForeignKey(Speaker, blank=True, null=True, on_delete=models.SET_NULL)
#     modified = models.DateField()
#     status = models.CharField(max_length=3, choices=STATUS_CHOICES)
#     slug = models.TextField()
#     url = models.URLField()
#     law_amendments_committee_submissions_url = models.URLField()
# 
#     def __str__(self):
#         return self.title
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('legislature:bill-view', (), {'slug': self.slug})


# Path: legislature/views.py
import calendar
import json
import re
from collections import defaultdict
from heapq import nlargest
from operator import itemgetter
from django import forms
from django.db.models import Count
from django.shortcuts import get_object_or_404, render_to_response
from django.utils.html import strip_tags
from django.views.generic import ListView, DetailView
from django.views.generic.dates import ArchiveIndexView, YearArchiveView, MonthArchiveView
from haystack.forms import SearchForm
from haystack.query import RelatedSearchQuerySet
from haystack.views import SearchView
from popolo.models import Organization
from speeches.models import Section, Speaker, Speech
from speeches.search import SpeakerForm
from legislature.models import Action, Bill

        return context


class DebateArchiveIndexView(ArchiveIndexView):
    queryset = Section.objects.filter(parent=None)
    date_field = 'start_date'
    template_name = 'section_archive.html'
debates = DebateArchiveIndexView.as_view()


class DebateYearArchiveView(TitleAdder, YearArchiveView):
    queryset = Section.objects.filter(parent=None).order_by('start_date')
    date_field = 'start_date'
    template_name = 'section_archive_year.html'
    make_object_list = True
    page_title = lambda self: 'Debates from %s' % self.get_year()
debates_by_year = DebateYearArchiveView.as_view()


class DebateMonthArchiveView(TitleAdder, MonthArchiveView):
    queryset = Section.objects.filter(parent=None).order_by('start_date')
    date_field = 'start_date'
    template_name = 'section_archive_month.html'
    make_object_list = True
    page_title = lambda self: 'Debates from %s %s' % (calendar.month_name[int(self.get_month())], self.get_year())
    month_format = '%m'  # Use integers in paths.
debates_by_month = DebateMonthArchiveView.as_view()


class SpeakerListView(ListView):

    queryset = Speaker.objects.exclude(email=None).order_by('sort_name').prefetch_related('memberships')