示例#1
0
def bill(request, bill_id):
  try:
    bill = Bill.objects.get(id = bill_id)
  except Bill.DoesNotExist:
    raise Http404
  # annotation_list = bill.annotation_set.all()
  bill.text = text_frontend(bill.text)
  authors = Bill.deserialize(bill.authors)
  subjects = Bill.deserialize(bill.subjects)
  context = {'bill': bill, 'authors': authors, 'subjects': subjects }#, 'annotation_list': annotation_list}
  return render(request, 'bill_future.html', context)
示例#2
0
def add_bill(request):
  if request.method == 'POST':
    form = BillForm(request.POST)
    if form.is_valid():
      data = form.cleaned_data
      bill = Bill()
      bill.number = data['number']
      bill_txt = get_bill_text(str(bill.number))
      if (bill_txt == None):
        return "Invalid bill number."
      else:
        bill.text = bill_txt
      bill.save()
      return HttpResponseRedirect("/index/")
  else:
    form = BillForm()
  return render(request, 'addbill.html', {'form': form})
示例#3
0
def create(request):
  from annotation_app.forms import BillForm

  form = BillForm(request.POST)

  if form.is_valid():
    data = form.cleaned_data
    bill = Bill.objects.filter(chamber_origin = data['chamber_origin'],
      number = data['number'])

    # If you find bill in the database, it is the first element in QuerySet
    if bill:
      bill = bill[0]
    # If bill is not in the database, pull it from TLO website
    else:
      from annotation_app.helpers.bill_scrapers import scrape_bill_text

      bill_text = scrape_bill_text(data)
      if bill_text == None:
        return HttpResponseRedirect('/')

      bill = Bill()
      bill.session = data['session']
      bill.chamber_origin = data['chamber_origin']
      bill.number = data['number']
      bill.text = bill_text

      from annotation_app.helpers.htmllogic import htmltext
      bill.text = htmltext(bill.text)
      bill.save()

    if 'format' in request.POST:
      return HttpResponse(serializers.serialize(request.POST['format'],
        [bill]))
    else:
      return HttpResponseRedirect('/bills/%sB%d/' % (bill.chamber_origin,
        bill.number))

  else:
    return HttpResponseRedirect('/')
def save_bill(number, chamber_origin, session):
	bill = Bill()
	bill.number = number
	bill.chamber_origin = chamber_origin
	bill.session = session
	bill_import = Bill_Import_Call(number)
	bill_list = bill_import.billtext
	bill.text = Bill.serialize(bill_list)
	bill.authors = Bill.serialize(bill_import.authors)
	bill.coauthors = Bill.serialize(bill_import.coauthors)
	bill.subjects = Bill.serialize(bill_import.subjects)
	bill.cosponsors = Bill.serialize(bill_import.cosponsors)
	bill.sponsors = Bill.serialize(bill_import.sponsors)
	bill.save()
	save_authors(bill, bill_import.authors)
	save_subjects(bill, bill_import.subjects)
	return(bill)
示例#5
0
def add_bill(request):
  if request.method == 'POST':
    form = BillForm(request.POST)

    if form.is_valid():
      data = form.cleaned_data
      bill_num = data["number"]
      bill = Bill.objects.filter(number=bill_num)
      # If you find bill in the database, it is the first element in QuerySet
      if bill:
          bill = bill[0]
      # If bill is not in the database, pull it from TLO website
      if not bill:
        data = form.cleaned_data
        bill = Bill()
        bill.number = data['number']
        bill_import = Bill_Import()
        bill_import.set_bill_num(str(bill.number))
        bill_import.pull_billtext()
        bill_list = bill_import.billtext
        bill.text = Bill.serialize(bill_list)
        bill_import.pull_history()
        bill_import.set_data()
        bill.authors = Bill.serialize(bill_import.authors)
        bill.coauthors = Bill.serialize(bill_import.coauthors)
        bill.subjects = Bill.serialize(bill_import.subjects)
        bill.cosponsors = Bill.serialize(bill_import.cosponsors)
        bill.sponsors = Bill.serialize(bill_import.sponsors)
        bill.save()

      if 'format' in request.POST:
        return HttpResponse(serializers.serialize(request.POST['format'],
          [bill]))
      else:
        return HttpResponseRedirect('/bills/%d/' % bill.id)
  else:
    form = BillForm()
  return render(request, 'addbill.html', {'form': form})