-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix/refactor choices #586
Fix/refactor choices #586
Conversation
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.
Nice, this makes my brain very happy.
Didn't do a full test or anything, but did do a double check if you got everything. I found 4 issues; I provided change-suggestions for you as easy fixes. If you fix them, it's approved :)
The other comments are just suggestions :)
I removed DESIGNS from the Studies model entirely, as these seem to not be used anywhere.
I did try to see if they were ever used, as far as I can tell they never were... At least not for 7 years lol.
reviews/utils/review_utils.py
Outdated
@@ -338,7 +338,7 @@ def auto_review(proposal: Proposal): | |||
if study.legally_incapable: | |||
reasons.append(_('De aanvraag bevat het gebruik van wilsonbekwame volwassenen.')) | |||
|
|||
if study.deception in [YES, DOUBT]: | |||
if study.deception in [YesNoDoubt.YES, DOUBT]: |
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.
if study.deception in [YesNoDoubt.YES, DOUBT]: | |
if study.deception in [YesNoDoubt.YES, YesNoDoubt.DOUBT]: |
reviews/utils/review_utils.py
Outdated
@@ -353,11 +353,11 @@ def auto_review(proposal: Proposal): | |||
for task in Task.objects.filter(session__study=study): | |||
reasons.extend(auto_review_task(study, task)) | |||
|
|||
if study.stressful in [YES, DOUBT]: | |||
if study.stressful in [YesNoDoubt.YES, DOUBT]: |
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.
if study.stressful in [YesNoDoubt.YES, DOUBT]: | |
if study.stressful in [YesNoDoubt.YES, YesNoDoubt.DOUBT]: |
reviews/utils/review_utils.py
Outdated
reasons.append(_('De onderzoeker geeft aan dat (of twijfelt erover of) het onderzoek op onderdelen of \ | ||
als geheel zodanig belastend is dat deze ondanks de verkregen informed consent vragen zou kunnen oproepen.')) | ||
|
||
if study.risk in [YES, DOUBT]: | ||
if study.risk in [YesNoDoubt.YES, DOUBT]: |
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.
if study.risk in [YesNoDoubt.YES, DOUBT]: | |
if study.risk in [YesNoDoubt.YES, YesNoDoubt.DOUBT]: |
reviews/models.py
Outdated
self.continuation, | ||
self.continuation | ||
) | ||
continuation = dict(self.Continuations.choices)[self.continuation] |
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.
continuation = dict(self.Continuations.choices)[self.continuation] | |
continuation = self.Continuations(self.continuation).label |
This is the proper way to get the label for a choice :)
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.
Ahh, I knew something like this had to be possible! Glad to know the syntax.
proposals/utils/pdf_diff_logic.py
Outdated
from main.models import YesNoDoubt | ||
|
||
d = dict(YES_NO_DOUBT) | ||
d = dict(YesNoDoubt.choices) | ||
return d[value] |
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.
No need for the dict cast:
from main.models import YesNoDoubt
return YesNoDoubt(value).label
reviews/forms.py
Outdated
@@ -102,7 +102,7 @@ def __init__(self, *args, **kwargs): | |||
allow_long_route_continuation = kwargs.pop('allow_long_route_continuation', False) | |||
super(ReviewCloseForm, self).__init__(*args, **kwargs) | |||
if not allow_long_route_continuation: | |||
self.fields['continuation'].choices = [x for x in Review.CONTINUATIONS if x[0] != Review.LONG_ROUTE] | |||
self.fields['continuation'].choices = [x for x in Review.Continuations.choices if x != Review.Continuations.LONG_ROUTE] |
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.
This does not work?:
>>> [x for x in Review.Continuations.choices if x != Review.Continuations.LONG_ROUTE]
[(0, 'Goedkeuring door FETC-GW'), (1, 'Revisie noodzakelijk'), (2, 'Afwijzing door FETC-GW'), (3, 'Open review met lange (4-weken) route'), (4, 'Laat opnieuw beoordelen door METC'), (5, 'Positief advies van FETC-GW, post-hoc'), (6, 'Negatief advies van FETC-GW, post-hoc'), (7, 'Niet verder in behandeling genomen')]
I think it should be this:
self.fields['continuation'].choices = [x for x in Review.Continuations.choices if x != Review.Continuations.LONG_ROUTE] | |
self.fields['continuation'].choices = [x for x in Review.Continuations.choices if x[0] != Review.Continuations.LONG_ROUTE] |
As for a better solution: there isn't any really that's clearly better. One alternative is a filter:
filter(lambda x: x[0] != Review.Continuations.LONG_ROUTE, Review.Continuations.choices)
But that's not really that much better.
You could also create a method in the new class to do the list comprehension there, but for this one usage that does not make much sense
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'm sorry. I just assumed ... Too bad that does not work. I just used your first suggestion.
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.
Nice, I like the new choices. I reviewed as follows:
- Ran tests
- Tried to make a pdf
- Migrated from scratch and loaded all fixtures
- Finally, pointed out all the places my IDE told me there were undefined variables like
DOUBT
andNO_WMO
I found a few issues, mainly from the final step.
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.
Missed a couple of model.wmo.NO_WMO
instances on lines 1017 and 1022
reviews/tests.py
Outdated
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.
Found some unchanged doubts and no's on lines 18 and 32.
These flagged up in python manage.py test
. Usually you would see this in the PR on Github as well, but it seems there's some issue with the runners right now. If this persists/happens again you can always run the tests locally to check.
proposals/tests.py
Outdated
wmo = Wmo.objects.create(proposal=proposal, metc=YES) | ||
self.assertEqual(proposal.wmo.status, Wmo.WAITING) | ||
wmo = Wmo.objects.create(proposal=proposal, metc=YesNoDoubt.YES) | ||
self.assertEqual(proposal.wmo.status, Wmo.WMOStatuses.WAITING) | ||
wmo.metc = NO |
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.
Stubborn metc just can't take NO
for an answer.
proposals/tests.py
Outdated
@@ -279,22 +279,22 @@ def setUp(self): | |||
self.wmo = Wmo.objects.create(proposal=self.p1, metc=NO) |
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.
Undefined NO
proposals/views/wmo_views.py
Outdated
is_metc = request.POST.get('metc') == YES | ||
is_medical = request.POST.get('medical') == YES | ||
is_metc = request.POST.get('metc') == YesNoDoubt.YES | ||
is_medical = request.POST.get('medical') == YesNoDoubt.YES | ||
|
||
doubt = request.POST.get('metc') == DOUBT or request.POST.get('medical') == DOUBT |
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.
Undefined DOUBT
Fixes #580. Refactoring all the choices in the models to use Django's special enumeration types. Had to change the code in lots of places, but really nothing major has happened. The most important changes happened in the models. When performing
makemigrations --dry-run
no changes are detected. A few things to pay attention to:DESIGNS
from theStudies
model entirely, as these seem to not be used anywhere.get_continuation_display()
. Again, this works, but I wonder if there could be a better solution?Review.SUPERVISOR
, but:Review.Stages.SUPERVISOR
choices = STAGES
, butchoices = self.Stages.choices
in models orReview.Stages.choices
in formsImport YES, NO, DOUBT, YES_NO_DOUBT
, butimport YesNoDoubt