コード例 #1
0
ファイル: views.py プロジェクト: solheng/govtrack.us-web
def export_panel_user_data(request, panel_id, download):
    import csv, io
    from django.utils.text import slugify
    from website.models import UserPosition
    from bill.models import Bill
    from events.models import Feed

    panel = get_object_or_404(Panel, id=panel_id, admins=request.user)

    buf = io.BytesIO()
    w = csv.writer(buf)

    if download == "members":
        # Download the panel's membership, with one row per member.
        w.writerow(["id", "email", "joined", "invitation_code", "notes"])
        for mbr in PanelMembership.objects.filter(
                panel=panel).order_by('created').select_related("user"):
            w.writerow([
                mbr.id,
                mbr.user.email,
                mbr.created,
                mbr.invitation_code,
                mbr.extra.get("notes", ""),
            ])
    elif download == "positions":
        # Download the positions panel members have taken on legislation,
        # with one row per member-position.
        members = dict(
            PanelMembership.objects.filter(panel=panel).values_list(
                "user_id", "id"))
        w.writerow([
            "position_id", "member_id", "member_email", "position_created",
            "bill_id", "bill_title", "bill_link", "likert_score", "reason_text"
        ])
        for upos in UserPosition.objects.filter(user__in=members)\
            .order_by('created')\
            .select_related("user"):
            w.writerow([
                upos.id,
                members[upos.user.id],
                upos.user.email,
                upos.created,
                Bill.from_feed(Feed.from_name(
                    upos.subject)).congressproject_id,
                upos.get_subject_title().encode("utf8"),
                "https://www.govtrack.us" + upos.get_subject_link(),
                upos.likert,
                upos.reason.encode("utf8"),
            ])
    else:
        return HttpResponse("invalid")

    ret = HttpResponse(buf.getvalue())
    if True:  # disable to make debugging easier
        ret["Content-Type"] = "text/csv"
        ret["Content-Disposition"] = "attachment;filename=%s_%s.csv" % (
            slugify(panel.title), download)
    else:
        ret["Content-Type"] = "text/plain"
    return ret
コード例 #2
0
    def build_info():
        # feeds about all legislation that we offer the user to subscribe to
        feeds = [
            f for f in Feed.get_simple_feeds() if f.category == "federal-bills"
        ]

        # info about bills by status
        groups = [
            (
                g[0],  # title
                g[1],  # text 1
                g[2],  # text 2
                "/congress/bills/browse?status=" +
                ",".join(str(s)
                         for s in g[4]) + "&sort=-current_status_date",  # link
                load_bill_status_qs(g[4]).count(),  # count in category
                load_bill_status_qs(g[4]).order_by(
                    '-current_status_date')[0:6],  # top 6 in this category
            ) for g in bill_status_groups
        ]

        # legislation coming up
        dhg_bills = Bill.objects.filter(
            congress=CURRENT_CONGRESS,
            docs_house_gov_postdate__gt=datetime.datetime.now() -
            datetime.timedelta(days=10)).filter(
                docs_house_gov_postdate__gt=F('current_status_date'))
        sfs_bills = Bill.objects.filter(
            congress=CURRENT_CONGRESS,
            senate_floor_schedule_postdate__gt=datetime.datetime.now() -
            datetime.timedelta(days=5)).filter(
                senate_floor_schedule_postdate__gt=F('current_status_date'))
        coming_up = list(
            (dhg_bills | sfs_bills).order_by('scheduled_consideration_date'))

        # top tracked bills
        top_bills = Feed.objects\
            .filter(feedname__startswith='bill:')\
            .filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
        top_bills = top_bills\
            .annotate(count=Count('tracked_in_lists'))\
            .order_by('-count')\
            .values('feedname', 'count')\
            [0:25]
        top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])),
                      bf["count"]) for bf in top_bills]

        return {
            "feeds": feeds,
            "total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
            "current_congress": CURRENT_CONGRESS,
            "current_congress_dates": get_congress_dates(CURRENT_CONGRESS),
            "groups": groups,
            "coming_up": coming_up,
            "top_tracked_bills": top_bills,
            "subjects": subject_choices(),
            "BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.reported),
        }
コード例 #3
0
ファイル: views.py プロジェクト: govtrack/govtrack.us-web
def export_panel_user_data(request, panel_id, download):
    import csv, io
    from django.utils.text import slugify
    from website.models import UserPosition
    from bill.models import Bill
    from events.models import Feed

    panel = get_object_or_404(Panel, id=panel_id, admins=request.user)

    buf = io.StringIO()
    w = csv.writer(buf)

    if download == "members":
        # Download the panel's membership, with one row per member.
        w.writerow(["id", "email", "joined", "invitation_code", "notes"])
        for mbr in PanelMembership.objects.filter(panel=panel).order_by('created').select_related("user"):
            w.writerow([
                str(mbr.id),
                mbr.user.email,
                mbr.created.isoformat(),
                mbr.invitation_code,
                mbr.extra.get("notes", ""),
            ])
    elif download == "positions":
        # Download the positions panel members have taken on legislation,
        # with one row per member-position.
        members = dict(PanelMembership.objects.filter(panel=panel).values_list("user_id", "id"))
        w.writerow(["position_id", "member_id", "member_email", "position_created", "bill_id", "bill_title", "bill_link", "likert_score", "reason_text"])
        for upos in UserPosition.objects.filter(user__in=members)\
            .order_by('created')\
            .select_related("user"):
            w.writerow([
                str(upos.id),
                members[upos.user.id],
                upos.user.email,
                upos.created.isoformat(),
                Bill.from_feed(Feed.from_name(upos.subject)).congressproject_id,
                upos.get_subject_title(),
                "https://www.govtrack.us" + upos.get_subject_link(),
                str(upos.likert),
                upos.reason,
            ])
    else:
        return HttpResponse("invalid")
    
    ret = HttpResponse(buf.getvalue())
    if True: # disable to make debugging easier
        ret["Content-Type"] = "text/csv"
        ret["Content-Disposition"] = "attachment;filename=%s_%s.csv" % (
            slugify(panel.title),
            download
        )
    else:
        ret["Content-Type"] = "text/plain"
    return ret
コード例 #4
0
ファイル: views.py プロジェクト: marcelor/govtrack.us-web
    def build_info():
        # feeds about all legislation that we offer the user to subscribe to
        feeds = [f for f in Feed.get_simple_feeds() if f.category == "federal-bills"]

        # info about bills by status
        groups = [
            (   g[0], # title
                g[1], # text 1
                g[2], # text 2
                "/congress/bills/browse?status=" + ",".join(str(s) for s in g[4]) + "&sort=-current_status_date", # link
               load_bill_status_qs(g[4]).count(), # count in category
               load_bill_status_qs(g[4]).order_by('-current_status_date')[0:6], # top 6 in this category
                )
            for g in bill_status_groups ]

        # legislation coming up
        dhg_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
        sfs_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=5)).filter(senate_floor_schedule_postdate__gt=F('current_status_date'))
        coming_up = list(dhg_bills | sfs_bills)
        coming_up.sort(key = lambda b : b.docs_house_gov_postdate if (b.docs_house_gov_postdate and (not b.senate_floor_schedule_postdate or b.senate_floor_schedule_postdate < b.docs_house_gov_postdate)) else b.senate_floor_schedule_postdate, reverse=True)

        # top tracked bills
        top_bills = Feed.objects\
            .filter(feedname__startswith='bill:')\
            .filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
        top_bills = top_bills\
            .annotate(count=Count('tracked_in_lists'))\
            .order_by('-count')\
            .values('feedname', 'count')\
            [0:25]
        top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])), bf["count"]) for bf in top_bills]

        # current congrss years
        start, end = get_congress_dates(CURRENT_CONGRESS)
        end_year = end.year if end.month > 1 else end.year-1 # count January finishes as the prev year
        current_congress_years = '%d-%d' % (start.year, end.year)
        current_congress = ordinal(CURRENT_CONGRESS)

        return {
            "feeds": feeds,

            "total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
            "current_congress_years": current_congress_years,
            "current_congress": current_congress,

            "groups": groups,
            "coming_up": coming_up,
            "top_tracked_bills": top_bills,

            "subjects": subject_choices(),
            "BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.referred, BillStatus.reported),
        }
コード例 #5
0
ファイル: views.py プロジェクト: govtrack/govtrack.us-web
    def build_info():
        # feeds about all legislation that we offer the user to subscribe to
        feeds = [f for f in Feed.get_simple_feeds() if f.category == "federal-bills"]

        # info about bills by status
        groups = [
            (   g[0], # title
                g[1], # text 1
                g[2], # text 2
                "/congress/bills/browse?status=" + ",".join(str(s) for s in g[4]) + "&sort=-current_status_date", # link
               load_bill_status_qs(g[4]).count(), # count in category
               load_bill_status_qs(g[4]).order_by('-current_status_date')[0:6], # top 6 in this category
                )
            for g in bill_status_groups ]

        # legislation coming up
        dhg_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
        sfs_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=5)).filter(senate_floor_schedule_postdate__gt=F('current_status_date'))
        coming_up = list((dhg_bills | sfs_bills).order_by('scheduled_consideration_date'))

        # top tracked bills
        top_bills = Feed.objects\
            .filter(feedname__startswith='bill:')\
            .filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
        top_bills = top_bills\
            .annotate(count=Count('tracked_in_lists'))\
            .order_by('-count')\
            .values('feedname', 'count')\
            [0:25]
        top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])), bf["count"]) for bf in top_bills]

        # trending bills
        trf = Feed.get_trending_feeds()
        trf = [Feed.objects.get(id=f) for f in trf]
        trending_bill_feeds = [f for f in trf if f.feedname.startswith("bill:")]

        return {
            "feeds": feeds,

            "total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
            "current_congress": CURRENT_CONGRESS,
            "current_congress_dates": get_congress_dates(CURRENT_CONGRESS),

            "groups": groups,
            "coming_up": coming_up,
            "top_tracked_bills": top_bills,
            "trending_bill_feeds": trending_bill_feeds,

            "subjects": subject_choices(),
            "BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.reported),
        }
コード例 #6
0
ファイル: views.py プロジェクト: jaythaceo/govtrack.us-web
def your_docket(request):
    from bill.models import Bill
    # Pre-load the user's subscription lists and for each list
    # pre-load the list of bills entered into the list.
    lists = []
    if request.user.is_authenticated():
        lists = request.user.subscription_lists.all()
        for lst in lists:
            lst.bills = []
            for trk in lst.trackers.all():
                try:
                    lst.bills.append( Bill.from_feed(trk) )
                except ValueError:
                    pass
    return { "lists": lists }
コード例 #7
0
ファイル: views.py プロジェクト: amyewest/govtrack.us-web
def your_docket(request):
    from bill.models import Bill
    # Pre-load the user's subscription lists and for each list
    # pre-load the list of bills entered into the list.
    lists = []
    if request.user.is_authenticated:
        lists = request.user.subscription_lists.all()
        for lst in lists:
            lst.bills = []
            for trk in lst.trackers.all():
                try:
                    lst.bills.append(Bill.from_feed(trk))
                except ValueError:
                    pass
    return {"lists": lists}
コード例 #8
0
	def show_stats(self, recent_users_only):
		# get feeds, across all congresses
		top_bills = Feed.objects\
			.filter(feedname__startswith='bill:')\
			.filter(feedname__regex='^bill:[hs][jcr]?%d-' % settings.CURRENT_CONGRESS)
		if recent_users_only:
			top_bills = top_bills.filter(tracked_in_lists__user__date_joined__gt=datetime.datetime.now()-datetime.timedelta(days=14))
		top_bills = top_bills\
			.annotate(count=Count('tracked_in_lists'))\
			.order_by('-count')\
			.values('feedname', 'count')\
			[0:25]

		print "new users \t all users \t sponsor \t url \t bill title"
		for bf in top_bills:
			f = Feed.from_name(bf["feedname"])
			b = Bill.from_feed(f)
			print bf["count"], "\t", f.tracked_in_lists.all().count(), "\t", b.sponsor.lastname, b.get_absolute_url(), "\t", b
コード例 #9
0
	def show_stats(self, recent_users_only):
		# get feeds, across all congresses
		top_bills = Feed.objects\
			.filter(feedname__startswith='bill:')\
			.filter(feedname__regex='^bill:[hs][jcr]?%d-' % settings.CURRENT_CONGRESS)
		if recent_users_only:
			top_bills = top_bills.filter(tracked_in_lists__user__date_joined__gt=datetime.datetime.now()-datetime.timedelta(days=14))
		top_bills = top_bills\
			.annotate(count=Count('tracked_in_lists'))\
			.order_by('-count')\
			.values('feedname', 'count')\
			[0:25]

		print("new users \t all users \t sponsor \t url \t bill title")
		for bf in top_bills:
			f = Feed.from_name(bf["feedname"])
			b = Bill.from_feed(f)
			print(bf["count"], "\t", f.tracked_in_lists.all().count(), "\t", b.sponsor.lastname.encode("utf8"), b.get_absolute_url(), "\t", b)
コード例 #10
0
    def build_info():
        # feeds about all legislation that we offer the user to subscribe to
        feeds = [
            f for f in Feed.get_simple_feeds() if f.category == "federal-bills"
        ]

        # info about bills by status
        groups = [
            (
                g[0],  # title
                g[1],  # text 1
                g[2],  # text 2
                "/congress/bills/browse?status=" +
                ",".join(str(s)
                         for s in g[4]) + "&sort=-current_status_date",  # link
                load_bill_status_qs(g[4]).count(),  # count in category
                load_bill_status_qs(g[4]).order_by(
                    '-current_status_date')[0:6],  # top 6 in this category
            ) for g in bill_status_groups
        ]

        # legislation coming up
        dhg_bills = Bill.objects.filter(
            congress=CURRENT_CONGRESS,
            docs_house_gov_postdate__gt=datetime.datetime.now() -
            datetime.timedelta(days=10)).filter(
                docs_house_gov_postdate__gt=F('current_status_date'))
        sfs_bills = Bill.objects.filter(
            congress=CURRENT_CONGRESS,
            senate_floor_schedule_postdate__gt=datetime.datetime.now() -
            datetime.timedelta(days=5)).filter(
                senate_floor_schedule_postdate__gt=F('current_status_date'))
        coming_up = list(dhg_bills | sfs_bills)
        coming_up.sort(
            key=lambda b: b.docs_house_gov_postdate
            if (b.docs_house_gov_postdate and
                (not b.senate_floor_schedule_postdate or b.
                 senate_floor_schedule_postdate < b.docs_house_gov_postdate))
            else b.senate_floor_schedule_postdate,
            reverse=True)

        # top tracked bills
        top_bills = Feed.objects\
            .filter(feedname__startswith='bill:')\
            .filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
        top_bills = top_bills\
            .annotate(count=Count('tracked_in_lists'))\
            .order_by('-count')\
            .values('feedname', 'count')\
            [0:25]
        top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])),
                      bf["count"]) for bf in top_bills]

        # current congrss years
        start, end = get_congress_dates(CURRENT_CONGRESS)
        end_year = end.year if end.month > 1 else end.year - 1  # count January finishes as the prev year
        current_congress_years = '%d-%d' % (start.year, end.year)
        current_congress = ordinal(CURRENT_CONGRESS)

        return {
            "feeds":
            feeds,
            "total":
            Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
            "current_congress_years":
            current_congress_years,
            "current_congress":
            current_congress,
            "groups":
            groups,
            "coming_up":
            coming_up,
            "top_tracked_bills":
            top_bills,
            "subjects":
            subject_choices(),
            "BILL_STATUS_INTRO":
            (BillStatus.introduced, BillStatus.referred, BillStatus.reported),
        }