-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add user measurement system #1610
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.
This looks good, I just have a few small requests. See below.
cadasta/accounts/serializers.py
Outdated
@@ -73,6 +74,8 @@ class UserSerializer(SanitizeFieldSerializer, | |||
"email address") | |||
)] | |||
) | |||
measurement = ChoiceField(choices=next(zip(*settings.MEASUREMENTS)), |
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 think, this will work without next
and zip
@@ -0,0 +1,25 @@ | |||
# -*- coding: utf-8 -*- |
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.
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 change this migration file with a starting 0005_
so that it should be merged after #1569 with has a 0004_
instead.
cadasta/accounts/forms.py
Outdated
@@ -92,6 +93,15 @@ def clean_username(self): | |||
_("Username cannot be “add” or “new”.")) | |||
return username | |||
|
|||
def clean_measurement(self): | |||
measurements = next(zip(*settings.MEASUREMENTS)) |
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.
next
and zip
are not needed.
cadasta/accounts/forms.py
Outdated
@@ -92,6 +93,15 @@ def clean_username(self): | |||
_("Username cannot be “add” or “new”.")) | |||
return username | |||
|
|||
def clean_measurement(self): |
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.
You could define a ChoiceField
instead (similar to what you did with the serializer for the user language). Using the invalid_choice
keyword, you can also define a custom error message.
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.
Great. I tried this and it simplified a lot everything:
- no need at all of
def clean_measurement(self):
- no need to test the
ValidationError
raise withpytest
.
I am going to do the same thing for Add account user language #1569 -- In that PR I added a ChoiceField
only in the serializers.py
, not in forms.py
yet.
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.
Other than @oliverroick's comments on the code/migration it looks good to me. Minor point, but a manual test case should probably be added to the manual test case spreadsheet.
https://docs.google.com/spreadsheets/d/1JmKVAmdQgjdzg8YhrSDtfBtWckkv7aq4-ZIZCmwbbwU/edit?usp=sharing
6f67af2
to
8761a53
Compare
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.
👍
@bjohare I added 2 entries on the document: lines 10-11. One for changing language and one for changing measurement. I didn't know what to put in the column Link to test case in cadasta-test though. I placed these 2 lines close to similar test cases. I noticed that there isn't the compulsory step to enter the password before 5. Click "Update Profile". I figure the password field has been added recently. |
7d5dfcc
to
dd41bc1
Compare
@oliverroick and @bjohare could you please review this again? No code has been changed, I resolved all merging conflicts but along the process your reviews got dismissed. Cheers 👍 |
@laura-barluzzi yeah, the manual test case stuff is a little out of date.. We haven't been very good about updating the spreadsheet when submitting PR's. @seav is working on the |
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 looks fine. If we're going to be adding any more user profile stuff, eg profile pictures etc., we should consider breaking that out into a separate UserProfle
model with a 1:1
relationship with User
.
dd41bc1
to
44f5675
Compare
@bjohare sure. I noticed that again the review was dismiss when I rebased, squashed and pushed.. should I just avoid to squash commits from now on? |
@laura-barluzzi we still haven't settled on a decision about automatic v's manual review dismissal so I think its fine to keep rebasing |
44f5675
to
0cf22c9
Compare
0cf22c9
to
e2f88dd
Compare
Proposed changes in this pull request
This PR contains a migration. The migration file on this document starts as
'0005_'
, therefore it should be merged after PR #1569 (which in turns has a migration file starting as'0004_'
.This PR replicates almost entirely the features in PR #1569 and is part of the epic issue User Dashboard #1491.
settings/default.py
I created global variables for available measurement systems and a default one. In this way it is easy to make future additions and/or changes to the available options.In accounts/models.py
I created a field where to store the preferred choice (or the default) value.accounts/tests/test_forms.py
I added the measurement field wherever it was required and inside the existing functiondef test_update_user
in order to test when the value is valid.accounts/tests/test_forms.py
I addeddef test_update_user_with_invalid_measurement
.ChoiceField
in theserializers.UserSerializer
classaccounts/tests/test_serializers.py
When should this PR be merged
As soon as it has been reviewed.
Risks
0004_
, the same as the migration file in PR Add account user language #1569.Follow-up actions
Checklist (for reviewing)
General
migration
label if a new migration is added.Functionality
Code
Tests
Security
Documentation