Skip to content

Bugfix user birth day has no limit#231

Merged
kbeker merged 6 commits intomasterfrom
bugfix-user-birth-day-has-no-limit
May 27, 2019
Merged

Bugfix user birth day has no limit#231
kbeker merged 6 commits intomasterfrom
bugfix-user-birth-day-has-no-limit

Conversation

@dybi
Copy link
Contributor

@dybi dybi commented May 24, 2019

resolves:
#225

Copy link
Contributor

@kbeker kbeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally OK, but strings refactoring should have separate commit because it is not related with adding validation. Please divide this commit to two and ready to merge :)

@kbeker
Copy link
Contributor

kbeker commented May 24, 2019

@dybi Also please remember when you are creating PR, please add milestone, projects, label and assign yourself to this PR. Same thing please do with issue which is related to this PR. :)


def setUp(self):

super().setUp()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -1,46 +1,44 @@
# pylint: disable=line-too-long
from django.utils.translation import ugettext_lazy
from django.utils.translation import ugettext_lazy as _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

raise serializers.ValidationError(CustomValidationErrorText.VALIDATION_ERROR_SIGNUP_EMAIL_MESSAGE)
return email

def validate_date_of_birth(self, date_of_birth: datetime.date) -> datetime.date: # pylint: disable=no-self-use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done directly on CustomUser.date_of_birth field as validators=[MaxValidator(), MinValidator] (https://docs.djangoproject.com/en/2.2/ref/validators/#maxvaluevalidator). This way we control it on lowest possible level in the app and don't have to worry about it anywhere else. If for some reason it won't work there, then clean() method of the model. The case is that we want to remove all remaining of django-rest-framework so this serializer will be removed soon, and we shouldn't loose this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwrzesien Ok, I will move it, but ther's a problem with MinValueValidator / MaxValueValidator. Namely, the min and max value are not set in stone, they depend on the current date (for example, if yesterday user was not 18 years old validation should rasie exception, but if today user turned 18, it should pass).

I will create a custom validator and use it in model.

@rwrzesien
Copy link
Contributor

@dybi Looks good, please just move the check to model instead of serializer, as it will be removed soon.

@dybi dybi self-assigned this May 27, 2019
@dybi dybi added the bug Something isn't working label May 27, 2019
@dybi dybi added this to the Next release milestone May 27, 2019
@dybi dybi force-pushed the bugfix-user-birth-day-has-no-limit branch from 5e47c0a to fbde5a7 Compare May 27, 2019 12:33
Piotr Dybowski added 5 commits May 27, 2019 14:36
- introduce setup
- reduce code duplication
- remove unnecessary / unused code
- improve asserts (add descriptive message)
- use `_` as shortcut for `ugettext_lazy
- add `VALIDATION_ERROR_AGE_NOT_ACCEPTED`
- delete user's age validation from serializers
- add `UserAgeValidator` to `CustomUser` model for `date_of_birth` field
- adapt `UserAgeValidator` model's tests
@dybi dybi force-pushed the bugfix-user-birth-day-has-no-limit branch from fbde5a7 to 25cc3bf Compare May 27, 2019 12:37
@kbeker kbeker merged commit e62ad3c into master May 27, 2019
@kbeker kbeker deleted the bugfix-user-birth-day-has-no-limit branch May 27, 2019 12:50
@kbeker kbeker modified the milestones: Next release, v0.3.0 May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants