-
Notifications
You must be signed in to change notification settings - Fork 6
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
Ks 2022 01 store token in session #4134
Conversation
Coverage reportTotal coverage
Report generated by 🧪jest coverage report action from cb763fe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
So, now the token is only shown when it matches the module? And when I go to another budgeting, the token is not shown, but overwritten when I add a new one? I will try that out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get an error, when I add a proposal while the voting phase is active. Probably not because of this PR. Will investigate later and also maybe still merge as that is an admin-edge-case anyway.
Template error:
In template /home/katharina/a4-meinberlin/meinberlin/templates/base.html, error at line 0
local variable 'token' referenced before assignment
1 : <!DOCTYPE html>
2 : {% load i18n static contrib_tags wagtailuserbar %}
3 : {% get_current_language as LANGUAGE_CODE %}
4 : <html lang="{{ LANGUAGE_CODE }}">
5 : <head>
6 : <meta charset="utf-8" />
7 : <meta http-equiv="X-UA-Compatible" content="IE=edge" />
8 : <title>{% block title %}{% trans 'meinBerlin' %}{% endblock %}</title>
9 : <link rel="shortcut icon" type="image/x-icon" href="{% static 'images/favicon.ico' %}?v=2" />
10 : {% block extra_css %}
Traceback (most recent call last):
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
response = response.render()
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
return template.render(context, self._request)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 170, in render
return self._render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/library.py", line 192, in render
output = self.func(*resolved_args, **resolved_kwargs)
File "/home/katharina/a4-meinberlin/meinberlin/apps/budgeting/templatetags/react_proposals_vote.py", line 40, in react_proposals_vote
serializer = VotingTokenSerializer(token)
Exception Type: UnboundLocalError at /budgeting/2022-00040/
Exception Value: local variable 'token' referenced before assignment
@fuzzylogic2000 Oh no, I think the problem is, that I was only handling the API View, but not the normal list view with the form.. so I'll look into it! |
@Rineee I found out more: it happens when there is a token in the session and you try to add a proposal in another module not belonging to that token. |
…o it token is present
bf557b5
to
cb763fe
Compare
Now it should be like that, yes! See updated PR description :) |
@fuzzylogic2000 The error should be fixed by commit 4! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supercool!
This now stores the token itself in the session instead of its pk which is probably safer!
When there are several modules with possible tokens, the token form is shown if the token in the session is not valid for this module. Once another token is entered, this one is saved and the old one removed. When testing this (so you entered a token in module 2 and want to make sure that the token in module 1 is removed), be careful that you dont just reload the page, because that will resend the token form in module 1 and thus the old token is there again. Hope that makes sense 🙈
This behaviour is not ideal, but I guess fine for an itenmediate step?