Skip to content

feat/t26 add view save first notice - #23

Merged
metaforx merged 2 commits into
mainfrom
feat/t26-add-view-save-first-notice
Apr 23, 2026
Merged

feat/t26 add view save first notice#23
metaforx merged 2 commits into
mainfrom
feat/t26-add-view-save-first-notice

Conversation

@metaforx

@metaforx metaforx commented Apr 23, 2026

Copy link
Copy Markdown
Owner
  • add save notice for form actions

Summary by Sourcery

Add save-first guidance to the form add view for form elements and handlers, and wire it into the Unfold admin inlines.

New Features:

  • Show add-view info cards in the Form elements and Form handlers tabs explaining that the form must be saved before elements or handlers can be added.

Enhancements:

  • Wire custom Unfold tabular templates into form element and form handler inlines to display contextual guidance on the add view.
  • Increment the package version to 0.1.13 and add an internal task description file for this feature.

Tests:

  • Add regression tests asserting that save-first notices appear on the add view and are absent on the change view.

@sourcery-ai

sourcery-ai Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds Unfold card-based informational notices to the FormEntry add view explaining that form elements and form handlers are only available after saving, wires these via custom inline templates, and introduces tests to assert the notice presence on add view and absence on change view, along with a patch version bump and locale updates.

Sequence diagram for FormEntry add view inline notice behavior

sequenceDiagram
    actor AdminUser
    participant DjangoAdmin
    participant FormEntryAddView
    participant FormElementsInlineTemplate
    participant FormHandlersInlineTemplate

    AdminUser->>DjangoAdmin: Request FormEntry add view
    DjangoAdmin->>FormEntryAddView: Dispatch add view
    FormEntryAddView-->>DjangoAdmin: Context with add = True
    DjangoAdmin->>FormElementsInlineTemplate: Render form_elements_tabular.html
    FormElementsInlineTemplate-->>FormElementsInlineTemplate: Include admin/edit_inline/tabular.html
    FormElementsInlineTemplate-->>FormElementsInlineTemplate: Check add flag
    alt add is True
        FormElementsInlineTemplate-->>FormElementsInlineTemplate: Render Unfold card notice
    end
    DjangoAdmin->>FormHandlersInlineTemplate: Render form_handlers_tabular.html
    FormHandlersInlineTemplate-->>FormHandlersInlineTemplate: Include admin/edit_inline/tabular.html
    FormHandlersInlineTemplate-->>FormHandlersInlineTemplate: Check add flag
    alt add is True
        FormHandlersInlineTemplate-->>FormHandlersInlineTemplate: Render Unfold card notice
    end
    DjangoAdmin-->>AdminUser: HTML with tabs and save-first notices on active tab
Loading

Flow diagram for inline template rendering of save-first notices

flowchart TD
    A[Render_FormElementEntryInline_or_FormHandlerEntryInline] --> B[Load_corresponding_tabular_template]
    B --> C[Include_admin_edit_inline_tabular_template]
    C --> D{Is_add_flag_true_for_FormEntry?}
    D -- Yes_add_view --> E[Render_full_width_Unfold_card_notice]
    E --> F[Bind_card_visibility_to_activeTab_matching_inline_prefix]
    F --> G[Return_HTML_with_info_card_on_add_view]
    D -- No_change_view --> H[Do_not_render_save_first_notice]
    H --> I[Return_standard_inline_rows_on_change_view]
Loading

File-Level Changes

Change Details Files
Introduce Unfold card-based notices on the add view for form elements and form handlers inlines, only visible when adding a new form entry.
  • Create custom tabular inline templates for form elements and form handlers that include the default Django admin tabular inline markup plus an Unfold card-based info message.
  • Conditionally render the notice card only when the admin is in add mode using the add context variable and the activeTab state for the corresponding inline tab.
  • Use internationalized strings for the notice title and instructions about saving first and using 'Save and continue editing' before opening the relevant tab.
src/unfold_fobi/templates/admin/unfold_fobi/edit_inline/form_elements_tabular.html
src/unfold_fobi/templates/admin/unfold_fobi/edit_inline/form_handlers_tabular.html
Wire the new inline templates into the existing admin inlines for form elements and form handlers.
  • Set the template attribute on FormElementEntryInline to point to the new form_elements_tabular.html template.
  • Set the template attribute on FormHandlerEntryInline to point to the new form_handlers_tabular.html template.
src/unfold_fobi/admin/inlines.py
Add regression tests to verify that the save-first notices appear on the add view but not on the change view.
  • Extend the add view tests to assert that the expected notice texts for form elements and form handlers are present on the add view response.
  • Add a test for the change view that asserts the notices are not rendered when editing an existing form entry.
  • Use get_admin_add_url and get_admin_edit_url helpers to fetch the correct admin endpoints.
tests/admin/test_add_view.py
Update project metadata and localization artifacts to reflect the new feature.
  • Bump the library version from 0.1.12 to 0.1.13.
  • Update or regenerate the English and German django.po files to include translations for the new notice strings.
src/unfold_fobi/__init__.py
src/unfold_fobi/locale/en/LC_MESSAGES/django.po
src/unfold_fobi/locale/de/LC_MESSAGES/django.po
Document the implementation details and acceptance criteria for the add-view save-first notice feature.
  • Add an internal task specification file describing the goal, scope, implementation requirements, and tests for the new add-view notices.
.agents/tasks/T26_add_view_save_first_notice_for_form_elements.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 1 issue, and left some high level feedback:

  • The new add-view tests for the notice rely on the literal "tabular-table" class and exact message strings in the rendered HTML, which makes them quite brittle against template or copy changes; consider asserting on more stable structure or IDs, or scoping the checks to the new card container instead.
  • The two new inline templates for form elements and form handlers are nearly identical apart from the messages, so it may be worth extracting a shared partial or macro/component to avoid duplication and keep future styling or behavioral changes in one place.
  • Since the notices are wrapped in x-show="activeTab == ...", it might be useful to add a small comment in the templates explaining the expectation about the activeTab Alpine state, to make the dependency on the surrounding tab implementation clearer to future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new add-view tests for the notice rely on the literal `"tabular-table"` class and exact message strings in the rendered HTML, which makes them quite brittle against template or copy changes; consider asserting on more stable structure or IDs, or scoping the checks to the new card container instead.
- The two new inline templates for form elements and form handlers are nearly identical apart from the messages, so it may be worth extracting a shared partial or macro/component to avoid duplication and keep future styling or behavioral changes in one place.
- Since the notices are wrapped in `x-show="activeTab == ..."`, it might be useful to add a small comment in the templates explaining the expectation about the `activeTab` Alpine state, to make the dependency on the surrounding tab implementation clearer to future maintainers.

## Individual Comments

### Comment 1
<location path="tests/admin/test_add_view.py" line_range="41-45" />
<code_context>
+            "Save this form first to add form elements."
+        )
+
+    def test_change_view_does_not_render_add_notice(self, admin_client, form_entry):
+        response = admin_client.get(get_admin_edit_url(form_entry.pk))
+        content = response.content.decode()
+        assert "Save this form first to add form elements." not in content
+        assert "Save this form first to add form handlers." not in content
+

</code_context>
<issue_to_address>
**suggestion (testing):** Also assert the change view status code to strengthen the regression check

As with the add-view test, please also assert `response.status_code == 200` so this regression test confirms the notices are absent on a successful change view, not on an unexpected redirect or 404.

```suggestion
    def test_change_view_does_not_render_add_notice(self, admin_client, form_entry):
        response = admin_client.get(get_admin_edit_url(form_entry.pk))
        assert response.status_code == 200
        content = response.content.decode()
        assert "Save this form first to add form elements." not in content
        assert "Save this form first to add form handlers." not in content
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +41 to +45
def test_change_view_does_not_render_add_notice(self, admin_client, form_entry):
response = admin_client.get(get_admin_edit_url(form_entry.pk))
content = response.content.decode()
assert "Save this form first to add form elements." not in content
assert "Save this form first to add form handlers." not in content

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.

suggestion (testing): Also assert the change view status code to strengthen the regression check

As with the add-view test, please also assert response.status_code == 200 so this regression test confirms the notices are absent on a successful change view, not on an unexpected redirect or 404.

Suggested change
def test_change_view_does_not_render_add_notice(self, admin_client, form_entry):
response = admin_client.get(get_admin_edit_url(form_entry.pk))
content = response.content.decode()
assert "Save this form first to add form elements." not in content
assert "Save this form first to add form handlers." not in content
def test_change_view_does_not_render_add_notice(self, admin_client, form_entry):
response = admin_client.get(get_admin_edit_url(form_entry.pk))
assert response.status_code == 200
content = response.content.decode()
assert "Save this form first to add form elements." not in content
assert "Save this form first to add form handlers." not in content

@metaforx
metaforx merged commit 19844f1 into main Apr 23, 2026
4 checks passed
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.

1 participant