From a1a1b7d1975732c3dc522699f7f7a713eb82afc9 Mon Sep 17 00:00:00 2001 From: Moasib-Arif Date: Tue, 8 Oct 2024 11:55:05 +0100 Subject: [PATCH] Added license and license_url field to the upload-new function --- dpytools/http/upload/base_upload.py | 4 +++- dpytools/http/upload/upload_service_client.py | 20 ++++++++++++++++++- dpytools/http/upload/utils.py | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dpytools/http/upload/base_upload.py b/dpytools/http/upload/base_upload.py index 9c2a399..cb665d6 100644 --- a/dpytools/http/upload/base_upload.py +++ b/dpytools/http/upload/base_upload.py @@ -61,6 +61,8 @@ def _upload_new( mimetype: str, alias_name: Optional[str], title: Optional[str], + license: Optional[str], + license_url: Optional[str], chunk_size: int = 5242880, ) -> None: """ @@ -76,7 +78,7 @@ def _upload_new( # Generate upload request params upload_params = _generate_upload_new_params( - file_path, chunk_size, mimetype, alias_name, title + file_path, chunk_size, mimetype, alias_name, title, license, license_url ) logger.info( "Upload parameters generated", data={"upload_params": upload_params} diff --git a/dpytools/http/upload/upload_service_client.py b/dpytools/http/upload/upload_service_client.py index 228e70a..f15ee1d 100644 --- a/dpytools/http/upload/upload_service_client.py +++ b/dpytools/http/upload/upload_service_client.py @@ -57,6 +57,8 @@ def upload_new_csv( csv_path: Union[Path, str], alias_name: Optional[str] = None, title: Optional[str] = None, + license: Optional[str] = None, + license_url: Optional[str] = None, chunk_size: int = 5242880, ) -> None: """ @@ -69,6 +71,8 @@ def upload_new_csv( "text/csv", alias_name, title, + license, + license_url, chunk_size, ) @@ -77,6 +81,8 @@ def upload_new_sdmx( sdmx_path: Union[Path, str], alias_name: Optional[str] = None, title: Optional[str] = None, + license: Optional[str] = None, + license_url: Optional[str] = None, chunk_size: int = 5242880, ) -> None: """ @@ -89,6 +95,8 @@ def upload_new_sdmx( "application/xml", alias_name, title, + license, + license_url, chunk_size, ) @@ -97,6 +105,8 @@ def upload_new_json( json_path: Union[Path, str], alias_name: Optional[str] = None, title: Optional[str] = None, + license: Optional[str] = None, + license_url: Optional[str] = None, chunk_size: int = 5242880, ) -> None: """ @@ -104,4 +114,12 @@ def upload_new_json( `alias_name` and `title` are optional arguments. If these are not explicitly provided, `alias_name` will default to the filename with the extension, and `title` will default to the filename without the extension - e.g. if the filename is "data.json", `alias_name` defaults to "data.json" and `title` defaults to "data". """ - self._upload_new(json_path, "application/json", alias_name, title, chunk_size) + self._upload_new( + json_path, + "application/json", + alias_name, + title, + license, + license_url, + chunk_size, + ) diff --git a/dpytools/http/upload/utils.py b/dpytools/http/upload/utils.py index 89b255c..5e798d0 100644 --- a/dpytools/http/upload/utils.py +++ b/dpytools/http/upload/utils.py @@ -65,6 +65,13 @@ def _generate_upload_new_params( if title is None: title = filename.split(".")[0] + + if licence is None: + licence = "Open Government Licence v3.0" + + if licence_url is None: + licence_url = "http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" + # Generate upload request params upload_params = {