-
Notifications
You must be signed in to change notification settings - Fork 295
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
Added local-flavor support for Cuba #292
Conversation
Thanks for this pull request. You can rebase with master to fix the failing test. I made a mistake removing the Python 3.4 / master test config in Travis but it should be fixed now. Let me know when this is ready for a review. |
Codecov Report
@@ Coverage Diff @@
## master #292 +/- ##
==========================================
- Coverage 96.28% 96.25% -0.04%
==========================================
Files 152 156 +4
Lines 4230 4351 +121
Branches 579 585 +6
==========================================
+ Hits 4073 4188 +115
- Misses 98 102 +4
- Partials 59 61 +2
Continue to review full report at Codecov.
|
Hi! @benkonrath , thanks for your suggestion. I made the rebase and finally all checks have passed. This PR is ready for review. In few days i'll take some time to ensure 100% of the coverage of localflavor/cu/forms.py. |
I noticed that some of my commits are now included in this PR which probably isn't what you were intending. You should do a Here's a guide I found that might be helpful: |
ohh! yes I see, thanks for the suggestion, I'll try ti fix that. Thanks for the suggestion @benkonrath ... |
Python 3.2 is no longer supported for Django 1.8 and above.
The next version of Django (2.0) will not support Python 3.4.
six has been removed since the version from django.utils is used in localflavor.
eb80be1
to
d4ff9a0
Compare
Hi! @benkonrath I organized the commits. |
Sorry for the delay in getting to this. I'll be able to do a review early next week. |
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.
Thanks again for this. There are a couple of changes needed then it be good go.
docs/changelog.rst
Outdated
@@ -6,7 +6,8 @@ Changelog | |||
|
|||
New flavors: | |||
|
|||
- None | |||
- Added local flavor for Ukraine |
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.
Ukraine -> Cuba
localflavor/cu/forms.py
Outdated
return value.strip() | ||
|
||
|
||
class CUPhoneNumberField(RegexField): |
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.
localflavor
has deprecated all phone number fields in favour of https://github.com/stefanfoulis/django-phonenumber-field. The CUPhoneNumberField
form field shouldn't be included in this PR.
localflavor/cu/models.py
Outdated
return super(CUIdentityCardNumberField, self).formfield(**defaults) | ||
|
||
|
||
class CUPhoneNumberField(CharField): |
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.
The CUPhoneNumberField
should also not be included.
localflavor/cu/forms.py
Outdated
|
||
def clean(self, value): | ||
super(CURegionField, self).clean(value) | ||
if value in EMPTY_VALUES: |
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.
EMPTY_VALUES -> self.empty_values
The same applies to CUProvinceField
localflavor/cu/forms.py
Outdated
return '' | ||
try: | ||
value = value.strip().lower() | ||
except AttributeError: |
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.
As far as I can see you don't need to catch an AttributeError
here.
The same applies to CUProvinceField
super(CUPostalCodeField, self).__init__(r'^[1-9]\d{4}$', *args, **kwargs) | ||
|
||
def to_python(self, value): | ||
value = super(CUPostalCodeField, self).to_python(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.
You need to add localflavor.compat.EmptyValueCompatMixin
to this class and add this python code:
if value in self.empty_values:
return value
This comes from a recent change that was made to properly support Django >= 1.11 (#298). You can search through the other localflavor modules to see examples of how to set this up if you're not sure.
localflavor/cu/forms.py
Outdated
|
||
def to_python(self, value): | ||
value = super(CUIdentityCardNumberField, self).to_python(value) | ||
return value.strip() |
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 also needs to use the EmptyValueCompatMixin
as explained above.
localflavor/cu/forms.py
Outdated
def __init__(self, *args, **kwargs): | ||
super(CUIdentityCardNumberField, self).__init__(r'^\d{11}$', *args, **kwargs) | ||
|
||
def _set_regex(self, regex): |
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 shouldn't override _set_regex
. Either use CharField
and set the CUIdentityCardNumberValidator
using the validators
arg in __init__()
or use the RegexField
like you do now and check the date in clean()
after calling super
instead of using the CUIdentityCardNumberValidator
.
localflavor/cu/models.py
Outdated
return name, path, args, kwargs | ||
|
||
|
||
class CUZipCodeField(CharField): |
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.
ZipCode -> Postal Code
The description also needs to be changed.
Hi @benkonrath , sorry for the delay. I updated the code with all your suggestions. Thanks for your time :) , if you have another question/suggestion, please let me know. |
@aaboffill Thanks for the update - it looks good. One some improvement that I missed last time: 'cuban' should be changed to 'Cuban' in the docstrings because it's a proper noun. Once that's updated, I'll merge this. |
01847d5
to
59f17a4
Compare
Hi! @benkonrath , thanks for your review :) ... I made your last suggestion related to |
Merged via 328caad. Thanks! |
All Changes
Add an entry to the docs/changelog.rst describing the change.
Add an entry for your name in the docs/authors.rst file if it's not
already there.
Adjust your imports to a standard form by running this command:
New Fields Only
Prefix the country code to all fields.
Field names should be easily understood by developers from the target
localflavor country. This means that English translations are usually
not the best name unless it's for something standard like postal code,
tax / VAT ID etc.
Prefer 'PostalCodeField' for postal codes as it's
international English; ZipCode is a term specific to the United
States postal system.
Add meaningful tests. 100% test coverage is not required but all
validation edge cases should be covered.
Add
.. versionadded:: <next-version>
comment markers to newlocalflavors.
Add documentation for all fields.