Skip to main content

An Idcard and RUC field for Ecuador for Django Models, Forms, and Serializers.

Project description

dj-ec-idcardfield

An Idcard and RUC field for Ecuador for Django Models, Forms, and Serializers.

Installation

It requires Python 3.8+ and Django 3.2+ to run.

pip install dj-ec-idcardfield

Usage

Settings

First, add 'dj_ec_idcardfield' to your INSTALLED_APPS in settings.py file:

INSTALLED_APPS = [
    ...
    'dj_ec_idcardfield',
    ...
]

Models

from django.db.models import Model

from dj_ec_idcardfield.models import IdcardField, IdcardOrRUCField, RUCField


class MandatoryIdcard(Model):
    idcard = IdcardField()


class OptionalIdcard(Model):
    idcard = IdcardField(blank=True, default='')


class MandatoryRUC(Model):
    ruc = RUCField()


class OptionalRUC(Model):
    ruc = RUCField(blank=True, default='')


class MandatoryIdcardOrRUC(Model):
    idcard_or_ruc = IdcardOrRUCField()


class OptionalIdcardOrRUC(Model):
    idcard_or_ruc = IdcardOrRUCField(blank=True, default='')

Forms

from django.forms import Form

from dj_ec_idcardfield.forms import IdcardField, IdcardOrRUCField, RUCField


class MandatoryIdcardForm(Form):
    idcard = IdcardField()


class OptionalIdcardForm(Form):
    idcard = IdcardField(required=False)


class MandatoryRUCForm(Form):
    ruc = RUCField()


class OptionalRUCForm(Form):
    ruc = RUCField(required=False)


class MandatoryIdcardOrRUCForm(Form):
    idcard_or_ruc = IdcardOrRUCField()


class OptionalIdcardOrRUCForm(Form):
    idcard_or_ruc = IdcardOrRUCField(required=False)

Serializers

Before using Serializer fields, you must install Django REST Framework 3.14+:

pip install djangorestframework

from rest_framework.serializers import Serializer

from dj_ec_idcardfield.serializers import IdcardField, IdcardOrRUCField, RUCField


class MandatoryIdcardSerializer(Serializer):
    idcard = IdcardField()


class OptionalIdcardSerializer(Serializer):
    idcard = IdcardField(required=False, allow_blank=True)


class MandatoryRUCSerializer(Serializer):
    ruc = RUCField()


class OptionalRUCSerializer(Serializer):
    ruc = RUCField(required=False, allow_blank=True)


class MandatoryIdcardOrRUCSerializer(Serializer):
    idcard_or_ruc = IdcardOrRUCField()


class OptionalIdcardOrRUCSerializer(Serializer):
    idcard_or_ruc = IdcardOrRUCField(required=False, allow_blank=True)

Testing

# clone repository
git clone https://github.com/hugofer93/dj-ec-idcardfield/

# up service with Docker
docker compose up -d

# run tests
docker compose exec dj-ec-idcardfield poetry run pytest

# if you want to test compat with others versions
docker compose exec dj-ec-idcardfield poetry run tox --parallel auto

License

Released under MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_ec_idcardfield-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_ec_idcardfield-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file dj_ec_idcardfield-0.1.0.tar.gz.

File metadata

  • Download URL: dj_ec_idcardfield-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for dj_ec_idcardfield-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2131ecfb738adc5768aa53d1c780ae85b6f01946986b26c5b145c3b141ab3db
MD5 12c7c436e55a6ffb1343cd39595ef2b4
BLAKE2b-256 fef4918fe1d1ca04fd83fc260d7ca19bb4a39fdb71ab03f3ff683e0c0add4463

See more details on using hashes here.

File details

Details for the file dj_ec_idcardfield-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_ec_idcardfield-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06cba1a86e4468e073b649e9bf01b55e6c6f3c9f2e9b6f903a821b9b52c9de14
MD5 9b08a91760dac7b4a02d4b929f31d305
BLAKE2b-256 61e8f4ebbcbd1d4eb31e100a4c01a1a331ee4db4c9d8a3b76cee3b60788593eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page