def getJSON(self, lang): """ Inherited from Widget """ j = super(CheckboxInputWidget, self).getJSON(lang) j['default'] = get_by_lang(self.attributes['defaults'], lang) """ "choices": [ { "label": "Uomo", "description": "", "type": "xsd:string", "value": "http://w3id.com/gender-ontology/male" }, ] """ options = get_by_lang(self.attributes['options'], lang) j['choices'] = [] if options: for opt in [ast.literal_eval(o.strip()) for o in options.split(',')]: choice = {} choice['label'] = opt choice['description'] = "" choice['type'] = "" choice['value'] = opt j['choices'] += [ choice ] return j
def getJSON(self, lang): """ Inherited from Widget """ j = super(CheckboxInputWidget, self).getJSON(lang) j['default'] = get_by_lang(self.attributes['defaults'], lang) """ "choices": [ { "label": "Uomo", "description": "", "type": "xsd:string", "value": "http://w3id.com/gender-ontology/male" }, ] """ options = get_by_lang(self.attributes['options'], lang) j['choices'] = [] if options: for opt in [ ast.literal_eval(o.strip()) for o in options.split(',') ]: choice = {} choice['label'] = opt choice['description'] = "" choice['type'] = "" choice['value'] = opt j['choices'] += [choice] return j
def getJSON(self, lang): """ Inherited from Widget """ j = super(TextInputWidget, self).getJSON(lang) j['default'] = get_by_lang(self.attributes['defaults'], lang) j['placeholder'] = get_by_lang(self.attributes['placeholders'], lang) return j
def update_single_field(d_orig, d_curr, field, property, lang): """Utility function""" old_value = get_by_lang(d_orig[field], lang) new_value = get_by_lang(d_curr[field], lang) assert (not old_value and old_value.language == None) or (old_value.language == new_value.language), \ "old language %r differ from new language %r" % (old_value.language, new_value.language) if old_value != new_value: if verbose: print "%(field)s (%(property)s): %(old_value)r -> %(new_value)r" % vars() update_triple(self.conn, self.individual_uri, property, old_value, new_value) return True else: return False
def get_allowed_values(self, lang): assert self.attributes.has_key('options') options = get_by_lang(self.attributes['options'], lang) if options: return [ast.literal_eval(o.strip()) for o in options.split(',')] else: return []
def update_single_field(d_orig, d_curr, field, property, lang): """Utility function""" old_value = get_by_lang(d_orig[field], lang) new_value = get_by_lang(d_curr[field], lang) assert (not old_value and old_value.language == None) or (old_value.language == new_value.language), \ "old language %r differ from new language %r" % (old_value.language, new_value.language) if old_value != new_value: if verbose: print "%(field)s (%(property)s): %(old_value)r -> %(new_value)r" % vars( ) update_triple(self.conn, self.individual_uri, property, old_value, new_value) return True else: return False
def get_json(self, lang): j = collections.OrderedDict() j['uri'] = self.individual_uri j['type'] = self.type j['lang'] = lang j['label'] = get_by_lang(self.data_current['labels'], lang) j['description'] = get_by_lang(self.data_current['descriptions'], lang) # j['last_modified'] = ... # j['authors'] = ... j['properties'] = [] for property in self.data_current['properties']: d = collections.OrderedDict() d['uri'] = property d['values'] = get_by_lang_mul(self.data_current['properties'][property], lang) j['properties'] += [ d ] return j
def get_json(self, lang): j = collections.OrderedDict() j['uri'] = self.individual_uri j['type'] = self.type j['lang'] = lang j['label'] = get_by_lang(self.data_current['labels'], lang) j['description'] = get_by_lang(self.data_current['descriptions'], lang) # j['last_modified'] = ... # j['authors'] = ... j['properties'] = [] for property in self.data_current['properties']: d = collections.OrderedDict() d['uri'] = property d['values'] = get_by_lang_mul( self.data_current['properties'][property], lang) j['properties'] += [d] return j
def get_description(self, lang): assert self.attributes.has_key('descriptions') return get_by_lang(self.attributes['descriptions'], lang)
def get_label(self, lang): assert self.attributes.has_key('labels') return get_by_lang(self.attributes['labels'], lang)