Exemple #1
0
def embed_view(attr_type, attr_id, section, topic):
    viz_only = request.args.get("viz", False)
    if not attr_type in PROFILES:
        abort(404);

    g.page_class = "{} embed".format(attr_type)

    topics = topic.split(",")
    required_namespaces = Profile.compute_namespaces(attr_type, section, topics)
    p = Profile(attr_id, attr_type, required_namespaces)
    section = p.section_by_topic(section, topics)

    if not section or not section.topics:
        abort(404)

    for t in section.topics:
        if viz_only:
            if "description" in t:
                del t["description"]
            if "stat" in t:
                del t["stat"]
        if "category" in t:
            del t["category"]

    return render_template("profile/embed.html", profile = p, section = section)
Exemple #2
0
def embed_view(attr_type, attr_id, section, topic):
    viz_only = request.args.get("viz", False)
    if not attr_type in PROFILES:
        abort(404)

    g.page_class = "{} embed".format(attr_type)

    topics = topic.split(",")
    required_namespaces = Profile.compute_namespaces(attr_type, section,
                                                     topics)
    p = Profile(attr_id, attr_type, required_namespaces)
    section = p.section_by_topic(section, topics)

    if not section or not section.topics:
        abort(404)

    if "description" in section.topics[0]:
        section.meta = section.topics[0]["description"][0]
    else:
        section.meta = ""

    for t in section.topics:
        if viz_only:
            if "description" in t:
                del t["description"]
            if "stat" in t:
                del t["stat"]
        if "category" in t:
            del t["category"]

    g.compare = request.args.get("compare", False)
    if g.compare:
        g.compare = fetch(g.compare, attr_type)

    return render_template("profile/embed.html", profile=p, section=section)
Exemple #3
0
def profile(attr_type, attr_id):

    if "_iocode" in attr_type:
        attr_type = "iocode"

    allowed_type = attr_type in PROFILES or attr_type in CROSSWALKS
    allowed_id = attr_type in attr_cache and attr_id in attr_cache[attr_type]
    if not allowed_type or not allowed_id:
        abort(404)
    if attr_type in CROSSWALKS:
        attr = attr_cache[attr_type][attr_id]

        crosswalks = acs_crosswalk(attr_type, attr_id)
        crosswalk_map = {
            "acs_occ": "soc",
            "acs_ind": "naics",
            "iocode": "naics"
        }
        crosswalk_labels = {
            "acs_occ": "ACS Occupation Code",
            "acs_ind": "ACS Industry Code",
            "iocode": "BEA I/O Code"
        }
        if len(crosswalks) > 1:
            g.page_type = "redirect"
            attr["type"] = crosswalk_labels[attr_type]
            return render_template("profile/redirect.html",
                                   attr=attr,
                                   crosswalks=crosswalks,
                                   crosswalk_type=crosswalk_map[attr_type])
        return redirect(
            url_for('.profile',
                    attr_type=crosswalk_map[attr_type],
                    attr_id=crosswalks[0]["id"]))

    g.page_class = attr_type

    # pass id and type to Profile class
    attr_data = attr_cache[attr_type][attr_id]
    p = Profile(attr_data["id"], attr_type)

    # render the profile template and pass the profile to jinja
    return render_template("profile/index.html", profile=p)
Exemple #4
0
 def process_viz(cls, attr_id, attr_type, viz_obj):
     profile = Profile(attr_id, attr_type)
     section = Section(profile.load_yaml(viz_obj), profile)
     return section.topics
Exemple #5
0
def profile_fetch(attr_type, attr_id):
    attr_data = attr_cache[attr_type][attr_id]
    p = Profile(attr_data["id"], attr_type)
    p.sections()
    return p
Exemple #6
0
def profile_fetch(attr_type, attr_id):
    attr_data = attr_cache[attr_type][attr_id]
    p = Profile(attr_data["id"], attr_type)
    p.sections()
    return p