V
V
Vic Shostak2018-02-10 15:05:08
Django
Vic Shostak, 2018-02-10 15:05:08

How not to lose data when submitting a form (view with LoginRequiredMixin) if the user is not authorized?

Good time of the year.
We set the task to make a tricky mechanism for sending an application from the site (about 10 fields) for users. Namely, if the visitor is NOT authorized, then direct him to the login and registration page (there are two forms side by side), but when he enters / registers, attach to him all the data that he filled out in the form.

A similar mechanism can be observed in almost all modern online stores (Yulmart, for example), when you first put everything in the basket, arrange delivery, choose a payment method, and only then they say - "now let's register or enter the site if you are already registered" and only after these actions - the order flies to the server as a "placed order".

I don't need code or (perhaps) pre-built libraries that do this out of the box. I will be glad at least for the algorithm (from production), use cases and / or advice from those who have implemented similar things on Django.
Also, I appeal to the Django-guru: please explain if I understand correctly, when an NOT authorized visitor goes to a view with LoginRequiredMixin(class-based), then you can pass not only nexta parameter for the URL, but also save it (in the session / cookies? ) any other data?
Perhaps this is the answer to my problem, but I want to hear a more authoritative opinion of Django practitioners, and not my own guesses :)

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tema_sun, 2018-02-10
@tema_sun

I would store the data from the form in localStorage as it is filled out, and after it was successfully submitted, I would clear the storage. It will also help in case of a page refresh by any user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question