SocialFinanceDigitalLabs / cs-demand-model-regional

CS Demand Model webapp for regional analysis
MIT License
0 stars 1 forks source link

feat: use middleware to replace router handler #132

Closed christina-moore closed 1 day ago

christina-moore commented 2 weeks ago

This update will remove the router_handler function and instead use a custom middleware. Middleware is applied to every request/response so now all views will have a session_scenario_id stored in the session.

views.py changes look extensive, but for each function all I did was remove the conditional that checks for the id in the session. Probably easiest to see those changes within this commit itself: https://github.com/SocialFinanceDigitalLabs/cs-demand-model-regional/commit/5f7c6c0af2ea32d5426858fc1a8bac59c0b35d23

Note: If there are no data uploads, the middleware will redirect the user to the home screen with a message: image

amynickolls commented 1 week ago

Should load_saved_scenario view be updated to use middleware to store session ID, I believe it's still using the old method?

christina-moore commented 1 week ago

Should load_saved_scenario view be updated to use middleware to store session ID, I believe it's still using the old method?

Hmm so the middleware can't be redirected to like other views. On each request made by a user, the middleware will "intercept" the request and then add it's logic. I think it's fine to still have load_saved_scenario set the scenario ID into the session directly - as long as the middleware isn't overwriting what load_saved_scenario is doing! So that's one to test for sure