def committee(c_id): c = {} c['votes'] = db.get('com_votes_by_committee', c_id) or None c['agendas'] = db.get('comagenda_by_committee', c_id) or [] c['shortname'] = c_id c['name'] = COMMITTEE_MAP.get(c_id, "Unknown committee") if c['agendas']: for a in c['agendas']: if 'time' in a and a['time']: a['date'] = a['time']['date'] if 'date' not in a: a['date'] = '' rankedMeps=[] for mep in (db.get('meps_by_committee', c_id) or []): for com in reversed(mep['Committees']): if com.get('abbr')==c_id: score=com_positions[com['role']] mep['crole']=com['role'] if com.get('end')=='9999-12-31T00:00:00': rankedMeps.append((score,mep,True)) else: rankedMeps.append((score,mep,False)) break c['meps'] = sorted(rankedMeps,key=lambda x: (x[2],x[0],x[1]['Name']['full']), reverse=True) or None c['dossiers'] = db.get('dossiers_by_committee', c_id) or [] if c['dossiers']: for d in c['dossiers']: clean_lb(d) del d['changes'] tmp=[c for c in d['committees'] if c['committee']==c_id] if len(tmp)>0: d['crole']=tmp[0].get('type') or ("Responsible" if tmp[0].get('responsible') else "Opinion") d['rapporteur']=list({m['name']: m for c in d['committees'] if c.get('type')=="Responsible Committee" or c.get('responsible') for m in c.get('rapporteur',[])}.values()) d['rapporteur_groups'] = sorted({'IND/DEM' if k['abbr'][0]=='ID' else 'NA' if k['abbr'][0]=='NA' else k['abbr'] for k in d['rapporteur'] if k.get('abbr')}) for event in d.get('events',[]): if event.get('type') in ['Non-legislative initial document', "Non-legislative basic document published", 'Commission/Council: initial legislative document', "Legislative proposal", "Legislative proposal published"] and 'docs' in event and len(event['docs'])>0: if 'title' in event['docs'][0]: d['comdoc']={'title': event['docs'][0]['title'], 'url': event['docs'][0].get('url'), } break return render( 'committee.html', committee=c, groupids=GROUPIDS, now_date=date.today().strftime("%Y-%m-%d"), exclude_from_json=('now_date',) )
def listdossiers(d): for act in d.get('activities', []): if act.get('type') in ['Non-legislative initial document', 'Commission/Council: initial legislative document', "Legislative proposal", "Legislative proposal published"]: if 'title' in act.get('docs',[{}])[0]: d['comdoc']={'title': act['docs'][0]['title'], 'url': act['docs'][0].get('url'), } if 'date' not in act: print('removing [%s] %s' % (d['activities'].index(act), act)) del d['activities'][d['activities'].index(act)] if 'legal_basis' in d.get('procedure', {}): clean_lb(d) # TODO implement db.comagendas_by_dossier in db. useful for dashboard view in notifications #for item in db.ep_comagendas.find({'epdoc': d['procedure']['reference']}): # if 'tabling_deadline' in item and item['tabling_deadline']>=datetime.now(): # d['activities'].insert(0,{'type': '(%s) Tabling Deadline' % item['committee'], 'body': 'EP', 'date': item['tabling_deadline']}) return d
def dossier(d_id): d = db.dossier(d_id) if not d: return not_found_error(None) d, changes, date, failed = timetravel(d) clean_lb(d) d['amendments'] = [a for a in (db.get("ams_by_dossier", d_id) or []) if a.get('date',"0") < date] # filter amendments by timetravel # some amendments have letters as seq numbers m( for a in d['amendments']: a['seq']=str(a['seq']) progress = 0 if d_id in v1dossiers or 'activities' in d: template = "v1dossier.html" types = None else: template = "dossier.html" d['events'] = merge_events(d) d['vmatrix'] = votematrices([v for v in (db.get('votes_by_dossier',d_id) or []) if v.get('ts','0') < date ]) # filter votes by timetravel date # get activities by meps meps={} # lookup to match shadow rapporteurs to committees comap = {c0: i for i, c in enumerate(d.get('committees', [])) if c.get('type',c.get('responsible')) not in ('Responsible Committee', 'Former Responsible Committee', True, None) for c0 in ([c['committee']] if isinstance(c['committee'], str) else c['committee'])} for act, type, mepid, mepname in (db.activities_by_dossier(d_id) or []): if type in ["REPORT", "REPORT-SHADOW", "COMPARL"]: continue if type == 'COMPARL-SHADOW': comlst = [act['committee']] if isinstance(act['committee'],str) else act['committee'] for srcom in comlst: if srcom not in comap: continue # merge shadow rapporteurs into d['committees'] mep = db.mep(mepid) com = d['committees'][comap[srcom]] if not 'shadows' in com: com['shadows']=[] for g in mep['Groups']: start = g['start'] end = datetime.now().isoformat() if g['end'] in ['9999-12-31T00:00:00', '31-12-9999T00:00:00'] else g['end'] if start <= act['date'] <=end: com['shadows'].append({'name': mepname, 'mepref': mepid, 'group': g['Organization'], 'abbr': g['groupid']} ) continue if not mepid in meps: meps[mepid]={'name': mepname, 'types': {}} if not type in meps[mepid]['types']: meps[mepid]['types'][type]=[] if act.get('date','0') < date: # filter for timetravel meps[mepid]['types'][type].append(act) d['mep_activities']=sorted(meps.items(), key=lambda x: sum(len(y) for y in x[1]['types'].values()), reverse=True) types = { 'CRE': 'Plenary Speeches', "MOTION": 'Institutional Motions', "OQ": 'Oral Questions', 'WEXP': 'Written Explanations', 'MINT': 'Major Interpellations', "WQ": 'Written Questions', "IMOTION": 'Individiual Motions', "WDECL": 'Written Declarations', } for a in d.get('events',[]): if a.get('type') in stage2percent: progress = stage2percent[a['type']] break stage_progress = stage2percent.get(d['procedure'].get('stage_reached'), 0) progress = max(progress, stage_progress) history_filters = set() for cs in d['changes'].values(): for c in cs: history_filters.add(change_path_str(c['path'])) history_filters = sorted(history_filters, key=lambda x: x.capitalize()) history_filter = request.args.get('history_filter') if history_filter: history_filter = [x for x in history_filter.split('.') if not x.isdigit()] d['changes'] = filter_changes(d['changes'], history_filter) return render( template, dossier=d, d=d_id, url=request.base_url, now_date=date, change_dates=changes, progress=progress, TYPES=types, msg=ep_wtf_dossiers.get(d_id), history_filters=history_filters, history_filter=None if not history_filter else change_path_str(history_filter), tt_fail=failed, exclude_from_json=('now_date', 'url', 'd', 'progress', 'TYPES', 'history_filter', 'history_filters', 'tt_fail'), )