Example #1
0
def fix_name(attr, lang):
    name_lang = "name_" + lang
    desc_lang = "desc_" + lang
    keywords_lang = "keywords_" + lang
    if desc_lang in attr:
        attr["desc"] = title_case(attr[desc_lang])
        if "desc_en" in attr: del attr["desc_en"]
        if "desc_pt" in attr: del attr["desc_pt"]
    if name_lang in attr:
        attr["name"] = title_case(attr[name_lang])
        if "name_en" in attr: del attr["name_en"]
        if "name_pt" in attr: del attr["name_pt"]
    if keywords_lang in attr:
        attr["keywords"] = title_case(attr[keywords_lang])
        if "keywords_en" in attr: del attr["keywords_en"]
        if "keywords_pt" in attr: del attr["keywords_pt"]
    return attr
Example #2
0
 def render(self, type):
     if self.is_number(self.text):
         num = float(self.text) if "." in str(self.text) else int(self.text)
         return Markup(num_format(num, type))
     else:
         dict = dictionary()
         if self.text in dict:
             return Markup(dict[self.text])
         else:
             return Markup(title_case(self.text))
Example #3
0
 def render(self, type):
     if self.is_number(self.text):
         num = float(self.text) if "." in str(self.text) else int(self.text)
         return Markup(num_format(num, type))
     else:
         dict = dictionary()
         if self.text in dict:
             return Markup(dict[self.text])
         else:
             return Markup(title_case(self.text))
Example #4
0
    def title(self, **kwargs):
        lang = g.locale
        if "lang" in kwargs:
            lang = kwargs["lang"]

        name_lang = "name_en" if lang == "en" else "name_pt"

        title = getattr(Plan_Title.query.get(self.title_id), name_lang)

        def get_article(attr, article):
            if attr.article_pt:
                if attr.gender_pt == "m":
                    if article == "em": new_article = "no"
                    if article == "de": new_article = "do"
                    if article == "para": new_article = "para o"
                elif attr.gender_pt == "f":
                    if article == "em": new_article = "na"
                    if article == "de": new_article = "da"
                    if article == "para": new_article = "para a"
                if attr.plural_pt:
                    new_article = new_article + "s"
                return new_article
            else:
                return article

        if title:
            variables = ["bra", "isic", "hs", "cbo", "wld"]
            and_joiner = " and " if lang == "en" else " e "
            for var in enumerate(variables):
                filter = var[1]
                if "<{0}>".format(filter) in title:
                    title = title.replace(
                        "<{0}>".format(filter),
                        and_joiner.join([
                            getattr(b, name_lang)
                            for b in getattr(self, filter)
                        ]))
                    article_search = re.search("<{0}_(\w+)>".format(filter),
                                               title)
                    if article_search:
                        title = title.replace(
                            article_search.group(0),
                            and_joiner.join([
                                get_article(b, article_search.group(1))
                                for b in getattr(self, filter)
                            ]))

        return title_case(title)
Example #5
0
def fix_name(attr, lang):

    for col in ["desc", "name", "gender", "article", "keywords"]:
        # raise Exception("{}_{}".format(col, lang) in attr)
        if "{}_{}".format(col, lang) in attr:
            attr[col] = title_case(attr["{}_{}".format(col, lang)])
        else:
            attr[col] = False
        if "{}_en".format(col) in attr: del attr["{}_en".format(col)]
        if "{}_pt".format(col) in attr: del attr["{}_pt".format(col)]

    school_type_lang = "school_type_" + lang
    if school_type_lang in attr:
        attr["school_type"] = attr[school_type_lang]
    if "school_type_en" in attr: del attr["school_type_en"]
    if "school_type_pt" in attr: del attr["school_type_pt"]

    if "is_vocational" in attr: del attr["is_vocational"]
    return attr
Example #6
0
def fix_name(attr, lang):

    for col in ["desc", "name", "gender", "article", "keywords"]:
        # raise Exception("{}_{}".format(col, lang) in attr)
        if "{}_{}".format(col, lang) in attr:
            attr[col] = title_case(attr["{}_{}".format(col, lang)])
        else:
            attr[col] = False
        if "{}_en".format(col) in attr: del attr["{}_en".format(col)]
        if "{}_pt".format(col) in attr: del attr["{}_pt".format(col)]

    school_type_lang = "school_type_" + lang
    if school_type_lang in attr:
        attr["school_type"] = attr[school_type_lang]
    if "school_type_en" in attr: del attr["school_type_en"]
    if "school_type_pt" in attr: del attr["school_type_pt"]

    if "is_vocational" in attr: del attr["is_vocational"]
    return attr
Example #7
0
def make_stat(key, group, name, desc=None, value=None, url=None, mode=None, year=None, profile=None):
    if year:
        name += " ({})".format(year)

    if profile:
        url = profile.url()
        desc = profile.name()

    if not value:
        if not desc:
            desc = "-"

    return {
                "group": group,
                "key": key,
                "name": title_case(name),
                "url": url,
                "desc" : desc,
                "value": value,
                "mode" : mode
            }
Example #8
0
    def title(self, **kwargs):
        lang = g.locale
        if "lang" in kwargs:
            lang =  kwargs["lang"]

        name_lang = "name_en" if lang == "en" else "name_pt"

        title = getattr(Plan_Title.query.get(self.title_id),name_lang)
        
        def get_article(attr, article):
            if attr.article_pt:
                if attr.gender_pt == "m":
                    if article == "em": new_article = "no"
                    if article == "de": new_article = "do" 
                    if article == "para": new_article = "para o" 
                elif attr.gender_pt == "f":
                    if article == "em": new_article = "na" 
                    if article == "de": new_article = "da"
                    if article == "para": new_article = "para a" 
                if attr.plural_pt:
                    new_article = new_article + "s"
                return new_article
            else:
                return article
        
        if title:
            variables = ["bra","isic","hs","cbo","wld"]
            and_joiner = " and " if lang == "en" else " e "
            for var in enumerate(variables):
                filter = var[1]
                if "<{0}>".format(filter) in title:
                    title = title.replace("<{0}>".format(filter), and_joiner.join([getattr(b, name_lang) for b in getattr(self,filter)]))
                    article_search = re.search("<{0}_(\w+)>".format(filter), title)
                    if article_search:
                        title = title.replace(article_search.group(0), and_joiner.join([get_article(b, article_search.group(1)) for b in getattr(self,filter)]))

        return title_case(title)
Example #9
0
 def name(self):
     lang = getattr(g, "locale", "en")
     return title_case(getattr(self, "name_" + lang))
Example #10
0
    def title(self, **kwargs):

        lang = g.locale
        if "lang" in kwargs:
            lang = kwargs["lang"]

        title_lang = "title_en" if lang == "en" else "title_pt"
        name_lang = "name_en" if lang == "en" else "name_pt"

        title = getattr(self, title_lang)

        depths = {
            "en": {
                "plural": {},
                "single": {}
            },
            "pt": {
                "plural": {},
                "single": {}
            }
        }
        depths["en"]["single"] = {
            "2": u"State",
            "4": u"Mesoregion",
            "8": u"Municipality"
        }
        depths["en"]["plural"] = {
            "2": u"States",
            "4": u"Mesoregions",
            "8": u"Municipalities"
        }
        depths["pt"]["single"] = {
            "2": u"Estado",
            "4": u"Mesorregião",
            "8": u"Município"
        }
        depths["pt"]["plural"] = {
            "2": u"Estados",
            "4": u"Mesorregiões",
            "8": u"Municípios"
        }

        if "depth" in kwargs and u"bra_" in kwargs["depth"][
                0] and kwargs["depth"][0] != "bra_8":
            if depths[lang]["plural"]["8"] in title:
                title = title.replace(
                    depths[lang]["plural"]["8"],
                    depths[lang]["plural"][kwargs["depth"][0][4:]])
            if depths[lang]["single"]["8"] in title:
                title = title.replace(
                    depths[lang]["single"]["8"],
                    depths[lang]["single"][kwargs["depth"][0][4:]])

        if self.output == "bra" and isinstance(
                self.bra, (list, tuple)) and self.bra[0].id == "all":
            title = title.replace(depths[lang]["plural"]["8"],
                                  depths[lang]["plural"]["2"])
            title = title.replace(depths[lang]["single"]["8"],
                                  depths[lang]["single"]["2"])

        if self.app_id != 2:
            if "year" in kwargs:
                year = kwargs["year"]
            else:
                year = __latest_year__[self.dataset]
            title += " ({0})".format(year)

        def get_article(attr, article):
            if attr.article_pt:
                if attr.gender_pt == "m":
                    if article == "em": new_article = "no"
                    if article == "de": new_article = "do"
                    if article == "para": new_article = "para o"
                elif attr.gender_pt == "f":
                    if article == "em": new_article = "na"
                    if article == "de": new_article = "da"
                    if article == "para": new_article = "para a"
                if attr.plural_pt:
                    new_article = new_article + "s"
                return new_article
            else:
                return article

        if title:
            if lang == "pt":
                joiner = " e "
            else:
                joiner = " and "
            if "<bra>" in title and isinstance(self.bra, (list, tuple)):
                bras = []
                for b in self.bra:
                    name = title_case(getattr(b, name_lang))
                    if b.id != "all" and b.distance > 0:
                        name = name + " " + b.distance + "km"
                    bras.append(name)
                article_search = re.search('<bra_(\w+)>', title)
                if article_search:
                    title = title.replace(" <bra>", "")
                    title = title.replace(
                        article_search.group(0),
                        joiner.join([
                            get_article(b, article_search.group(1)) + " " +
                            bras[i] for i, b in enumerate(self.bra)
                        ]))
                else:
                    title = title.replace("<bra>", joiner.join(bras))
            if "<isic>" in title and hasattr(self, "isic"):
                title = title.replace(
                    "<isic>",
                    joiner.join([
                        title_case(getattr(i, name_lang)) for i in self.isic
                    ]))
                article_search = re.search('<isic_(\w+)>', title)
                if article_search:
                    title = title.replace(
                        article_search.group(0),
                        joiner.join([
                            get_article(b, article_search.group(1))
                            for b in self.isic
                        ]))
            if "<hs>" in title and hasattr(self, "hs"):
                title = title.replace(
                    "<hs>",
                    joiner.join(
                        [title_case(getattr(h, name_lang)) for h in self.hs]))
                article_search = re.search('<hs_(\w+)>', title)
                if article_search:
                    title = title.replace(
                        article_search.group(0),
                        joiner.join([
                            get_article(b, article_search.group(1))
                            for b in self.hs
                        ]))
            if "<cbo>" in title and hasattr(self, "cbo"):
                title = title.replace(
                    "<cbo>",
                    joiner.join(
                        [title_case(getattr(c, name_lang)) for c in self.cbo]))
                article_search = re.search('<cbo_(\w+)>', title)
                if article_search:
                    title = title.replace(
                        article_search.group(0),
                        joiner.join([
                            get_article(b, article_search.group(1))
                            for b in self.cbo
                        ]))
            if "<wld>" in title and hasattr(self, "wld"):
                title = title.replace(
                    "<wld>",
                    joiner.join(
                        [title_case(getattr(w, name_lang)) for w in self.wld]))
                article_search = re.search('<wld_(\w+)>', title)
                if article_search:
                    title = title.replace(
                        article_search.group(0),
                        joiner.join([
                            get_article(b, article_search.group(1))
                            for b in self.wld
                        ]))

        return title
Example #11
0
def guide(category = None, category_id = None, option = None, option_id = None, extra_id = None):

    item = None
    article = None
    selector = category
    plan = None
    group = None
    crumbs = []
    color_icon = None
    option_icon = None
    idOption = 'bra'
    idItem = 'all'
    page = None
    crumb_title = None

    depths = {
        "bra": [2,3,4,7,8],
        "isic": [1,5],
        "cbo": [1,4],
        "hs": [2,6],
        "wld": [2,5],
        "industry": []
    }
    
    if category not in depths and category:
        abort(404)

    if option:

        if category_id == "all":
            category_type = category_id
        else:
            category_type = "<{0}.{1}>".format(category,len(category_id))

        if option_id == "isic" or option_id == "hs":
            option_type = option_id
        elif option_id and option_id != "all":
            option_type = "<bra.{0}>".format(len(option_id))
        else:
            option_type = option_id

        if extra_id and extra_id != "select" and extra_id != "all":
            extra_type = "<{0}.{1}>".format(option_id,len(extra_id))
        elif extra_id != "select":
            extra_type = extra_id
        else:
            extra_type = None

        plan = Plan.query.filter_by(category=category, category_type=category_type, option=option, option_type=option_type, option_id=extra_type).first()

    # raise Exception(plan)

    if plan:

        g.page_type = "plan"
        page = "guide/guide.html"

        plan.set_attr(category_id,category)

        if category == "bra" and extra_id:
            plan.set_attr(extra_id,option_id)

        if category != "bra":
            if option_type and "<bra" in option_type:
                plan.set_attr(option_id,"bra")
            else:
                plan.set_attr("all","bra")

        builds = [0]*len(plan.builds.all())
        for pb in plan.builds.all():

            build = {}
            build["url"] = "/apps/embed/{0}{1}".format(pb.build.all()[0].url(),pb.variables)
            params = dict(urls.url_decode(pb.variables[1:]))
            build["title"] = pb.build.all()[0].title(**params)
            build["type"] = pb.build.all()[0].app.type
            build["position"] = pb.position
            builds[pb.position-1] = build

        plan = {"title": plan.title(), "extra": extra_id,"option_id": option_id, "builds": builds}

    elif extra_id == "select" or option_id == "select" or category_id == "select":
        page = "general/selector.html"
        if extra_id:
            selector = option_id
        elif option_id:
            selector = "bra"

    elif option:
        if category == "cbo":
            selector = "bra"
            page = "guide/choice.html"
        elif category == "bra":
            page = "guide/industry.html"
        elif category == "hs" or category == "isic" and option == "potential":
            selector = "bra"
            page = "guide/choice.html"

    elif category_id:

        if category == "bra":
            if len(category_id) == depths[category][0]:
                group = "parent"
            elif len(category_id) == depths[category][1]:
                group = "all"
            else:
                group = "child"
        else:
            if len(category_id) == depths[category][0]:
                group = "parent"
            elif len(category_id) == depths[category][1]:
                group = "child"

        page = "guide/{0}.html".format(category)

    elif category == "industry":
        page = "guide/industry.html"
        
    elif category == "locate":
        page = "guide/index.html"
        
    elif category:
        page = "guide/choice.html"

    else:
        page = "guide/index.html"

    if selector == "cbo":
        article = gettext(u"an occupation")
    elif selector == "isic":
        article = gettext(u"an industry")
    elif selector == "hs":
        article = gettext(u"a product")
    elif selector == "bra":
        article = gettext(u"a location")

    if category:
        url = "/guide/"
        crumbs.append({"url": url, "text": gettext("Guide")})

        if category == "cbo":
            crumb_title = gettext(u"Career")
        elif category == "industry":
            crumb_title = gettext(u"Industry")
        elif category == "isic":
            crumb_title = gettext(u"Establishments and Employment")
        elif category == "hs":
            crumb_title = gettext(u"Product Exports")
        elif category == "bra":
            crumb_title = gettext(u"Location")

        url += "{0}/".format(category)
        crumbs.append({"url": url, "text": crumb_title})
       
        
        if category_id:
            url += "{0}/".format(category_id)

            if category_id != "all" and category_id != "select":
                table = category.title()
                item = globals()[table].query.get_or_404(category_id).name()
                c_i = globals()[table].query.get_or_404(category_id)
                color_icon = c_i.color
            elif category == "bra":
                item = Wld.query.get_or_404("sabra").name()

            if item:
                crumbs.append({"url": url, "text": item})
            elif category_id == "all":
                crumb_title = gettext("All")
                crumbs.append({"url": url, "text": crumb_title})

            if option:
                url += "{0}/".format(option)
                if option == "isic":
                    crumb_title = gettext(u"Establishments and Employment")
                elif option == "hs":
                    crumb_title = gettext(u"Product Exports")
                else:
                    crumb_title = title_case(gettext(option))
                crumbs.append({"url": url, "text": crumb_title})

                if option_id:
                    url += "{0}/".format(option_id)
                    if option_id == "isic":
                        crumb_title = gettext(u"Establishments and Employment")
                    elif option_id == "hs":
                        crumb_title = gettext(u"Product Exports")
                    elif option_id == "all":
                        crumb_title = Wld.query.get_or_404("sabra").name()
                    elif option_id != "select":
                        crumb_title = Bra.query.get(option_id).name()

                    if option_id != "select":
                        crumbs.append({"url": url, "text": crumb_title})

                    if extra_id and extra_id != "select":
                        url += "{0}/".format(extra_id)
                        if option_id == "hs":
                            crumb_title = Hs.query.get(extra_id).name()
                            c_i = Hs.query.get(extra_id)
                            color_icon = c_i.color
                        if option_id == "isic":
                            c_i = Isic.query.get(extra_id)
                            if c_i.name:
                                crumb_title = c_i.name
                                color_icon = c_i.color
                            else:
                                crumb_title = None
                                color_icon = None
                        crumbs.append({"url": url, "text": crumb_title})

        crumbs[len(crumbs)-1]["current"] = True
        
        if extra_id:
             idItem = extra_id
        else:
             idItem = 'all'
        
        
        if option_id and option_id != 'all':
            idOption = option_id
        else:
            idOption = category
                
        
        if category == 'cbo' or category == 'isic':
            idOption = category
            if category_id:
                idItem = category_id[0:1]
        
        
        if option == 'attract' and option_id == 'isic':
             idItem = extra_id[0:1]
               
        if option == 'attract' and option_id == 'hs':
            idItem = extra_id[0:2]
        

        if option == 'workforce' and category == 'bra': 
            idOption = 'cbo'
            idItem = 'all'
        
        
        if (option == 'isic' or option == 'hs') and category == 'bra': 
            idOption = option
            idItem = 'all'
                
        if (option == 'potential' or option == 'diversification' or option == 'destinations') and category == 'hs': 
            idOption = 'hs'
            idItem = category_id[0:2]

    return render_template(page,
        category = category,
        category_id = category_id,
        option = option,
        option_id = option_id,
        item = item,
        article = article,
        selector = selector,
        plan = plan,
        group = group,
        crumbs = crumbs,
        color_icon = color_icon,
        idOption = idOption,
        idItem = idItem
        )