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)
示例#2
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()

        save_authors(bill, bill_import.authors)
        save_subjects(bill, bill_import.subjects)

      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})