def convertToTags(vocab,newtag,data,error,context): new_tags = newtag if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def convertToTags(vocab, newtag, data, error, context): new_tags = newtag if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def func(key: FlattenKey, data: FlattenDataDict, errors: FlattenErrorDict, context: Context): new_tags = data.get(key) if not new_tags: return if isinstance(new_tags, str): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def callable(key, data, errors, context): new_tags = data.get(key) if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: if tag_in_vocabulary(tag, v.id, context) is None: log.debug(u'Tag "{}" does not exist in vocabulary "{}", will create one'.format(tag, v.name)) data = {'name': tag, 'vocabulary_id': v.id} created_tag = toolkit.get_action('tag_create')(context, data) log.debug(u'Created tag "{}" in vocabulary "{}"'.format(created_tag, v.name)) validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def callable(key, data, errors, context): new_tags = data.get(key) if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: for part in tag.split(","): try: tag_in_vocabulary_validator(part, context) except Exception: print "need to create tag" num = 1; for i, tag in enumerate(new_tags): for part in tag.split(","): data[('tags', num + n, 'name')] = part data[('tags', num + n, 'vocabulary_id')] = v.id num += 1
def convert_to_tags(key, data, context, vocab): new_tags = data[key] if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): if not data['tags']: data['tags'] = [] data['tags'].append({ 'name': tag, 'vocabulary_id': v.id, 'state': 'active' }) return data
def callable(key, data, errors, context): new_tags = data.get(key) if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: if tag_in_vocabulary(tag, v.id, context) is None: log.debug( u'Tag "{}" does not exist in vocabulary "{}", will create one' .format(tag, v.name)) data = {'name': tag, 'vocabulary_id': v.id} created_tag = toolkit.get_action('tag_create')(context, data) log.debug(u'Created tag "{}" in vocabulary "{}"'.format( created_tag, v.name)) validators.tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def validator(key, data, errors, context): tags = data.get(key) if not tags: return if isinstance(tags, basestring): tags = [tags] v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in tags: val.tag_in_vocabulary_validator(tag, context) return tags
def add_to_vocab(context, tags, vocab): try: v = get_action('vocabulary_show')(context, {'id': vocab}) except ObjectNotFound: v = plugin.create_vocabulary(vocab) context['vocabulary'] = model.Vocabulary.get(v.get('id')) for tag in tags: validators.tag_length_validator(tag, context) validators.tag_name_validator(tag, context) try: validators.tag_in_vocabulary_validator(tag, context) except Invalid: plugin.create_tag_to_vocabulary(tag, vocab)
def callable(key, data, errors, context): #print key if isinstance(data.get(key), basestring): #######controllo se vocab o string #print "string" tmp = data.get(key) tmp = tmp.replace("[", "") # errore scrittura lista/string tmp = tmp.replace("]", "") tmp = tmp.replace("'", " ") # apostrofo non accettato nel vocabolario tmp = tmp.replace(",", "-") # non accetta la virgola tmp = tmp.replace("(", "-") # nemmeno parentesi tmp = tmp.replace(")", "-") new_tags = tmp.lower().split("; ") ############# else: #print "uni" tmp = data.get(key) new_tags = [] import unicodedata for t in tmp: tmp_tags = re.split( ', |,', unicodedata.normalize('NFKD', t).encode('ascii', 'ignore')) for tag in tmp_tags: new_tags.append(tag.lower()) if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == 'tags': n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise df.Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context['vocabulary'] = v for tag in new_tags: old_tag = tag tag = tag.replace("'", " ") # apostrofo non accettato nel vocabolario tag = tag.replace(",", "-") # non accetta la virgola #tag = tag.replace("(", "-") # nemmeno parentesi #tag = tag.replace(")", "-") errore = validators.tag_in_vocabulary_validator( tag, context) #modified by FAST #print errore if errore: new_tags.remove(old_tag) for num, tag in enumerate(new_tags): data[('tags', num + n, 'name')] = tag data[('tags', num + n, 'vocabulary_id')] = v.id
def add_to_vocab(context, tags, vocab): try: v = get_action('vocabulary_show')(context, {'id': vocab}) except ObjectNotFound: v = plugin.create_vocabulary(vocab) if isinstance(tags, basestring): tags = [tags] for tag in tags: validators.tag_length_validator(tag, context) validators.tag_name_validator(tag, context) try: validators.tag_in_vocabulary_validator(tag, context) except Invalid: plugin.create_tag_to_vocabulary(tag, vocab)
def add_to_vocab(context, tags, vocab): defer = context.get('defer', False) try: v = get_action('vocabulary_show')(context, {'id': vocab}) except ObjectNotFound: log.info("creating vocab") v = plugin.create_vocabulary(vocab, defer) context['vocabulary'] = model.Vocabulary.get(v.get('id')) if isinstance(tags, basestring): tags = [tags] for tag in tags: validators.tag_length_validator(tag, context) validators.tag_name_validator(tag, context) try: validators.tag_in_vocabulary_validator(tag, context) except Invalid: plugin.create_tag_to_vocabulary(tag, vocab, defer)
def callable(key, data, errors, context): new_tags = data.get(key) if not new_tags: return if isinstance(new_tags, basestring): new_tags = [new_tags] # get current number of tags n = 0 for k in data.keys(): if k[0] == "tags": n = max(n, k[1] + 1) v = model.Vocabulary.get(vocab) if not v: raise Invalid(_('Tag vocabulary "%s" does not exist') % vocab) context["vocabulary"] = v for tag in new_tags: tag_in_vocabulary_validator(tag, context) for num, tag in enumerate(new_tags): data[("tags", num + n, "name")] = tag data[("tags", num + n, "vocabulary_id")] = v.id