예제 #1
0
def get_fao_agrovoc_term(name):
    lang = get_lang()
    term = VocabularyTerm.get(Vocabulary.VOCABULARY_AGROVOC, name)
    if term:
        label = term.get_label(lang) or term.get_label(DEFAULT_LANG) or term.get_label('en')
        return label.label
    return name
예제 #2
0
 def get_localized_datatype(self, datatype):
     out = {'fao_datatype': datatype}
     v = VocabularyTerm.get(Vocabulary.VOCABULARY_DATATYPE, datatype)
     for l in v.labels:
         lname = 'fao_datatype_{}'.format(l.lang)
         out[lname] = l.label
     return out
예제 #3
0
def get_fao_m49_region(name):
    lang = get_lang()
    term = VocabularyTerm.get(Vocabulary.VOCABULARY_M49_REGIONS, name)
    if term:
        label = term.get_label(lang) or term.get_label(DEFAULT_LANG) or term.get_label('en')
        return label.label
    return name
예제 #4
0
def get_url_for_location(location_code):
    lang = get_lang()
    term = VocabularyTerm.get(Vocabulary.VOCABULARY_M49_REGIONS, location_code)
    if not term:
        return h.url_for('search')
    label = term.get_label(lang).label or term.get_label('en').label
    qdict = {'fao_m49_regions_l{}_{}'.format(term.depth, lang): label}
    return h.url_for('search', **qdict)
예제 #5
0
 def get_localized_regions(self, regions):
     out = {'fao_m49_regions': regions}
     for reg in regions:
         v = VocabularyTerm.get(Vocabulary.VOCABULARY_M49_REGIONS, reg)
         parent = v
         while parent:
             for label in parent.labels:
                 lname = 'fao_m49_regions_l{}_{}'.format(parent.depth, label.lang)
                 try:
                     out[lname].add(label.label)
                 except KeyError:
                     out[lname] = set([label.label])
             parent = parent.parent
     for k,v in out.items():
         if isinstance(v, set):
             out[k] = list(v)
     return out
예제 #6
0
    def get_localized_agrovoc(self, terms):
        if not isinstance(terms, list):
            terms = v._deserialize_from_array(terms)
        out = {'fao_agrovoc': terms}
        for term in terms:
            term = VocabularyTerm.get(Vocabulary.VOCABULARY_AGROVOC, term)
            if not term:
                continue
            for label in term.labels:
                lname = 'fao_agrovoc_{}'.format(label.lang)
                try:
                    out[lname].add(label.label)
                except KeyError:
                    out[lname] = set([label.label])

        for k,val in out.items():
            if isinstance(val, set):
                out[k] = list(val)
        return out
예제 #7
0
def get_field_data(data, field, lang=None):
    if field.get('element') == 'agrovoc':
        values = v._deserialize_from_array(data)
        out = []
        lang = lang or get_lang()
        for val in values:
            if not val:
                continue
            term = VocabularyTerm.get(Vocabulary.VOCABULARY_AGROVOC, val)
            if not term:
                out.append(u'{}|{}'.format(val, val))
                continue
            label = term.get_label(lang)
            if not label:
                label = term.get_label('en')
            out.append(u'{}|{}'.format(val, label.label or val))
        print('out', out)
        return out

    elif field.get('multiple'):
        return v._deserialize_from_array(data)
    else:
        return data
예제 #8
0
def get_fao_datatype(name):
    lang = get_lang()
    term = VocabularyTerm.get(Vocabulary.VOCABULARY_DATATYPE, name)
    label = term.get_label(lang) or term.get_label(
        DEFAULT_LANG) or term.get_label('en')
    return (label.label or term.name) if term else None