# Path: montanha/models.py
# class Institution(models.Model):
# 
#     class Meta:
#         verbose_name = _("Institution")
#         verbose_name_plural = _("Institutions")
# 
#     name = models.CharField(max_length=2048,
#                             verbose_name=_("Name"))
# 
#     siglum = models.CharField(max_length=10,
#                               verbose_name=_("Siglum"),
#                               unique=True)
# 
#     logo = ThumbnailerImageField(
#         verbose_name=_('Logo'),
#         upload_to='institution',
#         blank=True,
#         null=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)
# 
# class Legislature(models.Model):
# 
#     class Meta:
#         verbose_name = _("Legislature")
#         verbose_name_plural = _("Legislatures")
# 
#     institution = models.ForeignKey("Institution")
# 
#     original_id = models.CharField(blank=True, null=True,
#                                    max_length=512,
#                                    verbose_name=_("Original ID"))
# 
#     date_start = models.DateField(verbose_name=_("Date started"),
#                                   help_text=_("""Date in which this legislature started."""),
#                                   db_index=True)
# 
#     date_end = models.DateField(blank=True, null=True,
#                                 verbose_name=_("Date ended"),
#                                 help_text=_("""Date in which this legislature ended."""),
#                                 db_index=True)
# 
#     def __unicode__(self):
#         return u"%s's legislature starting at %s, ending at %s" % (self.institution.siglum,
#                                                                    str(self.date_start),
#                                                                    str(self.date_end))


from datetime import date
from montanha.models import Institution, Legislature

        current_date_from: the start date that is being used for this query
        current_date_to: the end date that is being used for this query
    """
    try:
        if consolidated_data:
            cdf = data.order_by('date_start')[0].date_start
        else:
            cdf = data.order_by('date')[0].date
    except Exception:
        cdf = date.today()

    try:
        if consolidated_data:
            cdt = data.order_by('-date_end')[0].date_end
        else:
            cdt = data.order_by('-date')[0].date
    except Exception:
        cdt = date.today()

    if institution:
        if not isinstance(institution, Institution):
            institution = Institution.objects.get(siglum=institution)

        # Bound dates to the start of the first legislature to the end
        # of the last, which makes more sense to our purposes.
        first = institution.legislature_set.order_by('date_start')[0]
        last = institution.legislature_set.order_by('-date_end')[0]
    else:
        first = Legislature.objects.order_by('date_start')[0]

# Path: montanha/models.py
# class Institution(models.Model):
# 
#     class Meta:
#         verbose_name = _("Institution")
#         verbose_name_plural = _("Institutions")
# 
#     name = models.CharField(max_length=2048,
#                             verbose_name=_("Name"))
# 
#     siglum = models.CharField(max_length=10,
#                               verbose_name=_("Siglum"),
#                               unique=True)
# 
#     logo = ThumbnailerImageField(
#         verbose_name=_('Logo'),
#         upload_to='institution',
#         blank=True,
#         null=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)
# 
# class Legislature(models.Model):
# 
#     class Meta:
#         verbose_name = _("Legislature")
#         verbose_name_plural = _("Legislatures")
# 
#     institution = models.ForeignKey("Institution")
# 
#     original_id = models.CharField(blank=True, null=True,
#                                    max_length=512,
#                                    verbose_name=_("Original ID"))
# 
#     date_start = models.DateField(verbose_name=_("Date started"),
#                                   help_text=_("""Date in which this legislature started."""),
#                                   db_index=True)
# 
#     date_end = models.DateField(blank=True, null=True,
#                                 verbose_name=_("Date ended"),
#                                 help_text=_("""Date in which this legislature ended."""),
#                                 db_index=True)
# 
#     def __unicode__(self):
#         return u"%s's legislature starting at %s, ending at %s" % (self.institution.siglum,
#                                                                    str(self.date_start),
#                                                                    str(self.date_end))


# Path: montanha/util.py
from datetime import date
from montanha.models import Institution, Legislature


        current_date_from: the start date that is being used for this query
        current_date_to: the end date that is being used for this query
    """
    try:
        if consolidated_data:
            cdf = data.order_by('date_start')[0].date_start
        else:
            cdf = data.order_by('date')[0].date
    except Exception:
        cdf = date.today()

    try:
        if consolidated_data:
            cdt = data.order_by('-date_end')[0].date_end
        else:
            cdt = data.order_by('-date')[0].date
    except Exception:
        cdt = date.today()

    if institution:
        if not isinstance(institution, Institution):
            institution = Institution.objects.get(siglum=institution)

        # Bound dates to the start of the first legislature to the end
        # of the last, which makes more sense to our purposes.
        first = institution.legislature_set.order_by('date_start')[0]
        last = institution.legislature_set.order_by('-date_end')[0]
    else:
        first = Legislature.objects.order_by('date_start')[0]

        last = Legislature.objects.order_by('-date_end')[0]