Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto populate fields if user already filled them in (if they go back in application) #8

Open
mpbrown opened this issue Oct 25, 2019 · 2 comments

Comments

@mpbrown
Copy link
Member

mpbrown commented Oct 25, 2019

User input is stored in request.session dictionary before being submitted to the database. Access keys by request.session[key_name] in .py files and by {{ request.session.key_name }} in .html files

@MrEvertide
Copy link

Hi!

I would like to help out with this issue, would it be possible to list the particular forms I need to update? From what I can see it's all in the users/templates directory, right?

I assume we wouldn't want to do anything with passwords or sensitive information.

Thanks,

@mpbrown
Copy link
Member Author

mpbrown commented Oct 28, 2019

Hi Cédric, glad to hear you'd like to help out!

I believe most of it can be done right in pathways/views.py. Since we're using Django class-based views and specifically FormView, we can override the get_initial function and pass in sessions values if they exist.

Here's what I came up with for overriding it in HouseholdView

class HouseholdView(FormView):
    template_name = 'pathways/apply/household-size.html'
    form_class = forms.HouseholdForm
    success_url = '/apply/household-benefits/'

    def get_initial(self):
        initial = super(HouseholdView, self).get_initial()
        if 'household' in self.request.session:
            initial['household'] = self.request.session['household']
        return initial

Let me know if you come across any parts of the repo that are unclear and could do with some additional documentation.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants