def setUp(self) -> None: self.user = User.objects.create_superuser("batch_import_user", "*****@*****.**", uuid4) self.root_node = Node.add_root(name="test") self.collection = Collection.objects.create(name="test", short_name="test", root_node=self.root_node) self.collection.administrators.set([self.user])
def handle(self, *args, **options): # index nodes root_nodes = Node.get_collection_roots() for root in root_nodes: self.index_collection(root) # index media items media_entries = Media.objects.select_related('collection', 'set').iterator() for media in media_entries: if media.pk not in self.media_pks: self.index_media(media) self.index_items()
def index_collection(self, root_node): assert root_node in Node.get_collection_roots( ), 'Not a collection root node.' collection = root_node.collection type = ItemType.folder for node in root_node.get_descendants().iterator(): ancestors = node.get_ancestors().values_list('pk', flat=True) item = SearchIndexItem( id=f'{type}_{node.pk}', type=type, pk=node.pk, title=node.name, body=node.description, last_update=time.time(), parents=list(ancestors), collection=collection.slug, ) self.items.append(item)
def generate_test_media(): creator, _ = MediaCreator.objects.get_or_create(first_name="Tester", last_name="Testeroo") user, _ = User.objects.get_or_create(username="******", email="*****@*****.**") license, _ = License.objects.get_or_create(short_name="WTFPL") media_type, _ = MediaType.objects.get_or_create(type=1, name="testtype") node = Node.add_root(name="TestingCollection") return Media.objects.create_media( created_by=user, license=license, creation_date=( timezone.now() - timedelta(days=3), timezone.now() - timedelta(hours=2), ), set=node, creators=[creator], original_media_type=media_type, )
def setUp(self): self.root = Node.add_root(name="testroot") self.target = self.root.add_child(name="testchild") self.user = User.objects.create_superuser("tester", "*****@*****.**", uuid4()) self.creator = MediaCreator.objects.create(first_name="Tester", last_name="Testeroo") self.role = MediaCreatorRole.objects.create(name="testrole") self.license = License.objects.create(short_name="WTFPL") self.collection = Collection.objects.create(name="Testcollection", root_node=self.target) self.media_type = MediaType.objects.create(type=1, name="testtype") self.collection.administrators.set([self.user]) self.tag = Tag.objects.create(name="testtag", collection=self.collection) self.source_id = self.generate_source_id() self.queue = IngestQueue.objects.create( target=self.target, created_by=self.user, ingestion_queue=[self.source_id]) self.url = reverse("api:v1:ingest:ingest_queue_ingest", kwargs={"pk": str(self.queue.pk)})
def get_childrenDirs(self, _): return BaseHAVNodeSerializer( Node.get_collection_roots(), many=True, context=self.context ).data