Skip to content

Commit 83c539a

Browse files
authored
Add update_view_url to object_form context (#93)
The object_form.html template referenced update_view_url but it was never added to the view context.
1 parent 0dd67fa commit 83c539a

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

docs/source/templates.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,30 @@ See ``python manage.py mktemplate --help`` for full details.
6464

6565
Used for both the create and update views.
6666

67-
``neapolitan/object_list.html``
67+
``neapolitan/object_form.html``
6868

6969
Context variables:
7070

71-
* ``object``: the object being updated, if present.
71+
* ``object``: the object being updated (for the update view)
7272
* ``object_verbose_name``: the verbose name of the object, e.g. ``bookmark``.
7373
* ``form``: the form.
7474
* ``create_view_url``: the URL for the create view.
7575
* ``update_view_url``: the URL for the update view.
7676

77+
``object_list.html``
78+
--------------------
79+
80+
Used for the list view.
81+
82+
``neapolitan/object_list.html``
83+
84+
Context variables:
85+
86+
* ``object_list``: the list of objects.
87+
* ``object_verbose_name``: the verbose name of the object, e.g. ``bookmark``.
88+
* ``object_verbose_name_plural``: the plural verbose name, e.g. ``bookmarks``.
89+
* ``create_view_url``: the URL for the create view.
90+
7791
``object_confirm_delete.html``
7892
------------------------------
7993

src/neapolitan/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ def get_context_data(self, **kwargs):
378378

379379
if getattr(self, "object", None) is not None:
380380
kwargs["object"] = self.object
381+
kwargs["update_view_url"] = Role.UPDATE.maybe_reverse(self, self.object)
381382
context_object_name = self.get_context_object_name()
382383
if context_object_name:
383384
kwargs[context_object_name] = self.object

tests/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_update(self):
136136
# Load the form.
137137
response = self.client.get(update_url)
138138
self.assertEqual(response.status_code, 200)
139+
self.assertContains(response, f'action="/bookmark/{self.homepage.pk}/edit/"')
139140

140141
# Submit the form.
141142
response = self.client.post(

0 commit comments

Comments
 (0)