ajlittoz
ajlittoz

Reputation: 454

Django: how to reset page URL in a post response?

EDIT 2024-01-12

Don't answer this question. It is probably nonsense. I experimented with Content-Location and behaviour is not what I expected. In addition, it probably varies with browser.

I'll go for a more classic management, identifying row from button name (O(n) unfortunately) and scanning columns.

I leave the question for the records (unless someone more knowledgeable than me recommends to delete it).

Context

Page displays a list of records (from a DB) where some columns are editable. One "cell" is supposed to contain a sum. Layout is something like this:

+----+-------+--------+--------+--------+---------------+
| id | name  | Price  |Packing |Shipping| Total fees    |
+----+-------+--------+--------+--------+---------------+
| 32 | Name1 | 150.25 | (0.00) | (1.00) | <Update> 0.00 | <Save>

| 47 | Name2 |  57.16 | (0.50) | (1.00) | <Update> 0.00 | <Save>
+----+-------+--------+--------+--------+---------------+
           <Cancel>  <Approve>

where (…) denotes an input field and <…> a button.

The goal is to be able to manually override what comes from the DB and, in case the row is not "approved" for the next step in the workflow, to save the overrides in the DB for later check.

<Update> button computes the sum of the fees. This should probably be handled by JavaScript, locally in the client.

<Save> requires a POST transaction. The button has a formaction= to return the row id for identification of which order to process. This means the URL is http://host/app/save/<rowid> while the page is initially queried by http://host/app.

It is "easy" to handle it in urls.py:

urlpatterns=[
  path('app', MyView.as_view(), name='current_list'),
  path('app/save/<id>', MyView.as_view(), name='patch_entry'),
]

When <Save> is pressed, post() receives all necessary information to handle the request. But if the response is sent with render(), the page URL displayed by the browser becomes http://host/app/save/<rowid>.

If another <Save> button is pressed, the browser sends request http://host/app/save/save/<rowid> which obviously fails. Similarly, if <Approve> is pressed, http://host/app/save/ is sent which corresponds to no pattern and fails.

Question

It looks like the response should be returned as a redirect. I don't like the idea because it causes a new GET which in its turn results in a new query on the DB though we had all information already processed.

Is there a way to "reset" the sent page URL to a "pristine" state when returning a response?

It is possible that I am completely wrong in my design. I am open to any suggestion simplifying processing.

Thanks in advance.

Upvotes: 0

Views: 53

Answers (0)

Related Questions