Ejemplo n.º 1
0
def index(request):
    blog_feed = cache.get("our_blog_feed")
    if not blog_feed:
        blog_feed = get_blog_items()[0:4]
        cache.set("our_blog_feed", blog_feed, 60 * 30)  # 30 min

    events_feed = cache.get("frontpage_events_feed")
    if not events_feed:
        events_feed = Feed.get_events_for([
            fn for fn in ("misc:activebills2", "misc:billsummaries",
                          "misc:allvotes")
            if Feed.objects.filter(feedname=fn).exists()
        ], 6)
        cache.set("frontpage_events_feed", events_feed, 60 * 15)  # 15 minutes

    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    return {
        'events': events_feed,
        'blog': blog_feed,
        'bill_subject_areas': bill_subject_areas,
    }
Ejemplo n.º 2
0
def index(request):
    # Fetch subject areas for drop-down.
    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    post_groups = []

    # Fetch our Medium posts for summaries and features.
    from website.models import MediumPost
    post_groups.append({
        "title":
        "What We're Watching",
        "posts":
        MediumPost.objects.order_by('-published')[0:3],
        "link":
        "/events/govtrack-insider",
        "link_text":
        "Subscribe to all GovTrack Insider articles",
    })

    # legislation coming up
    from django.db.models import F
    from django.conf import settings
    from bill.models import Bill
    dhg_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        docs_house_gov_postdate__gt=datetime.now() -
        timedelta(days=10)).filter(
            docs_house_gov_postdate__gt=F('current_status_date'))
    sfs_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        senate_floor_schedule_postdate__gt=datetime.now() -
        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 bill: -bill.proscore())
    if len(coming_up) > 0:
        post_groups.append({
            "title":
            "Legislation Coming Up",
            "posts": [{
                "image_url":
                bill.get_thumbnail_url_ex(),
                "title":
                bill.title,
                "url":
                bill.get_absolute_url(),
                "published":
                "week of " + bill.scheduled_consideration_date.strftime("%x"),
            } for bill in coming_up[0:3]],
            "link":
            "/congress/bills",
            "link_text":
            "View All",
        })

    # recent oversight topics
    from oversight.models import OversightTopic
    oversight_topics = OversightTopic.objects.filter(
        congress_end__gte=settings.CURRENT_CONGRESS).order_by('-updated')[0:3]
    if oversight_topics:
        post_groups.append({
            "title":
            "Congressional Oversight and Investigations",
            "posts": [{
                "title": topic.title,
                "url": topic.get_absolute_url(),
                "published": topic.post_date,
            } for topic in oversight_topics],
            "link":
            "/congress/oversight",
            "link_text":
            "View All",
        })

    # trending feeds
    trending_feeds = [
        Feed.objects.get(id=f) for f in Feed.get_trending_feeds()[0:6]
    ]
    if len(trending_feeds) > 0:
        post_groups.append({
            "title":
            "Trending",
            "posts": [{
                "title": feed.title,
                "url": feed.link,
            } for feed in trending_feeds]
        })

    from person.models import Person
    from vote.models import Vote
    return {
        # for the action area below the splash
        'bill_subject_areas': bill_subject_areas,

        # for the highlights blocks
        'post_groups': post_groups,
    }
Ejemplo n.º 3
0
def index(request):
    # Fetch subject areas for drop-down.
    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    posts = []

    # Fetch our Medium posts for summaries and features.
    from website.models import MediumPost
    medium_posts = MediumPost.objects.order_by('-published')[0:6]
    for m in medium_posts:
        m.type = "GovTrack Insider"
    posts.extend(medium_posts)

    # Fetch our blog posts for site news. This is an expensive
    # call but the page is cached in whole.
    blog_feed = list(get_blog_items())
    for p in blog_feed:
        p["type"] = "Site News"
    posts.extend(blog_feed)

    # Get some bills whose status recently changed, focusing on important bills
    # using the proscore. Draw from different time periods to get a mix of
    # bills that are both important and recent.
    from bill.models import Bill
    from datetime import datetime, timedelta
    from settings import CURRENT_CONGRESS
    from haystack.query import SearchQuerySet
    bills = set()
    for days in (1, 2, 3, 7, 14):
        sqs = SearchQuerySet().using("bill").filter(
            indexed_model_name__in=["Bill"],
            congress=CURRENT_CONGRESS,
            current_status_date__gt=datetime.now() -
            timedelta(days=days)).order_by('-proscore')[0:60]
        n1 = len(bills)
        sqs_bills = Bill.objects.select_related('oursummary').in_bulk(
            {sb.pk
             for sb in sqs})
        for sb in sqs:
            bill = sqs_bills[int(sb.pk)]
            if bill in bills: continue
            bills.add(bill)
            if len(bills) - n1 > 1: break
        if len(bills) == 60: break
    from bill.models import Bill
    for b in bills:
        snippet = b.current_status_description
        try:
            snippet = b.oursummary.plain_text
        except:
            pass  # no summary
        posts.append({
            "title":
            b.title,
            "published":
            datetime(b.current_status_date.year, b.current_status_date.month,
                     b.current_status_date.day),
            "date_has_no_time":
            True,
            "type":
            b.get_current_status_display(),
            "snippet":
            snippet,
            "url":
            b.get_absolute_url(),
            "image_url":
            b.get_thumbnail_url_ex(),
        })

    ## Get some legislative events, mixing across mutually exclusive feeds.
    #from events.templatetags.events_utils import render_event
    #for feed, count in (("misc:comingup", 2),):
    #    events_feed = Feed.get_events_for([feed], count)
    #    for evt in events_feed:
    #        r = render_event(evt, [])
    #        r["published"] = r["date"]
    #        r["snippet"] = r["body_text"]
    #        r["image_url"] = r.get("thumbnail_url")
    #        posts.append(r)

    # Sort.
    posts.sort(key=lambda p: p["published"]
               if isinstance(p, dict) else p.published,
               reverse=True)

    # Fix events that have time-less dates --- turn into a date instance
    # so rendering is correct (otherwise we get "midnight").
    for p in posts:
        if isinstance(p, dict) and p.get("date_has_no_time"):
            p["published"] = p["published"].date()

    return {
        'bill_subject_areas': bill_subject_areas,
        'posts': posts,
    }
Ejemplo n.º 4
0
def index(request):
    # Fetch subject areas for drop-down.
    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    post_groups = []

    # Fetch our Medium posts for summaries and features.
    from website.models import MediumPost
    post_groups.append({
        "title": "What We're Watching",
        "posts": MediumPost.objects.order_by('-published')[0:3],
        "link": "/events/govtrack-insider",
        "link_text": "Subscribe to all GovTrack Insider articles",
    })

    # legislation coming up
    from django.db.models import F
    from django.conf import settings
    from bill.models import Bill
    dhg_bills = Bill.objects.filter(congress=settings.CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.now() - timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
    sfs_bills = Bill.objects.filter(congress=settings.CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.now() - 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 bill : -bill.proscore())
    if len(coming_up) > 0:
        post_groups.append({
            "title": "Legislation Coming Up",
            "posts": [{
                "image_url": bill.get_thumbnail_url_ex(),
                "title": bill.title,
                "url": bill.get_absolute_url(),
                "published": "week of " + bill.scheduled_consideration_date.strftime("%x"),
            } for bill in coming_up[0:3]],
            "link": "/congress/bills",
            "link_text": "View All",
        })

    # recent oversight topics
    from oversight.models import OversightTopic
    oversight_topics = OversightTopic.objects.filter(congress_end__gte=settings.CURRENT_CONGRESS).order_by('-updated')[0:3]
    if oversight_topics:
        post_groups.append({
            "title": "Congressional Oversight and Investigations",
            "posts": [{
                "title": topic.title,
                "url": topic.get_absolute_url(),
                "published": topic.post_date,
            } for topic in oversight_topics],
            "link": "/congress/oversight",
            "link_text": "View All",
        })

    # trending feeds
    trending_feeds = [Feed.objects.get(id=f) for f in Feed.get_trending_feeds()[0:6]]
    if len(trending_feeds) > 0:
        post_groups.append({
            "title": "Trending",
            "posts": [{
                "title": feed.title,
                "url": feed.link,
            } for feed in trending_feeds
        ]})


    from person.models import Person
    from vote.models import Vote
    return {
        # for the splash
        'number_of_bills': Bill.objects.filter(congress=settings.CURRENT_CONGRESS).count(),
        'number_of_legislators': Person.objects.filter(roles__current=True).count(),
        'number_of_votes': Vote.objects.filter(created__year=datetime.now().year).count(),

        # for the action area below the splash
        'bill_subject_areas': bill_subject_areas,

        # for the highlights blocks
        'post_groups': post_groups,
        }
Ejemplo n.º 5
0
def index(request):
    # Fetch subject areas for drop-down.
    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    post_groups = []

    # Fetch our latest YouTube videos.
    post_groups.append({
        "title":
        "A Bill a Minute",
        "link":
        "https://www.youtube.com/govtrack",
        "link_text":
        "See all videos on YouTube",
        "posts": [
            {
                "url": "https://www.youtube.com/watch?v=" + video["videoId"],
                "title": video["title"],
                "snippet": video["description"],
                "published": video["publishedAt"],
                "image_url": video["thumbnails"]["medium"]["url"],
            } for video in get_youtube_videos("UCL1f7AGknZWFmXWv6bpJzXg",
                                              limit=3)
            [0:3]  # that's https://www.youtube.com/govtrack
        ]
    })

    # Fetch our Medium posts for summaries and features.
    from website.models import MediumPost
    post_groups.append({
        "title":
        "What We're Watching",
        "posts":
        MediumPost.objects.order_by('-published')[0:3],
        "link":
        "/events/govtrack-insider",
        "link_text":
        "Subscribe to all GovTrack Insider articles",
    })

    # legislation coming up
    from django.db.models import F
    from django.conf import settings
    from bill.models import Bill
    dhg_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        docs_house_gov_postdate__gt=datetime.now() -
        timedelta(days=10)).filter(
            docs_house_gov_postdate__gt=F('current_status_date'))
    sfs_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        senate_floor_schedule_postdate__gt=datetime.now() -
        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 bill: -bill.proscore())
    if len(coming_up) > 0:
        post_groups.append({
            "title":
            "Legislation Coming Up",
            "posts": [{
                "image_url":
                bill.get_thumbnail_url_ex(),
                "title":
                bill.title,
                "url":
                bill.get_absolute_url(),
                "published":
                "week of " + bill.scheduled_consideration_date.strftime("%x"),
            } for bill in coming_up[0:3]],
            "link":
            "/congress/bills",
            "link_text":
            "View All",
        })

    # trending feeds
    trending_feeds = [
        Feed.objects.get(id=f) for f in Feed.get_trending_feeds()[0:6]
    ]
    if len(trending_feeds) > 0:
        post_groups.append({
            "title":
            "Trending",
            "posts": [{
                "title": feed.title,
                "url": feed.link,
            } for feed in trending_feeds]
        })

    from person.models import Person
    from vote.models import Vote
    return {
        # for the action area below the splash
        'bill_subject_areas': bill_subject_areas,

        # for the highlights blocks
        'post_groups': post_groups,
    }
Ejemplo n.º 6
0
def index(request):
    # Fetch subject areas for drop-down.
    from bill.views import subject_choices
    bill_subject_areas = subject_choices()

    post_groups = []
    MAX_PER_GROUP = 3

    # Trending feeds. These are short (no image, no snippet) so they go first.
    trending_feeds = [
        Feed.objects.get(id=f) for f in Feed.get_trending_feeds()[0:6]
    ]
    if len(trending_feeds) > 0:
        post_groups.append({
            "title":
            "Trending",
            "posts": [{
                "title": feed.title,
                "url": feed.link,
            } for feed in trending_feeds],
            "compact":
            True
        })

    # Fetch our latest Medium posts and YouTube videos. Since we publish them in the same
    # work cycle, we can intermix and expect the most recent few to alternate between them.
    # But we only get one link at the bottom.
    from website.models import MediumPost
    post_groups.append({
        "title":
        "What We’re Watching",
        "links":
        [("/events/govtrack-insider",
          "Subscribe to all GovTrack Insider articles"),
         ("https://www.youtube.com/govtrack", "See all videos on YouTube")],
        "posts":
        list(MediumPost.objects.order_by('-published')[0:MAX_PER_GROUP]) + [
            {
                "url":
                "https://www.youtube.com/watch?v=" + video["videoId"],
                "title":
                video["title"].replace("GovTrack A Bill A Minute: ",
                                       "").replace("&",
                                                   "&"),  # !, snippet too?
                "snippet":
                video["description"],
                "published":
                datetime.strptime(video["publishedAt"], '%Y-%m-%dT%H:%M:%SZ'),
                "image_url":
                video["thumbnails"]["medium"]["url"],
            } for video in get_youtube_videos(
                "UCL1f7AGknZWFmXWv6bpJzXg",
                limit=MAX_PER_GROUP)  # that's https://www.youtube.com/govtrack
        ]
    })
    post_groups[-1]["posts"].sort(key=lambda p: p["published"]
                                  if isinstance(p, dict) else p.published,
                                  reverse=True)

    # Legislation coming up. Sadly this is usually the least interesting.
    from django.db.models import F
    from django.conf import settings
    from bill.models import Bill
    dhg_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        docs_house_gov_postdate__gt=datetime.now() -
        timedelta(days=10)).filter(
            docs_house_gov_postdate__gt=F('current_status_date'))
    sfs_bills = Bill.objects.filter(
        congress=settings.CURRENT_CONGRESS,
        senate_floor_schedule_postdate__gt=datetime.now() -
        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 bill: -bill.proscore())
    if len(coming_up) > 0:
        post_groups.append({
            "title":
            "Legislation Coming Up",
            "posts": [{
                "image_url":
                bill.get_thumbnail_url_ex(),
                "title":
                bill.title,
                "url":
                bill.get_absolute_url(),
                "published":
                "week of " + bill.scheduled_consideration_date.strftime("%x"),
            } for bill in coming_up[0:6]],
            "links": [("/congress/bills", "View All")],
        })

    from person.models import Person
    from vote.models import Vote
    return {
        # for the action area below the splash
        'bill_subject_areas': bill_subject_areas,

        # for the highlights blocks
        'post_groups': post_groups,
    }