def get_member_context(member):
    for position_attr in ('committees', 'committee_chairperson',
                          'faction_chairperson', 'factions', 'govministries'):
        for position in member.setdefault(position_attr, []):
            position['start_date'] = position['start_date'].strftime(
                '%d/%m/%Y')
            if position['finish_date']:
                position['finish_date'] = position['finish_date'].strftime(
                    '%d/%m/%Y')
    return get_context(member)
Exemple #2
0
def get_meeting_context(meeting, context_data, use_data=True):
    context = get_context({
        "topics":
        meeting["topics"],
        "note":
        meeting.get("Note"),
        "meeting_datestring":
        meeting["StartDate"].strftime("%d/%m/%Y"),
        "member_url":
        MEMBER_URL,
        "meeting_id":
        meeting["CommitteeSessionID"],
        "source_meeting_schema":
        context_data['meetings_descriptor']["schema"],
        "source_meeting_row":
        meeting,
        "source_committee_schema":
        context_data['kns_committee_descriptor']["schema"],
    })
    if meeting['CommitteeSessionID'] in HIDE_MEETING_IDS:
        context['hidden_meeting'] = True
        speech_parts_list = []
    else:
        try:
            speech_parts_list = list(
                get_speech_parts(meeting, use_data=use_data))
        except Exception as e:
            logging.exception(
                "failed to get speech parts for meeting {}".format(
                    meeting["CommitteeSessionID"]))
            speech_parts_list = []
        context.update(speech_parts=speech_parts_list,
                       speech_part_body=get_speech_part_body)

    attended_mks = [
        context_data['mk_individuals'][mk_id]
        for mk_id in meeting["attended_mk_individual_ids"]
    ]
    context.update(attended_mks=attended_mks)

    committee = context_data['kns_committees'][meeting["CommitteeID"]]
    context.update(title="ישיבה של {} בתאריך {}".format(
        committee["Name"], meeting["StartDate"].strftime("%d/%m/%Y")),
                   committee_name=committee["Name"],
                   committee_url=COMMITTEE_DETAIL_URL.format(
                       committee_id=committee["CommitteeID"]),
                   knesset_num=committee["KnessetNum"],
                   committeelist_knesset_url=COMMITTEE_LIST_KNESSET_URL.format(
                       num=committee["KnessetNum"]),
                   source_committee_row=committee)

    context_data['meeting_stats'][meeting["CommitteeSessionID"]] = {
        "num_speech_parts": len(speech_parts_list)
    }
    return context
Exemple #3
0
def get_meeting_context(meeting):
    try:
        speech_parts_list = list(get_speech_parts(meeting))
    except Exception as e:
        logging.exception("failed to get speech parts for meeting {}".format(
            meeting["CommitteeSessionID"]))
        speech_parts_list = []
    attended_mks = [
        mk_individuals[mk_id]
        for mk_id in meeting["attended_mk_individual_ids"]
    ]
    committee = kns_committees[meeting["CommitteeID"]]
    context = get_context({
        "topics":
        meeting["topics"],
        "title":
        "ישיבה של {} בתאריך {}".format(
            committee["Name"], meeting["StartDate"].strftime("%d/%m/%Y")),
        "committee_name":
        committee["Name"],
        "meeting_datestring":
        meeting["StartDate"].strftime("%d/%m/%Y"),
        "committee_url":
        COMMITTEE_DETAIL_URL.format(committee_id=committee["CommitteeID"]),
        "member_url":
        MEMBER_URL,
        "knesset_num":
        committee["KnessetNum"],
        "committeelist_knesset_url":
        COMMITTEE_LIST_KNESSET_URL.format(num=committee["KnessetNum"]),
        "meeting_id":
        meeting["CommitteeSessionID"],
        "speech_parts":
        speech_parts_list,
        "speech_part_body":
        get_speech_part_body,
        "source_meeting_schema":
        meetings_descriptor["schema"],
        "source_meeting_row":
        meeting,
        "source_committee_schema":
        kns_committee_descriptor["schema"],
        "source_committee_row":
        committee,
        "attended_mks":
        attended_mks,
    })
    meeting_stats[meeting["CommitteeSessionID"]] = {
        "num_speech_parts": len(speech_parts_list)
    }
    return context
def get_committee_index_context(knesset_num_committees):
    def knesset_nums():
        for knesset_num, kns_committees in knesset_num_committees.items():
            num_meetings = 0
            for kns_committee in kns_committees:
                num_meetings += len(kns_committee.get("meetings", []))
            yield {
                "num": knesset_num,
                "url": COMMITTEE_LIST_KNESSET_URL.format(num=knesset_num),
                "num_committees": len(kns_committees),
                "num_meetings": num_meetings
            }

    return get_context({
        "knesset_nums":
        sorted(knesset_nums(), key=lambda k: k["num"], reverse=True)
    })
def get_committee_context(committee):
    return get_context({
        "source_committee_row":
        committee,
        "source_committee_schema":
        kns_committee_descriptor["schema"],
        "name":
        get_committee_name(committee),
        "meetings":
        get_committee_meeting_contexts(committee),
        "knesset_num":
        committee["KnessetNum"],
        "committeelist_knesset_url":
        COMMITTEE_LIST_KNESSET_URL.format(num=committee["KnessetNum"]),
        "member_url":
        MEMBER_URL,
        "mks":
        sorted(committee.get("mks", {}).values(),
               key=lambda mk: mk["mk_individual_name"]),
    })
def get_committee_list_context(committees, knesset_num):
    def committees_generator():
        for committee in committees:
            yield {
                "id":
                committee["CommitteeID"],
                "name":
                get_committee_name(committee),
                "url":
                COMMITTEE_DETAIL_URL.format(
                    committee_id=committee["CommitteeID"]),
                "num_meetings":
                len(committee["meetings"]),
            }

    return get_context({
        "committees":
        sorted(committees_generator(), key=lambda c: c["name"]),
        "knesset_num":
        knesset_num
    })
def main():
    parameters, datapackage, resources = ingest()

    jinja_env = get_jinja_env()

    members = {}
    factions = {}
    knessets = {}
    counts = {}

    for descriptor, resource in zip(datapackage["resources"], resources):
        if descriptor["name"] == "members":
            for member in resource:
                members[member["mk_individual_id"]] = member
        elif descriptor["name"] == "positions":
            for position in resource:
                if position["object_type"] == "faction":
                    factions[position["object_id"]] = {
                        "faction_num": position["object_id"],
                        "faction_name": position["object_name"],
                        "mks": []
                    }
                    for id in position["mk_individual_ids"]:
                        factions[position["object_id"]]["mks"].append(
                            members[id])
        elif descriptor["name"] == "knessets":
            for knesset in resource:
                knessets[knesset["KnessetNum"]] = []
                for id in knesset["faction"]:
                    knessets[knesset["KnessetNum"]].append(factions[id])

    for knesset_num, factions in knessets.items():
        mks = set()

        build_template(
            jinja_env, "factions_index.html",
            get_context({
                "knesset_num":
                knesset_num,
                "factions":
                factions,
                "faction_url":
                FACTION_URL.format(knesset_num=knesset_num,
                                   faction_id="{faction_id}"),
                "member_url":
                MEMBER_URL
            }), FACTION_HOME_URL.format(knesset_num=knesset_num))

        for faction in factions:
            if not faction['faction_name']:
                continue

            for mk in faction['mks']:
                mks.add(mk['mk_individual_id'])

            build_template(
                jinja_env, "faction_detail.html",
                get_context({
                    "knesset_num":
                    knesset_num,
                    "faction_num":
                    faction["faction_num"],
                    "faction_name":
                    faction["faction_name"],
                    "mks":
                    faction["mks"],
                    "faction_home_url":
                    FACTION_HOME_URL.format(knesset_num=knesset_num),
                    "member_url":
                    MEMBER_URL
                }),
                FACTION_URL.format(knesset_num=knesset_num,
                                   faction_id=faction["faction_num"]))

        counts[knesset_num] = {'factions': len(factions), 'mks': len(mks)}

    build_template(
        jinja_env, "members_index.html",
        get_context({
            "keys": sorted(counts, reverse=True),
            "knessets": counts,
            "url": FACTION_HOME_URL
        }), MEMBERS_HOME_URL)

    if os.environ.get("SKIP_STATIC") != "1":
        subprocess.check_call(
            ["mkdir", "-p", "../../data/committees/dist/dist"])
        subprocess.check_call(
            ["cp", "-rf", "static", "../../data/committees/dist/dist/"])

    spew(dict(datapackage, resources=[]), [], {})
def get_homepage_context():
    return get_context({})