# 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
        self.notices_present = False
        section_ids = []
        for section in self.object._get_descendants(include_self=True):
            if section.title == 'NOTICES OF MOTION UNDER RULE 32(3)':
                self.notices_present = True
                if self.notices:
                    section_ids.append(section.id)
            elif not self.notices:
                section_ids.append(section.id)
        return Speech.objects.filter(section__in=section_ids).prefetch_related('speaker', 'speaker__memberships', 'speaker__memberships__organization', 'section', 'section__parent')

    def get_context_data(self, **kwargs):
        context = super(DebateDetailView, self).get_context_data(**kwargs)
        context['section'] = self.object
        context['notices'] = self.notices
        context['notices_present'] = self.notices_present
        return context
debate = DebateDetailView.as_view()
notices = DebateDetailView.as_view(notices=True)
debate_single_page = DebateDetailView.as_view(paginate_by=None)
notices_single_page = DebateDetailView.as_view(paginate_by=None, notices=True)


class BillListView(ListView):
    model = Bill
    template_name = 'bill_list.html'
bills = BillListView.as_view()


class BillDetailView(DetailView):

# 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

        self.notices_present = False
        section_ids = []
        for section in self.object._get_descendants(include_self=True):
            if section.title == 'NOTICES OF MOTION UNDER RULE 32(3)':
                self.notices_present = True
                if self.notices:
                    section_ids.append(section.id)
            elif not self.notices:
                section_ids.append(section.id)
        return Speech.objects.filter(section__in=section_ids).prefetch_related('speaker', 'speaker__memberships', 'speaker__memberships__organization', 'section', 'section__parent')

    def get_context_data(self, **kwargs):
        context = super(DebateDetailView, self).get_context_data(**kwargs)
        context['section'] = self.object
        context['notices'] = self.notices
        context['notices_present'] = self.notices_present
        return context
debate = DebateDetailView.as_view()
notices = DebateDetailView.as_view(notices=True)
debate_single_page = DebateDetailView.as_view(paginate_by=None)
notices_single_page = DebateDetailView.as_view(paginate_by=None, notices=True)


class BillListView(ListView):
    model = Bill
    template_name = 'bill_list.html'
bills = BillListView.as_view()


class BillDetailView(DetailView):

    model = Bill