The publication importer (importer_publikacji) allowed creating chapters
(Wydawnictwo_Zwarte records with charakter_formalny.charakter_ogolny == "roz")
without a parent publication (wydawnictwo_nadrzedne). This created orphan chapter
records — chapters that don't belong to any book — which violates the data model's
semantic constraint. The bug was triggered by BibTeX imports of @inbook/@incollection
entries, where the importer's source step (step 3) had no UI for selecting a parent
publication.
- Added two nullable ForeignKey fields to
ImportSession:wydawnictwo_nadrzedne→bpp.Wydawnictwo_Zwartewydawnictwo_nadrzedne_w_pbn→pbn_api.Publication
- New migration adding both FK fields to
ImportSession.
- Added
wydawnictwo_nadrzedneandwydawnictwo_nadrzedne_w_pbnModelChoiceFieldfields toSourceForm(bothrequired=False, conditional validation in view).
- Added
_is_chapter()helper to detect chapters bycharakter_ogolny. - Modified
_source_context()to passis_chapterflag and parent publication objects for Select2 pre-population. - Modified
SourceView.post()to validate that chapters have exactly one parent publication (either BPP or PBN, not both, not neither). - Modified
_create_wydawnictwo_zwarte()to setwydawnictwo_nadrzedneand/orwydawnictwo_nadrzedne_w_pbnon the created record.
- Added conditional UI block for chapters: shows two Select2 autocomplete fields for parent publication selection (BPP book or PBN publication).
- Added JavaScript to initialize Select2 AJAX on both fields using existing
autocomplete URLs (
wydawnictwo-nadrzedne-autocomplete,wydawnictwo-nadrzedne-w-pbn-autocomplete).
- Added display of parent publication in the review step summary table.
- Start the development server and open the publication importer.
- Import a BibTeX
@inbookor@incollectionentry. - On step 2 (Verify), confirm the charakter formalny is set to a chapter type.
- On step 3 (Source), verify:
- The parent publication section appears with "Rozdział wymaga wydawnictwa nadrzędnego" callout.
- Two Select2 fields are shown: "Wydawnictwo nadrzędne (BPP)" and "Wydawnictwo nadrzędne (PBN)".
- Attempting to proceed without selecting a parent shows validation error.
- Selecting both a BPP and PBN parent shows mutual exclusivity error.
- Selecting exactly one parent allows proceeding.
- On step 5 (Review), verify the parent publication appears in the summary.
- After creation, verify the
Wydawnictwo_Zwarterecord haswydawnictwo_nadrzedneset correctly. - Import a regular book (non-chapter) and verify step 3 does NOT show the parent publication fields.