Example #1
0
 def test_get_container_path_ontwerp(self):
     """
     Test and assert that the correct container path is returned for type ontwerp
     """
     self.assertEqual(
         ObjectStore.get_container_path(Document.DocumentType.Ontwerp),
         f"upload_container_name/doc/ontwerp")
Example #2
0
 def test_get_container_path_rapport(self):
     """
     Test and assert that the correct container path is returned for type rapport
     """
     self.assertEqual(
         ObjectStore.get_container_path(Document.DocumentType.Rapportage),
         f"upload_container_name/doc/rapportage")
Example #3
0
    def get_file(self, request, pk=None):
        document_model = self.get_object()
        container_path = ObjectStore.get_container_path(document_model.type)
        filename = document_model.filename

        objstore = ObjectStore(settings.OBJECTSTORE_CONNECTION_CONFIG)
        connection = objstore.get_connection()
        try:
            store_object = objstore.get_document(connection, container_path, filename)
        except ClientException as e:
            return handle_swift_exception(container_path, filename, e)

        content_type = store_object[0].get('content-type')
        obj_data = store_object[1]

        response = HttpResponse(content_type=content_type)
        response['Content-Disposition'] = f'attachment; filename="{filename}"'
        response.write(obj_data)

        return response