Beispiel #1
0
def get_context(**context):
    context["labels"] = {
        label_id: label[{
            "he": 0,
            "en": 1
        }[context["lang"]]]
        for label_id, label in LABELS.items()
    }
    return template_functions.get_context(context)
def get_committee_list_context(committees, knesset_num, aggregations):
    def committees_generator():
        override_ids = get_override_committee_ids(aggregations)
        for committee_id, committee in committees.items():
            if not os.environ.get("OVERRIDE_COMMITTEE_IDS") or int(committee_id) in override_ids:
                if committee.get("KnessetNum") and int(committee["KnessetNum"]) == int(knesset_num) and int(committee_id) in aggregations["committee_id"]:
                    yield {"id": committee_id,
                           "name": get_committee_name(committee),
                           "url": COMMITTEE_DETAIL_URL.format(committee_id=committee["CommitteeID"]),
                           "num_meetings": aggregations["committee_id"][int(committee_id)]["num_meetings"]}
    return get_context({"committees": sorted(committees_generator(), key=lambda c: c["name"]),
                        "knesset_num": knesset_num,
                        "aggregations": aggregations})
def build_committees_index_template(jinja_env, committees, aggregations):
    override_nums = os.environ["OVERRIDE_KNESSET_NUMS"].split(",") if os.environ.get("OVERRIDE_KNESSET_NUMS") else []
    override_nums += aggregations["knesset_num"].keys()
    override_nums = set(map(int, override_nums))
    def knesset_nums():
        for knesset_num, knesset_num_stats in aggregations["knesset_num"].items():
            if not os.environ.get("OVERRIDE_KNESSET_NUMS") or int(knesset_num) in override_nums:
                num_meetings = 0
                for committee_id, committee_stats in aggregations["committee_id"].items():
                    if int(committee_id) in map(int, knesset_num_stats["committee_ids"]):
                        num_meetings += committee_stats["num_meetings"]
                yield {"num": knesset_num,
                       "url": COMMITTEE_LIST_KNESSET_URL.format(num=knesset_num),
                       "num_committees": len(knesset_num_stats["committee_ids"]),
                       "num_meetings": num_meetings}
    context = get_context({"knesset_nums": sorted(knesset_nums(), key=lambda k: k["num"], reverse=True)})
    build_template(jinja_env,
                   "committees_index.html",
                   context,
                   COMMITTEES_INDEX_URL)
Beispiel #4
0
def get_context(**context):
    return template_functions.get_context(context)
Beispiel #5
0
from datapackage_pipelines.wrapper import ingest, spew
import logging
import template_functions

parameters, datapackage, resources, stats = ingest() + ({}, )


def get_context(**context):
    return template_functions.get_context(context)


def get_images():
    for resource in resources:
        for row in resource:
            yield row


env = template_functions.get_jinja_env()
context = {"images": get_images()}
template_functions.build_template(env, "arc_index.html",
                                  template_functions.get_context(context),
                                  "final-data/arc/index.html")

spew(dict(datapackage, resources=[]), [], stats)