当前位置: 首页>>代码示例>>Python>>正文


Python Metadata.get_object方法代码示例

本文整理汇总了Python中billy.models.Metadata.get_object方法的典型用法代码示例。如果您正苦于以下问题:Python Metadata.get_object方法的具体用法?Python Metadata.get_object怎么用?Python Metadata.get_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在billy.models.Metadata的用法示例。


在下文中一共展示了Metadata.get_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: event

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def event(request, abbr, event_id):
    event = db.events.find_one({'_id': event_id})
    if event is None:
        raise Http404

    fmt = "%Y%m%dT%H%M%SZ"

    start_date = event['when'].strftime(fmt)
    duration = dt.timedelta(hours=1)
    ed = (event['when'] + duration)
    end_date = ed.strftime(fmt)

    gcal_info = {
        "action": "TEMPLATE",
        "text": event['description'],
        "dates": "%s/%s" % (start_date, end_date),
        "details": "",
        "location": event['location'].encode('utf-8'),
        "trp": "false",
        "sprop": "http://openstates.org/%s/events/%s/" % (
            abbr,
            event_id
        ),
        "sprop": "name:Open States Event"
    }
    gcal_string = urllib.urlencode(gcal_info)

    return render(request, templatename('event'),
                  dict(abbr=abbr,
                       metadata=Metadata.get_object(abbr),
                       event=event,
                       sources=event['sources'],
                       gcal_info=gcal_info,
                       gcal_string=gcal_string,
                       statenav_active='events'))
开发者ID:JT5D,项目名称:billy,代码行数:37,代码来源:events.py

示例2: committee

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def committee(request, abbr, committee_id):
    '''
    Context:
        - committee
        - abbr
        - metadata
        - sources
        - nav_active
        - events

    Tempaltes:
        - billy/web/public/committee.html
        - billy/web/public/developer_committee.html
    '''
    committee = db.committees.find_one({'_id': committee_id})
    if committee is None:
        raise Http404

    events = db.events.find({
        settings.LEVEL_FIELD: abbr,
        "participants.id": committee_id
    }).sort("when", -1)
    events = list(events)
    if len(events) > EVENT_PAGE_COUNT:
        events = events[:EVENT_PAGE_COUNT]

    popularity.counter.inc('committees', committee_id, abbr=abbr)

    return render(request, templatename('committee'),
                  dict(committee=committee, abbr=abbr,
                       metadata=Metadata.get_object(abbr),
                       sources=committee['sources'],
                       nav_active='committees',
                       events=events))
开发者ID:rhymeswithcycle,项目名称:billy,代码行数:36,代码来源:committees.py

示例3: recent_actions

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def recent_actions(abbr):
    state = Metadata.get_object(abbr)
    bills = state.bills({'session': state.most_recent_session,
                         '$or': [{'actions.type': 'bill:passed'},
                                 {'actions.type': 'bill:introduced'}],
                         'type': 'bill'})
    bills_by_action = defaultdict(list)
    for bill in bills:
        for action in bill['actions']:
            actor = re.search(r'(upper|lower)', action['actor'])
            if actor:
                actor = actor.group()
            else:
                continue
            for type_ in action['type']:
                if type_ in ['bill:passed', 'bill:introduced']:
                    bills_by_action[(type_, actor)].append(
                                            (action['date'], bill))

    def f(type_, chamber):
        bills = list(sorted(bills_by_action[(type_, chamber)],
                     reverse=True, key=itemgetter(0)))[:2]
        return map(itemgetter(1), bills)

    res = dict(
        passed_upper=f('bill:passed', 'upper'),
        passed_lower=f('bill:passed', 'lower'),
        introduced_upper=f('bill:introduced', 'upper'),
        introduced_lower=f('bill:introduced', 'lower'))

    return res
开发者ID:msabramo,项目名称:billy,代码行数:33,代码来源:overview.py

示例4: events

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def events(request, abbr):
    year = request.GET.get("year")
    month = request.GET.get("month")
    if year and month:
        if month == "0":
            month = 1

        month = int(month)
        display_date = datetime.datetime(year=int(year), month=month, day=1)
    else:
        display_date = datetime.datetime.now()

    # Compensate for js dates.
    events = _get_events(abbr, display_date.year, display_date.month - 1)
    return TemplateResponse(
        request,
        templatename("events"),
        dict(
            abbr=abbr,
            display_date=display_date,
            metadata=Metadata.get_object(abbr),
            events=events,
            event_template=templatename("_event"),
            events_list_template=templatename("events-pjax"),
            nav_active="events",
        ),
    )
开发者ID:dmc2015,项目名称:billy,代码行数:29,代码来源:events.py

示例5: bill

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def bill(request, abbr, session, bill_id):
    # get fixed version
    fixed_bill_id = fix_bill_id(bill_id)
    # redirect if URL's id isn't fixed id without spaces
    if fixed_bill_id.replace(' ', '') != bill_id:
        return redirect('bill', abbr=abbr, session=session,
                        bill_id=fixed_bill_id.replace(' ', ''))
    bill = db.bills.find_one({'state': abbr, 'session': session,
                              'bill_id': fixed_bill_id})
    if bill is None:
        raise Http404('no bill found {0} {1} {2}'.format(abbr, session,
                                                         bill_id))

    events = db.events.find({
        "state": abbr,
        "related_bills.bill_id": bill['_id']
    }).sort("when", -1)

    popularity.counter.inc('bills', bill['_id'], abbr=abbr, session=session)

    show_all_sponsors = request.GET.get('show_all_sponsors')
    if show_all_sponsors:
        sponsors = bill.sponsors_manager
    else:
        sponsors = bill.sponsors_manager.first_fifteen
    return render(request, templatename('bill'),
        dict(vote_preview_row_template=templatename('vote_preview_row'),
             abbr=abbr,
             metadata=Metadata.get_object(abbr),
             bill=bill,
             events=events,
             show_all_sponsors=show_all_sponsors,
             sponsors=sponsors,
             sources=bill['sources'],
             statenav_active='bills'))
开发者ID:JT5D,项目名称:billy,代码行数:37,代码来源:bills.py

示例6: state_not_active_yet

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def state_not_active_yet(request, args, kwargs):
    return render_to_response(
        template_name=templatename('state_not_active_yet'),
        dictionary=dict(
            metadata=Metadata.get_object(kwargs['abbr']),
            statenav_active=None),
        context_instance=RequestContext(request, default_context))
开发者ID:msabramo,项目名称:billy,代码行数:9,代码来源:views.py

示例7: bill

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def bill(request, abbr, session, bill_id):
    '''
    Context:
        - vote_preview_row_template
        - abbr
        - metadata
        - bill
        - events
        - show_all_sponsors
        - sponsors
        - sources
        - nav_active

    Templates:
        - billy/web/public/bill.html
        - billy/web/public/vote_preview_row.html
    '''
    # get fixed version
    fixed_bill_id = fix_bill_id(bill_id)
    # redirect if URL's id isn't fixed id without spaces
    if fixed_bill_id.replace(' ', '') != bill_id:
        return redirect('bill',
                        abbr=abbr,
                        session=session,
                        bill_id=fixed_bill_id.replace(' ', ''))
    _bill = db.bills.find_one({settings.LEVEL_FIELD: abbr, 'session': session,
                              'bill_id': fixed_bill_id})
    if _bill is None:
        raise Http404(
            u'no bill found {0} {1} {2}'.format(abbr, session, bill_id))

    events = db.events.find({
        settings.LEVEL_FIELD: abbr,
        "related_bills.bill_id": _bill['_id']
    }).sort("when", -1)
    events = list(events)
    if len(events) > EVENT_PAGE_COUNT:
        events = events[:EVENT_PAGE_COUNT]

    popularity.counter.inc('bills',
                           _bill['_id'], abbr=abbr, session=session)

    show_all_sponsors = request.GET.get('show_all_sponsors')
    if show_all_sponsors:
        sponsors = _bill.sponsors_manager
    else:
        sponsors = _bill.sponsors_manager.first_fifteen

    return render(
        request, templatename('bill'),
        dict(vote_preview_row_template=templatename('vote_preview_row'),
             abbr=abbr,
             metadata=Metadata.get_object(abbr),
             bill=_bill,
             events=events,
             show_all_sponsors=show_all_sponsors,
             sponsors=sponsors,
             sources=_bill['sources'],
             nav_active='bills'))
开发者ID:jmdupont,项目名称:billy,代码行数:61,代码来源:bills.py

示例8: not_active_yet

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def not_active_yet(request, args, kwargs):
    try:
        metadata = Metadata.get_object(kwargs['abbr'])
    except DoesNotExist:
        raise Http404

    return render(request, templatename('state_not_active_yet'),
                  dict(metadata=metadata, statenav_active=None))
开发者ID:JT5D,项目名称:billy,代码行数:10,代码来源:region.py

示例9: state

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def state(request, abbr):
    report = db.reports.find_one({'_id': abbr})
    try:
        meta = Metadata.get_object(abbr)
    except DoesNotExist:
        raise Http404

    # count legislators
    legislators = meta.legislators({'active': True}, {'party': True,
                                                      'chamber': True})
    # Maybe later, mapreduce instead?
    party_counts = defaultdict(lambda: defaultdict(int))
    for leg in legislators:
        if 'chamber' in leg: # if statement to exclude lt. governors
            party_counts[leg['chamber']][leg['party']] += 1

    chambers = []

    for chamber in ('upper', 'lower'):
        res = {}

        # chamber metadata
        res['type'] = chamber
        res['title'] = meta[chamber + '_chamber_title']
        res['name'] = meta[chamber + '_chamber_name']

        # legislators
        res['legislators'] = {
            'count': sum(party_counts[chamber].values()),
            'party_counts': dict(party_counts[chamber]),
        }

        # committees
        res['committees_count'] = meta.committees({'chamber': chamber}).count()

        res['latest_bills'] = meta.bills({'chamber': chamber}).sort([('action_dates.first', -1)]).limit(2)
        res['passed_bills'] = meta.bills({'chamber': chamber}).sort([('action_dates.passed_' + chamber, -1)]).limit(2)

        chambers.append(res)

    joint_committee_count = meta.committees({'chamber': 'joint'}).count()

    # add bill counts to session listing
    sessions = meta.sessions()
    for s in sessions:
        try:
            s['bill_count'] = (
                report['bills']['sessions'][s['id']]['upper_count']
                + report['bills']['sessions'][s['id']]['lower_count'])
        except KeyError:
            # there's a chance that the session had no bills
            s['bill_count'] = 0

    return render(request, templatename('state'),
                  dict(abbr=abbr, metadata=meta, sessions=sessions,
                       chambers=chambers,
                       joint_committee_count=joint_committee_count,
                       statenav_active='home'))
开发者ID:annerajb,项目名称:billy,代码行数:60,代码来源:region.py

示例10: event

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def event(request, abbr, event_id):
    event = db.events.find_one({'_id': event_id})
    if event is None:
        raise Http404

    return render(request, templatename('event'),
                  dict(abbr=abbr, metadata=Metadata.get_object(abbr),
                       event=event, sources=event['sources'],
                       statenav_active='events'))
开发者ID:annerajb,项目名称:billy,代码行数:11,代码来源:events.py

示例11: committee

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def committee(request, abbr, committee_id):
    committee = db.committees.find_one({'_id': committee_id})
    if committee is None:
        raise Http404

    return render(request, templatename('committee'),
                  dict(committee=committee, abbr=abbr,
                       metadata=Metadata.get_object(abbr),
                       sources=committee['sources'],
                       statenav_active='committees'))
开发者ID:annerajb,项目名称:billy,代码行数:12,代码来源:committees.py

示例12: speeches

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def speeches(request, abbr):
    events = db.events.find({
        settings.LEVEL_FIELD: abbr,
    })

    return render(request, templatename('speeches'),
                  dict(abbr=abbr,
                       metadata=Metadata.get_object(abbr),
                       speeches=speeches,
                       events=events))
开发者ID:rhymeswithcycle,项目名称:billy,代码行数:12,代码来源:speeches.py

示例13: bill

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def bill(request, abbr, session, bill_id):
    """
    Context:
        - vote_preview_row_template
        - abbr
        - metadata
        - bill
        - events
        - show_all_sponsors
        - sponsors
        - sources
        - nav_active

    Templates:
        - billy/web/public/bill.html
        - billy/web/public/vote_preview_row.html
    """
    # get fixed version
    fixed_bill_id = fix_bill_id(bill_id)
    # redirect if URL's id isn't fixed id without spaces
    if fixed_bill_id.replace(" ", "") != bill_id:
        return redirect("bill", abbr=abbr, session=session, bill_id=fixed_bill_id.replace(" ", ""))
    bill = db.bills.find_one({settings.LEVEL_FIELD: abbr, "session": session, "bill_id": fixed_bill_id})
    if bill is None:
        raise Http404(u"no bill found {0} {1} {2}".format(abbr, session, bill_id))

    events = db.events.find({settings.LEVEL_FIELD: abbr, "related_bills.bill_id": bill["_id"]}).sort("when", -1)
    events = list(events)
    if len(events) > EVENT_PAGE_COUNT:
        events = events[:EVENT_PAGE_COUNT]

    popularity.counter.inc("bills", bill["_id"], abbr=abbr, session=session)

    show_all_sponsors = request.GET.get("show_all_sponsors")
    if show_all_sponsors:
        sponsors = bill.sponsors_manager
    else:
        sponsors = bill.sponsors_manager.first_fifteen

    return render(
        request,
        templatename("bill"),
        dict(
            vote_preview_row_template=templatename("vote_preview_row"),
            abbr=abbr,
            metadata=Metadata.get_object(abbr),
            bill=bill,
            events=events,
            show_all_sponsors=show_all_sponsors,
            sponsors=sponsors,
            sources=bill["sources"],
            nav_active="bills",
        ),
    )
开发者ID:kvimal13,项目名称:billy,代码行数:56,代码来源:bills.py

示例14: vote

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def vote(request, abbr, _id):
    vote = db.votes.find_one(_id)
    if vote is None:
        raise Http404
    bill = vote.bill()

    return render(request, templatename('vote'),
                  dict(abbr=abbr, metadata=Metadata.get_object(abbr),
                       bill=bill,
                       vote=vote,
                       statenav_active='bills'))
开发者ID:annerajb,项目名称:billy,代码行数:13,代码来源:bills.py

示例15: filter_bills

# 需要导入模块: from billy.models import Metadata [as 别名]
# 或者: from billy.models.Metadata import get_object [as 别名]
def filter_bills(request, abbr):
    metadata = Metadata.get_object(abbr)
    FilterBillsForm = get_filter_bills_form(metadata)
    form = FilterBillsForm(request.GET)

    chambers = form.data.getlist('chambers')
    subjects = form.data.getlist('subjects')
    sponsored = form.data.getlist('sponsored')
    actions = form.data.getlist('actions')
    bill_types = form.data.getlist('bill_types')

    raise NotImplementedError('Search is in the works')
开发者ID:msabramo,项目名称:billy,代码行数:14,代码来源:views.py


注:本文中的billy.models.Metadata.get_object方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。