diff --git a/uploader/serializers.py b/uploader/serializers.py index 8e645c4..f6fb09f 100644 --- a/uploader/serializers.py +++ b/uploader/serializers.py @@ -5,7 +5,7 @@ class FileSerializer(serializers.Serializer): name = fields.CharField(allow_blank=True) id = fields.CharField(allow_blank=True) description = fields.CharField(max_length=200, allow_blank=True, allow_null=True) - + categories = fields.CharField(max_length=200, allow_blank=True, allow_null=True) class GooglePhotosUploadInputSerializer(serializers.Serializer): fileList = FileSerializer(many=True) diff --git a/uploader/templates/upload.html b/uploader/templates/upload.html index beccbb6..0bfdc29 100644 --- a/uploader/templates/upload.html +++ b/uploader/templates/upload.html @@ -201,14 +201,15 @@
aria-valuemax="100" > 100% - + + +
- - - - - - + + + + + {% endblock body %} @@ -318,6 +319,46 @@
}, width: 80 }, + { + title: "Categories", + field: "categories", + formatter: function(cell, formatterParams, onRendered) { + return ``; + } + }, { title: "Title", field: "name", @@ -352,6 +393,12 @@
fileList: fileStagingTable.getData(), token: oauthToken }; + for (var x = 0; x < fileData["fileList"].length; x++) { + var sel = document.getElementById( + `wpCategories${fileData["fileList"][x]["id"]}` + ); + fileData["fileList"][x]["categories"] = sel.value; + } function getCookie(name) { var cookieValue = null; diff --git a/uploader/views.py b/uploader/views.py index b2a1273..516c657 100644 --- a/uploader/views.py +++ b/uploader/views.py @@ -81,7 +81,7 @@ def post(self, request, format=None, *args, **kwargs): download_status, done = downloader.next_chunk() uploaded, image_info = wiki_uploader.upload_file( - file_name=file["name"], file_stream=fh, description=file["description"] + file_name=file["name"], file_stream=fh, description=file["description"], categories=file["categories"] ) if uploaded: uploaded_results.append(image_info) diff --git a/uploader/wiki_uploader.py b/uploader/wiki_uploader.py index b335faa..37f3a82 100644 --- a/uploader/wiki_uploader.py +++ b/uploader/wiki_uploader.py @@ -23,7 +23,7 @@ def __init__( access_secret=access_secret, ) - def upload_file(self, file_name, file_stream, description=""): + def upload_file(self, file_name, file_stream, description="", categories=""): if not description: description = file_name @@ -32,7 +32,7 @@ def upload_file(self, file_name, file_stream, description=""): filename=file_name, description=description, ignore=True, - comment="Uploaded with Google drive to commons.", + comment=get_initial_page_text(categories, description), ) debug_information = "Uploaded: {0} to: {1}, more information: {2}".format( file_name, self.mw_client.host, upload_result @@ -43,3 +43,9 @@ def upload_file(self, file_name, file_stream, description=""): return False, {} else: return True, upload_result["imageinfo"] + + + +def get_initial_page_text(categories="", summary=""): + + return "== Summary ==\n{0}\n== Categories ==\n{{{{{1}}}}} ".format(summary, categories)