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 4.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.1.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.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dj_ec_idcardfield-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 bc34589f5c2ec7a7af8e7a257e7c17e26b802a16c005c9386288e9fad1a9e7ab
MD5 14d808b2d78e4b9b9234b4e73f7a423f
BLAKE2b-256 e8d195641ab6935b02251b118d1992cbbaa769581038199f445e0c9331e1e867

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dj_ec_idcardfield-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 096d688198240f6c4df4751f2b6657383f6e8dad36b74fa3dbc3d3d78af7c274
MD5 e3b6d75200e46408b087bda03803237a
BLAKE2b-256 f03be9d02d71ae524b35ffd8c43648a5731c5093b1d0c76b52dfdf7131b831b7

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