Ejemplo n.º 1
0
 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])
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
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,
    )
Ejemplo n.º 5
0
    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)})
Ejemplo n.º 6
0
 def get_childrenDirs(self, _):
     return BaseHAVNodeSerializer(
         Node.get_collection_roots(), many=True, context=self.context
     ).data