def check_save(sender, **kwargs): """ Checks item type uniqueness, field applicability and multiplicity. """ tag = kwargs['instance'] obj = Tag.get_object(tag) previous_tags = Tag.get_tags(obj) err_uniq = check_item_type_uniqueness(tag, previous_tags) err_appl = check_field_applicability(tag) err_mult = check_field_multiplicity(tag, previous_tags) err_msg = generate_error_message(tag, err_uniq, err_appl, err_mult) if err_uniq or err_appl or err_mult: raise TypeError(err_msg)
def delete_tags(sender, **kwargs): """ Delete the tags pointing to an object. """ try: obj = kwargs.get('instance') tags = Tag.get_tags(obj) tags.delete() except AttributeError: pass
def render_meta(obj, vocabulary): result = u'<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/">' tags = Tag.get_tags(obj) if tags: value = tags[0].item_type.type_name meta_tag = u'<meta property="DC.type" content="%s"/>' % value result = u'%s\n%s' % (result, meta_tag) for tag in tags: field = tag.field name = field.namespaces.get(vocabulary, field.field_name) value = tag.value if name == 'identifier': value = '%s %s' % (field.field_name.lower(), value) meta_tag = u'<meta property="DC.%s" content="%s"/>' % (name, value) result = u'%s\n%s' % (result, meta_tag) return result
def clone_document(orig, new, options): # Duplicate directories and files orig = Document.objects.get(id=orig_id) new = Document.objects.get(id=new_id) orig_docfile_name = orig.docfile_basename orig_docfile_path = orig.docfile.name orig_dir_path = orig.get_root_path() dest_dir_path = new.get_root_path() orig_slug = orig.slug dest_slug = new.slug fss.clone_tree( orig_docfile_name, orig_docfile_path, orig_dir_path, dest_dir_path, orig_slug, dest_slug ) # Clone pages pages = orig.pages_set.all() for page in pages: new.pages_set.create( page=page.page, modified=page.modified, ) # Clone annotations if options['annotations']: anns = orig.annotations_set.all() for ann in anns: new.annotations_set.create( title=ann.title, location=ann.location, page=ann.page, content=ann.content, author=ann.author, ) # Clone editions if options['editions']: clone_all_editions(orig, new) else: clone_only_primitive_editions(orig, new) # Clone zotero tags if options['zotero']: z_tags = Tag.get_tags(orig) for tag in z_tags: new_t = deepcopy(tag) new_t.id = None new_t.pk = None new_t.set_object(new) # new_t.save() Not necessary - set_object saves the object # Copy collaborators if options['collaborators']: collabs = orig.get_users_with_perms() for collab in collabs: assign_perm('documents.access_document', collab, new) # Copy taggit tags if options['tags']: t_tags = orig.taggit_tags.all() for tag in t_tags: new.taggit_tags.add(tag.name)