Skip to content

Introduce BoundingBox field and define_regions admin UI - #63

Merged
domdinicola merged 9 commits into
developfrom
feature/archive-define-regions
Oct 26, 2026
Merged

domdinicola merged 9 commits into
developfrom
feature/archive-define-regions

Conversation

@JackW09

@JackW09 JackW09 commented Oct 22, 2026

Copy link
Copy Markdown

Summary

  • Add BoundingBox / Point value types and BoundingBoxField custom model field

  • Add DocumentAttribute.region field to store a bounding box per attribute

  • Add "Define Regions" admin button on DocumentAdmin — canvas UI lets users draw a bounding box for each attribute on an uploaded document image and save them back to the DB

  • Add AttributeExtractor Protocol and OCRAttributeExtractor implementation

  • Wire region-aware extraction into process_analysis_job; fall back to full-image OCR when no region is set

  • Expose ?sync=true on POST /api/analyze/ for synchronous extraction (runs in-process, no Celery required)

  • Register AnalysisJobAdmin and add demo_data management command

  • Fix: canvas image lost after "Save regions" POST (embed image_src as hidden field)

  • Rewrite all docs (about, api, architecture, configuration) to reflect the REST API, async pipeline, and region extraction

Notes

  • BoundingBoxField stores coordinates in original image pixel space regardless of how the canvas is scaled in the browser
  • OCRAttributeExtractor crops with a small padding constant before passing to Tesseract; if the crop is empty it falls back to full-image OCR

Legal Boilerplate

Look, I get it.
Contributing to HOPE Payment Gateway, I retain all rights, title and interest in and to my contributions, and by keeping
this boilerplate intact I confirm that HOPE Workspace can use, modify, copy, and redistribute my contributions,
under HOPE's choice of terms.

@JackW09
JackW09 requested review from domdinicola and saxix October 22, 2026 13:22
@JackW09
JackW09 added this pull request to stack #61 October 22, 2026 13:22
@codecov-commenter

codecov-commenter commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (194bc2c) to head (ffa99c1).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #63      +/-   ##
===========================================
+ Coverage    99.09%   99.18%   +0.08%     
===========================================
  Files           74       78       +4     
  Lines         1659     1837     +178     
  Branches       123      149      +26     
===========================================
+ Hits          1644     1822     +178     
  Misses           8        8              
  Partials         7        7              
Flag Coverage Δ
unittests 99.18% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@JackW09
JackW09 force-pushed the feature/archive-define-regions branch from 3d725c5 to 6645c6f Compare October 23, 2026 10:33
@domdinicola
domdinicola force-pushed the feature/archive-define-regions branch from 6645c6f to 51bfec9 Compare October 23, 2026 11:11
Base automatically changed from feature/52-validation-expressions to develop October 26, 2026 07:15
  Add Point and BoundingBox frozen dataclasses with BoundingBoxField
  (JSONField subclass) to replace the raw JSONField on
  DocumentAttribute.region. Adds a Define Regions button to
  DocumentAdmin that renders an HTML5 canvas page for labelling
  attribute bounding boxes against a reference image. Also fixes the
  admin login blur by adding unsafe-eval to CSP (required by
  Unfold/Alpine.js) and corrects the Unfold logo static path.
… fix validation_expression dark mode

  - Add unit tests for Point, BoundingBox, and BoundingBoxField (round-trip,
    value_from_object regression, get_prep_value, from_db_value)
  - Add four admin view tests for the define_regions button (GET, image upload,
    save coords, clear coords)
  - Fix validation_expression input invisible in dark mode: switch
    DocumentAttributeInline to unfold TabularInline and override
    formfield_for_dbfield to replace the widget after RegexField.formfield()
    sets its own, ensuring UnfoldAdminTextInputWidget is used
  - Add validation_expression to DocumentAttributeAdmin.list_display
  - Rename migration 0005→0006 for BoundingBoxField (rebase conflict fix)
  - Add demo_data management command and wire it into develop
…ysisJob admin

  - Introduce AttributeExtractor protocol and OCRAttributeExtractor in
    extractors.py; regions are treated as hints — crop is tried first,
    falling back to full-image search if the crop returns empty. This
    isolates extraction logic behind a protocol ready for a future
    LLM-based extractor without touching task code.
  - Update _match_documents to accept AttributeExtractor instead of
    Processor directly.
  - Add ?sync=true query param to POST /api/analyze/: runs the task
    in-process and returns the completed AnalysisJobStatusSerializer
    payload with HTTP 200; async path unchanged (202 + job_id).
  - Register AnalysisJob with a read-only Unfold ModelAdmin so operators
    can inspect job queue and results without Postman.
  - Add tests for region extraction (crop used, empty-crop fallback,
    no-region fallback) and sync/async mode branching.
  - Fix test_handle_debug_true to assert both call_command calls
    (upgrade + demo_data) after develop command change.
…e media in dev

  - Embed image_src as hidden POST field so the canvas persists after
    "Save regions" without a full re-upload
  - Override submit_buttons_bottom block to suppress Django's default
    Save/Save and continue/Save and add another buttons on the
    define_regions action page
  - Add "Go back" link button returning to the Document change page
  - Serve MEDIA_URL via static() in DEBUG mode so uploaded analysis
    job images are accessible from the admin detail view
  Both OCRAttributeExtractor and _generic_fallback discarded the Match
  return value from find_single and returned the raw full-page OCR text
  as every attribute's extracted_value. The match.text field identifies
  where the attribute label appears in the OCR output; the fix locates
  that position and returns the first non-empty line that follows it,
  returning "" if the label is not found at all.
@domdinicola
domdinicola force-pushed the feature/archive-define-regions branch from 2a386db to ffa99c1 Compare October 26, 2026 07:15
@domdinicola
domdinicola merged commit adfafb4 into develop Oct 26, 2026
13 checks passed
@domdinicola
domdinicola deleted the feature/archive-define-regions branch October 26, 2026 07:16
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.

3 participants