本文整理汇总了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'))
示例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))
示例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
示例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",
),
)
示例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'))
示例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))
示例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'))
示例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))
示例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'))
示例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'))
示例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'))
示例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))
示例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",
),
)
示例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'))
示例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')