Adds bulk image imports from Google Drive to the Wagtail Admin
Project description
wagtail-image-import
Adds image import from Google Drive, including identifying potential duplicates, to the Wagtail Admin.
Installation
Add to INSTALLED_APPS
in your settings file above wagtail.admin
Setup
Wagtail Image Import relies on Google APIs, which you will first need to enable for your project:
-
Navigate to the Google API Library. Select a project for your Wagtail site, or create a new one.
-
Find and enable the Google Docs and Google Drive APIs.
-
Find and enable the Google Picker API, and copy its API key to the setting
WAGTAIL_IMAGE_IMPORT_GOOGLE_PICKER_API_KEY
. -
Open the Credentials page in the API Console.
-
Select
Create credentials
, thenOAuth client ID
-
If you haven't already configured the consent screen, you will need to configure this now.
-
Under
Scopes for Google APIs
, clickAdd scope
. -
Add
../auth/documents.readonly
and../auth/drive.readonly
scopes.Note: adding these sensitive scopes means that you will need to submit your project for verification by Google to avoid user caps and warning pages during use.
-
Add your domain to
Authorised domains
.
-
-
For
Application type
, chooseWeb application
. -
Under
Authorised JavaScript origins
, add your domain. -
On the Credentials page, next to your Client ID, click the download item to download a JSON file of your client secret.
-
Copy the text from this file, and use it to set
WAGTAILIMAGEIMPORT_GOOGLE_OAUTH_CLIENT_SECRET
.
Duplicate Comparison Setup
Wagtail Image Import will attempt to identify the most likely duplicate of an image, in case it has been previously imported. By default, it will do this by comparing the unique Drive ID of each import, as well as the titles. If this is all you need, you can skip this section, or just use it to tweak the default experience.
If you are using a custom image model, you can also add the wagtail_image_import.models.DuplicateFindingMixin
to your custom model, which exposes the EXIF datetime and md5 hash for even better duplicate identification. An example of adding this to a very basic custom image model is shown below:
from wagtail.images.models import Image, AbstractImage, AbstractRendition
from wagtail_image_import.models import DuplicateFindingMixin
class CustomImage(DuplicateFindingMixin, AbstractImage):
admin_form_fields = Image.admin_form_fields
class CustomRendition(AbstractRendition):
image = models.ForeignKey(
CustomImage, on_delete=models.CASCADE, related_name="renditions"
)
class Meta:
unique_together = (("image", "filter_spec", "focal_point_key"),)
If you choose to add the mixin and have existing image data, you will need to call save()
on all existing instances to fill in the new fields. This can be done in the Django shell:
from wagtail.images import get_image_model
for image in get_image_model().objects.all():
image.save()
In order to adjust the duplicate finding process, you can use the
WAGTAILIMAGEIMPORT_FIELD_MAPPING
and WAGTAILIMAGEIMPORT_FIELD_WEIGHTING
settings.
WAGTAILIMAGEIMPORT_FIELD_MAPPING
maps Google Drive field names to the database field names. By default, it is:
{
"id": "driveidmapping__drive_id",
"name": "title",
}
If you add the mixin, use:
{
"id": "driveidmapping__drive_id",
"name": "title",
"imageMediaMetadata__time": "exif_datetime",
"md5Checksum": "md5_hash"
}
To map the new fields. (If you have additional custom fields, the full list of Drive fields is: 'id', 'name', 'thumbnailLink', 'fileExtension' 'md5Checksum', 'size', 'imageMediaMetadata__width', 'imageMediaMetadata__height', 'imageMediaMetadata__rotation', 'imageMediaMetadata__time
, though not all may be present on every image)
To adjust the field weighting - their relative importance in finding the most likely duplicate - you can set WAGTAILIMAGEIMPORT_FIELD_WEIGHTING
, which maps database fields to weightings. The default is:
{
"driveidmapping__drive_id": 10,
"md5Checksum": 5,
"title": 2
}
All fields not listed are given a weighting of 1.
Other Settings
WAGTAILIMAGEIMPORT_SET_DRIVE_PARENT_FUNCTION
:
If you would like to choose the starting folder for the Google picker, and prevent navigation outside it (note that due to the limitations of the picker options, this does not limit search results to children of this folder), this setting can be set to the string path to a function. This function must take the request object, and return a string Drive ID for the parent folder.
Usage
For superusers or users with the 'import' permission (which can be added to groups in the Wagtail admin groups section), the image index's "Add image" button will now be a dropdown, with an additional "Import from Drive" option. Choose this to be taken to the import screen.
You may select folders (all of whose direct image children will be imported - currently, children of subfolders are ignored) or images.
Once selected, Wagtail Image Import will find potential duplicates and - if duplicates are found - take you to the review screen, where you can choose whether to replace existing images, keep both, or cancel the upload for the new image.
Once confirmed, the upload will begin. As images finish importing, you will be able to edit their metadata.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtail_image_import-0.1.1.tar.gz
.
File metadata
- Download URL: wagtail_image_import-0.1.1.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ab180a87f8786b8d480882f5bff9624e1d620d5d425826531d35f6e4639c26 |
|
MD5 | 297b4c0030e3de53f24ee297558234f6 |
|
BLAKE2b-256 | 30c860c7f40b354ae0f363b1fbf7bb47d2c2934f98d8a6d9dcecc07bfbbb59c6 |
File details
Details for the file wagtail_image_import-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: wagtail_image_import-0.1.1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 701fc828575fbfba368ada987e9fc51ee37f932d0475bec49d1f441994523290 |
|
MD5 | c6206f7660d3a3460d32c77c20fa888d |
|
BLAKE2b-256 | 04060ac428eaa06e960644918c21f6dfd81193c653211b9eee046e9e7e5457a5 |