Skip to content

315766: Add batch picture import functionality#404

Open
arsen-vs wants to merge 6 commits into
developfrom
feature/315766-Upload-picture-helper
Open

315766: Add batch picture import functionality#404
arsen-vs wants to merge 6 commits into
developfrom
feature/315766-Upload-picture-helper

Conversation

@arsen-vs
Copy link
Copy Markdown
Contributor

@arsen-vs arsen-vs commented Jun 4, 2026

  • Introduced BatchPictureImportForm for uploading ZIP files containing images.
  • Implemented methods for processing and validating uploaded images, including handling duplicates and generating previews.
  • Added a new template for the import form to guide users through the upload and matching process.
  • Enhanced unit tests to cover the new functionality, ensuring correct handling of image imports and matching logic.

AB#315766

- Introduced `BatchPictureImportForm` for uploading ZIP files containing images.
- Implemented methods for processing and validating uploaded images, including handling duplicates and generating previews.
- Added a new template for the import form to guide users through the upload and matching process.
- Enhanced unit tests to cover the new functionality, ensuring correct handling of image imports and matching logic.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 98.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.10%. Comparing base (db4feb1) to head (24cc3c5).
⚠️ Report is 8 commits behind head on develop.

Files with missing lines Patch % Lines
...workspace/workspaces/admin/batch/picture_import.py 97.05% 1 Missing and 2 partials ⚠️
.../country_workspace/workspaces/admin/batch/admin.py 98.95% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #404      +/-   ##
===========================================
+ Coverage    96.93%   97.10%   +0.17%     
===========================================
  Files          237      238       +1     
  Lines         9729     9927     +198     
  Branches      1072     1107      +35     
===========================================
+ Hits          9431     9640     +209     
+ Misses         143      133      -10     
+ Partials       155      154       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Arsen P added 2 commits June 5, 2026 10:06
- Modified `compose.yaml` to include additional environment variables for API integration and debugging.
- Updated service configurations for backend, celery worker, and health checks.
- Enhanced unit tests in `test_batch_admin.py` to cover new functionalities, including reprocessing forms and batch picture imports.
- Added helper functions for middleware and ZIP file uploads to streamline test setup and validation.
- Added `BatchPictureImportForm` to the imports in `__init__.py` for better accessibility.
- Updated the `__all__` list to include the new form, ensuring it is publicly available for module users.
Arsen P added 3 commits June 5, 2026 10:54
- Updated the import statement for `Base64ImageField` to reflect its new location in the `country_workspace.utils.flex_fields` module, ensuring consistency across the codebase.
… handling

- Updated the `_guess_image_mimetype` method to return only valid image MIME types.
- Added a filter to remove duplicate entries based on their keys during ZIP file extraction.
- Modified the test for importing pictures to include the ZIP file in the request data.
- Refactored the mock setup for the individual checker in the batch tests for clarity.
…fficiently

- Removed the filtering of duplicate entries from the list of processed images, instead skipping duplicates during the ZIP file extraction process.
- Updated the logic to ensure that only unique keys are processed, improving performance and clarity in handling image imports.
"batch_id": obj.pk,
"match_field": form.cleaned_data["match_field"],
"target_field": form.cleaned_data["target_field"],
**preview,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right that all matching images are base64-encoded and stored in the session until confirmation?
If I’m not mistaken, SESSION_ENGINE is set to django.contrib.sessions.backends.db. Could this result in oversized rows in django_session?

@vitali-yanushchyk-valor
Copy link
Copy Markdown
Contributor

Do we need limits on archive size, file count, and total uncompressed size before reading and base64-encoding all entries?

current[target_field] = item["data_uri"]
if current != individual.flex_fields:
individual.flex_fields = current
individual.save(update_fields=["flex_fields"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should importing pictures invalidate the existing validation status, for example by setting last_checked to None without triggering immediate revalidation?

return entries, duplicates

def get_match_field_choices(self) -> list[tuple[str, str]]:
first_individual = CountryIndividual.objects.filter(batch=self.batch, removed=False).only("raw_data").first()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all individuals in a batch guaranteed to have the same raw_data keys? Otherwise, using only the first active individual may hide valid match fields that are present in other records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants