Brazil (br)

Forms

BR-specific Form helpers.

class localflavor.br.forms.BRCNPJField(min_length=14, max_length=18, **kwargs)[source]

A form field that validates input as Brazilian CNPJ.

Input can either be of the format XX.XXX.XXX/XXXX-XX or be a group of 14 digits.

If you want to use the long format only, you can specify:
brcnpj_field = BRCNPJField(min_length=16)
If you want to use the short format, you can specify:
brcnpj_field = BRCNPJField(max_length=14)

Otherwise both formats will be valid.

Changed in version 1.4.

Changed in version 2.2: Use BRCNPJValidator to centralize validation logic and share with equivalent model field. More details at: https://github.com/django/django-localflavor/issues/334

class localflavor.br.forms.BRCPFField(max_length=14, min_length=11, **kwargs)[source]

A form field that validates a CPF number or a CPF string.

A CPF number is compounded by XXX.XXX.XXX-VD. The two last digits are check digits.

More information: http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas

Changed in version 2.2: Use BRCPFValidator to centralize validation logic and share with equivalent model field. More details at: https://github.com/django/django-localflavor/issues/334

class localflavor.br.forms.BRProcessoField(max_length=25, min_length=20, **kwargs)[source]

A form field that validates a Legal Process(Processo) number or a Legal Process string.

A Processo number is compounded by NNNNNNN-DD.AAAA.J.TR.OOOO. The two DD digits are check digits. More information: http://www.cnj.jus.br/busca-atos-adm?documento=2748

New in version 1.2.

clean(value)[source]

Value can be either a string in the format NNNNNNN-DD.AAAA.J.TR.OOOO or an 20-digit number.

class localflavor.br.forms.BRStateChoiceField(**kwargs)[source]

A choice field that uses a list of Brazilian states as its choices.

clean(value)[source]

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

class localflavor.br.forms.BRStateSelect(attrs=None)[source]

A Select widget that uses a list of Brazilian states/territories as its choices.

class localflavor.br.forms.BRZipCodeField(**kwargs)[source]

A form field that validates input as a Brazilian zip code, with the format 00000-000.

Changed in version 2.2: Use BRPostalCodeValidator to centralize validation logic and share with equivalent model field. More details at: https://github.com/django/django-localflavor/issues/334

Models

class localflavor.br.models.BRCNPJField(*args, **kwargs)[source]

A model field for the brazilian document named of CNPJ (Cadastro Nacional de Pessoa Jurídica)

New in version 2.2.

class localflavor.br.models.BRCPFField(*args, **kwargs)[source]

A model field for the brazilian document named of CPF (Cadastro de Pessoa Física)

New in version 2.2.

class localflavor.br.models.BRPostalCodeField(*args, **kwargs)[source]

A model field for the brazilian zip code

New in version 2.2.

class localflavor.br.models.BRStateField(*args, **kwargs)[source]

A model field for states of Brazil.

deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.
  • The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
  • A list of positional arguments.
  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
  • UUID
  • datetime.datetime (naive), datetime.date
  • top-level classes, top-level functions - will be referenced by their full import path
  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

Data

localflavor.br.br_states.STATE_CHOICES = (('AC', 'Acre'), ('AL', 'Alagoas'), ('AP', 'Amapá'), ('AM', 'Amazonas'), ('BA', 'Bahia'), ('CE', 'Ceará'), ('DF', 'Distrito Federal'), ('ES', 'Espírito Santo'), ('GO', 'Goiás'), ('MA', 'Maranhão'), ('MT', 'Mato Grosso'), ('MS', 'Mato Grosso do Sul'), ('MG', 'Minas Gerais'), ('PA', 'Pará'), ('PB', 'Paraíba'), ('PR', 'Paraná'), ('PE', 'Pernambuco'), ('PI', 'Piauí'), ('RJ', 'Rio de Janeiro'), ('RN', 'Rio Grande do Norte'), ('RS', 'Rio Grande do Sul'), ('RO', 'Rondônia'), ('RR', 'Roraima'), ('SC', 'Santa Catarina'), ('SP', 'São Paulo'), ('SE', 'Sergipe'), ('TO', 'Tocantins'))

An alphabetical list of Brazilian states for use as choices in a formfield