def bill_text(request, congress, type_slug, number, version=None): if version == "": version = None try: bill_type = BillType.by_slug(type_slug) except BillType.NotFound: raise Http404("Invalid bill type: " + type_slug) bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number) from billtext import load_bill_text, get_bill_text_versions try: textdata = load_bill_text(bill, version) except IOError: textdata = None # Get a list of the alternate versions of this bill. alternates = None is_latest = True if textdata: alternates = [] for v in get_bill_text_versions(bill): try: alternates.append(load_bill_text(bill, v, mods_only=True)) except IOError: pass alternates.sort(key = lambda mods : mods["docdate"]) if len(alternates) > 0: is_latest = False if textdata["doc_version"] == alternates[-1]["doc_version"]: is_latest = True # Get a list of related bills. from billtext import get_current_version related_bills = [] for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]: try: rbv = get_current_version(rb) if not (rb, rbv) in related_bills: related_bills.append((rb, rbv)) except IOError: pass # text not available for btc in BillTextComparison.objects.filter(bill1=bill).exclude(bill2=bill): if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2)) for btc in BillTextComparison.objects.filter(bill2=bill).exclude(bill1=bill): if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1)) return { 'bill': bill, "congressdates": get_congress_dates(bill.congress), "textdata": textdata, "version": version, "is_latest": is_latest, "alternates": alternates, "related_bills": related_bills, "days_old": (datetime.datetime.now().date() - bill.current_status_date).days, "is_on_bill_text_page": True, # for the header tabs }