Skip to content
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

Closed
wants to merge 16 commits into from

Conversation

aaboffill
Copy link

@aaboffill aaboffill commented Jun 2, 2017

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:

    `isort --recursive --line-width 120 localflavor tests`
    

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 new
    localflavors.

  • Add documentation for all fields.

@benkonrath
Copy link
Member

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-io
Copy link

codecov-io commented Jun 6, 2017

Codecov Report

Merging #292 into master will decrease coverage by 0.03%.
The diff coverage is 95.04%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
localflavor/cu/models.py 100% <100%> (ø)
localflavor/cu/choices.py 100% <100%> (ø)
localflavor/cu/validators.py 76.47% <76.47%> (ø)
localflavor/cu/forms.py 96.29% <96.29%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 067ed1c...59f17a4. Read the comment docs.

@aaboffill
Copy link
Author

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.

@benkonrath
Copy link
Member

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 git rebase against the latest version from master to replay your commits on top of the latest version from master. Since you're rewriting the history of your branch, you'll have to force push your branch. While you do the rebase, you can also squash the commits into 1 commit if you want.

Here's a guide I found that might be helpful:
https://help.github.com/articles/about-git-rebase/

@aaboffill
Copy link
Author

ohh! yes I see, thanks for the suggestion, I'll try ti fix that. Thanks for the suggestion @benkonrath ...

@aaboffill aaboffill force-pushed the localflavor_for_cu branch from eb80be1 to d4ff9a0 Compare June 7, 2017 16:16
@aaboffill
Copy link
Author

Hi! @benkonrath I organized the commits.

@benkonrath
Copy link
Member

Sorry for the delay in getting to this. I'll be able to do a review early next week.

Copy link
Member

@benkonrath benkonrath left a 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.

@@ -6,7 +6,8 @@ Changelog

New flavors:

- None
- Added local flavor for Ukraine
Copy link
Member

Choose a reason for hiding this comment

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

Ukraine -> Cuba

return value.strip()


class CUPhoneNumberField(RegexField):
Copy link
Member

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.

return super(CUIdentityCardNumberField, self).formfield(**defaults)


class CUPhoneNumberField(CharField):
Copy link
Member

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.


def clean(self, value):
super(CURegionField, self).clean(value)
if value in EMPTY_VALUES:
Copy link
Member

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

return ''
try:
value = value.strip().lower()
except AttributeError:
Copy link
Member

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)
Copy link
Member

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.


def to_python(self, value):
value = super(CUIdentityCardNumberField, self).to_python(value)
return value.strip()
Copy link
Member

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 EmptyValueCompatMixinas explained above.

def __init__(self, *args, **kwargs):
super(CUIdentityCardNumberField, self).__init__(r'^\d{11}$', *args, **kwargs)

def _set_regex(self, regex):
Copy link
Member

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.

return name, path, args, kwargs


class CUZipCodeField(CharField):
Copy link
Member

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.

@aaboffill
Copy link
Author

aaboffill commented Aug 11, 2017

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.

@benkonrath
Copy link
Member

@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.

@aaboffill
Copy link
Author

Hi! @benkonrath , thanks for your review :) ... I made your last suggestion related to Cuban instead of cuban

@benkonrath
Copy link
Member

Merged via 328caad.

Thanks!

@benkonrath benkonrath closed this Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants