Django half filled forms - python

How do i save a half filled form?
eg: User logs in and registers for a service. Remembers that some scanned docs are missing. Saves the form for completion at a later date. Comes back completes it and submits it.
Solutions I came up with
I can set the required field to False and save the half filled form to DB. But that defeats the purpose of required fields.
I can save the half filled data in a seperate table. Migrate to the actual table once validating passes.
However for something so simple does Django not already have inbuilt functionalities.
If I am missing some term here that I should be googling point me in the right direction.
Django 1.6
Python 2.7

the easiest way to do this is to store the data posted and save it in the user session.
eg.
form_state = request.POST.copy()
request.session['form_state'] = form_state
Something similar is done by form form wizard (https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/)

Related

How to make Django Form repeatedly submit in background while user is filling it in?

Background information about my project:
I'm building a CV/Resume generator that automatically creates a CV/Resume based on the user filling out a form. I'm using a Django Crispy Form which has a submit button at the end that, when clicked, submits the user's input to a SQL database and redirects the user to their newly built CV/Resume (as a PDF).
What I need help with:
The goal is to have a form on the left side of the screen and a live view (HTML/CSS) of the CV/Resume on the right side, where the live view updates as the user is filling out the form.
I've seen this kind of thing before, but never for a Django project (they tend to use JavaScript/React).
What I'm thinking:
Could I have a background process that does something like, when the user makes a change (e.g. is filling out the form), submit any new inputs to the SQL database every 5 seconds? Then the live view can extract any new inputs from the database and display it in real time?
It might be possible to do something like that with ajax requests, but I wouldn't recommend it. It would be better to render a simulation of it in the browser with javascript html and css. That way you avoid many many needless post requests before the user is ready to submit the form.

How do I cache form data in Django?

I'm creating a single page application in Django.
It mainly consists of multiple, small forms that are filled in and validated independent from each other. Every form looks similar to this:
With a final button press at the end though, the input of all those forms should be processed together.
How can I save/cache all data of the submitted forms to process them with a final form submit at the end?
I tried creating only one big form, but then I can't validate each field one after the other, when the user clicks the 'Next' button.
If you want to have a form spread across multiple pages with multiple request/response cycles I'd probably recommend storing it either in the session or in the database. The session is probably easier whereas the database approach is more sophisticated. You can store items in the session using request.session['step_1'] = {} for example.

Option to add extra choices in django form

I am trying to create a model via a form that has multiple other models related to it. Say I have a model Publisher, then another model Article with a foreign key to Publisher. When creating a Publisher via a form, I want to create An article at the same time. I know how to do this via formsets. However, I don't know how to add a button that says add extra article at the same view, without having to be redirected to a new page and losing the old data since the form was not saved. What I want is when someone clicks add new article, for a new form for article to appear and for the user to add a new Article. Is this possible to be done in the same view in django, if so can someone give me and idea how to approach this?
I would show code or my attempts, but I am not sure how to even approach it.
This can only be done using JavaScript. The hard part is to have the management form sync up with the number of rows.
But there's two alternatives:
Semi-javascript (Mezzanine's approach): Generate a ton of rows in the formset and only show one empty. Upon the click of the "add another row" button, unhide the next one. This makes it easier to handle the management form as the unfilled extra's don't need any work.
No fix needed: Add as many rows as is humanly sane. In general, people don't need 40 rows, they get bored with filling out the form or worry that all that work is lost when the browser crashes.
Hope this helps you along. Good luck!

Django : Storing user steps with django admin form

I am doing a workflow app that forces the users to go through a set of forms and save some data.
They can leave the process of filling that form and log-out at any point of time.
When they log in back, they should be redirected to the same form/page where they left last time.
What is the best way to approach this problem ? Should I have a model in this app which stores such data every step ?
UPDATE:
By form I mean admin forms.
Django form wizard is what you want.
You can use SessionWizardView for more easily display the wizard when user comes back again.

Django FormPreview - What is it for?

While looking across the Django documentation, I came across the FormPreview.
The description says this:
Django comes with an optional “form preview” application that helps automate the following workflow:
“Display an HTML form, force a preview, then do something with the submission.”
What is meant by "force a preview"? What would you use this feature for an in application?
To force a preview means the users are forced to see the value they have inserted on the form input fields, before django actually saves it to the database.
One example is django comment system, which enforce the users to take a look at the comment they have written before django actually saves it to the database. You would see that the users are redirected to another page to take a look at their comment, and after that there is a submit button to actually save the comment.
I think they mean (I use django but I didn't know of this until now..) that you can let people write, for example in a textarea box like I'm doing right now. After the user submits it the system would preview it to the user and give him the chance to read and edit what he submitted, before it being submitted again all the way to the database.

Categories