示例#1
0
def _get_session(term, session):
    """wrapper around number_to_session(term, session)
    so that it raises a Http404 for invalid session|term
    """
    try:
        session = number_to_leg(term, session)
    except AttributeError:
        raise Http404('Invalid Legislative Session')
    return session
示例#2
0
def bill_overview(request, term, session, bill_number):
    """
    Individual Bill Detail shows sponsors, versions, actions(past and pending)
    with a link to show text and comments and also an option to view the Arizona
    Statues that this legislation affects when applicable
    """
    session = number_to_leg(term, session)

    bill = get_object_or_404(Bill, number=bill_number, session__name=session)
    # TODO replace this with real analytics
    bill.page_views_count += 1
    page_view, c = bill.page_views.get_or_create(date=datetime.date.today())
    page_view.views += 1
    page_view.save()
    bill.save()

    ###################################
    # Basic Bill Information
    ###################################
    c = {}
    c['title'] = "%s - %s" % (bill.number, bill.title)
    c['bill'] = bill
    # just need the name and document_id or each summary
    # sorting by date should be replaced by date added for the new session
    # need to make it so that the user can select a summary to read
    c['summaries'] = bill.documents.filter(doc_type="summary")
    if 'summary' in request.GET and request.GET['summary']:
        pass
    for summary in c['summaries']:
        if summary.doc_id:
            c['text'] = get_summary(summary)
            break
    else:
        c['text'] = ''
    
    c['sponsors'] = Sponsor.objects.filter(bill=bill).order_by('type')
    c['chamber'] = {'upper': 'Senate', 'lower': 'House'}[bill.chamber]
    c['other_chamber'] = {'upper': 'House', 'lower': 'Senate'}[bill.chamber]
    try:
        c['latest_action'] = bill.actions.latest()
    except ObjectDoesNotExist:
        c['latest_action'] = None
    c['latest_action'] = _render_action_description(c['latest_action'], bill)

    ###################################
    # Charts and User Actions
    ###################################
    actions = bill.actions.all().order_by('order')
    simi = []
    for act in actions:
        action = {}
        action['start'] = act.date.strftime('%Y %m %d')
        action['title'] = act.action
        action['description'] = act.action
        simi.append(action)
    c['actions'] = actions
    c['graph_actions'] = json.dumps(simi)
    c['bill_graph'] = json.dumps(bill.get_bill_stats())
    c['support'] = json.dumps(bill.get_user_support())
    c['tracker_form'] = AddTrackerShortForm(
            initial={'object_id': bill.id,
                     'content_type': ContentType.objects.get(model="bill").id,
                     'where_to': request.get_full_path()}
            )
    ###################################
    # bill tracking
    ###################################
    if request.user.is_authenticated():
        tracked = request.user.profile.is_tracking(bill.id)
        if tracked:
            c['is_tracking'] = True
    elif 'trackers' in request.COOKIES:
        if bill.id in request.COOKIES['trackers']:
            c['is_tracking'] = True
    return render_to_response('bill.html', RequestContext(request, c))