Skip to content

Commit

Permalink
django_request_formatter -> django_api_forms 😨
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibyx committed Mar 3, 2020
1 parent a71f2ba commit 1bc2259
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.7.0 : 03.02.2020

- **Change**: Library renamed from `django_request_formatter` to `django_api_forms`
- **Change**: Imports in main module `django_api_forms`

## 0.6.0 : 18.02.2020

- **Feature**: `BooleanField` introduced
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Jakub Dubec
Copyright (c) 2020 Jakub Dubec

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# DjangoRequestFormatter
# Django API Forms

[![PyPI version](https://badge.fury.io/py/django-request-formatter.svg)](https://badge.fury.io/py/django-request-formatter)

[Django Forms](https://docs.djangoproject.com/en/2.2/topics/forms/) approach in validation of request payload
[Django Forms](https://docs.djangoproject.com/en/3.0/topics/forms/) approach in validation of request payload
(especially for content type like [JSON](https://www.json.org/) or [MessagePack](https://msgpack.org/))
without HTML front-end.

Expand All @@ -11,7 +11,7 @@ without HTML front-end.
## Motivation

Main idea was to create a simple and declarative way to specify format of expecting request with ability to validate
them. Firstly I tried to use [Django Forms](https://docs.djangoproject.com/en/2.2/topics/forms/) to validate my API
them. Firstly I tried to use [Django Forms](https://docs.djangoproject.com/en/3.0/topics/forms/) to validate my API
request (I use pure Django in my APIs). I have encountered a problem with nesting my requests without huge boilerplate.
Also, the whole HTML thing was pretty useless in my RESTful APIs.

Expand All @@ -26,19 +26,19 @@ I wanted to keep:

- friendly declarative Django syntax
([DeclarativeFieldsMetaclass](https://github.com/django/django/blob/master/django/forms/forms.py#L22) is beautiful)
- [Django Validators](https://docs.djangoproject.com/en/2.2/ref/validators/)
- [ValidationError](https://docs.djangoproject.com/en/2.2/ref/exceptions/#validationerror)
- [Django Validators](https://docs.djangoproject.com/en/3.0/ref/validators/)
- [ValidationError](https://docs.djangoproject.com/en/3.0/ref/exceptions/#validationerror)

So I decided to create simple Python package to cover all my expectations.

## Installation

```shell script
# Using pip
pip install django_request_formatter
pip install django_api_forms

# Using pipenv
pipenv install django_request_formatter
pipenv install django_api_forms

# Using setup.py
python setup.py install
Expand Down Expand Up @@ -95,16 +95,15 @@ python setup.py install

```

**DjangoRequestFormatter equivalent + validation**
**Django API Forms equivalent + validation**

```python
from enum import Enum

from django.core.exceptions import ValidationError
from django.forms import fields

from django_request_formatter.fields import FieldList, FormField, FormFieldList, DictionaryField, EnumField, AnyField
from django_request_formatter.forms import Form
from django_api_forms import FieldList, FormField, FormFieldList, DictionaryField, EnumField, AnyField, Form


class AlbumType(Enum):
Expand Down Expand Up @@ -159,4 +158,4 @@ def create_album(request):
```

---
Made with ❤️ by Jakub Dubec & [BACKBONE s.r.o.](https://www.backbone.sk/en/)
Made with ❤️ and ☕️ by Jakub Dubec & [BACKBONE s.r.o.](https://www.backbone.sk/en/)
23 changes: 23 additions & 0 deletions django_api_forms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .exceptions import RequestValidationError
from .fields import BooleanField
from .fields import FieldList
from .fields import FormField
from .fields import FormFieldList
from .fields import EnumField
from .fields import DictionaryField
from .fields import AnyField
from .forms import Form
from .version import __version__

__all__ = [
'RequestValidationError',
'BooleanField',
'FieldList',
'FormField',
'FormFieldList',
'EnumField',
'DictionaryField',
'AnyField',
'Form',
'__version__'
]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from django.utils.translation import gettext_lazy as _

from django_request_formatter.exceptions import RequestValidationError
from .exceptions import RequestValidationError


class BooleanField(Field):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.forms import MediaDefiningClass, Field
from django.utils.translation import gettext as _

from django_request_formatter.exceptions import RequestValidationError
from .exceptions import RequestValidationError


class DeclarativeFieldsMetaclass(MediaDefiningClass):
Expand Down
1 change: 1 addition & 0 deletions django_api_forms/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.7.0'
Empty file.
1 change: 0 additions & 1 deletion django_request_formatter/version.py

This file was deleted.

8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def read_files(files):


meta = {}
with open('./django_request_formatter/version.py') as f:
with open('django_api_forms/version.py') as f:
exec(f.read(), meta)

setup(
name='django_request_formatter',
name='django_api_forms',
version=meta['__version__'],
packages=['django_request_formatter'],
packages=['django_api_forms'],
install_requires=REQUIRED,
url='https://github.com/Sibyx/django_request_formatter',
url='https://github.com/Sibyx/django_api_forms',
license='MIT',
author='Jakub Dubec',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class TestAppConfig(AppConfig):
name = 'django_request_formatter.tests.testapp'
name = 'django_api_forms.tests.testapp'
verbose_name = 'TestApp'
3 changes: 1 addition & 2 deletions tests/testapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from django.core.exceptions import ValidationError
from django.forms import fields

from django_request_formatter.fields import FieldList, FormField, FormFieldList, DictionaryField, EnumField, AnyField
from django_request_formatter.forms import Form
from django_api_forms import Form, FieldList, AnyField, FormField, FormFieldList, EnumField, DictionaryField


class AlbumType(Enum):
Expand Down

0 comments on commit 1bc2259

Please sign in to comment.