Framework for views in big projects on Django.
Project description
Documentation on other languages:
DjBurger – patched views format for big projects on Django.
Key principes:
Validation only before main logic.
Reusable logic for many views.
Reusable input and output data formats.
More clear views.
Dataflow:
Decorators (d).
Parser (p). Parse request body.
PreValidator (prev). Validate and clear request.
PreRenderer (prer). Render and return PreValidation errors.
Controller (c). Main logic: do some things.
PostValidator (postv). Validate and clear response.
PostRenderer (postr). Render and return PostValidation errors.
Renderer (r). Render successfull response.
Required only Controller and Renderer.
Installation
STABLE
pip install djburger
DEV
Using pip:
sudo pip install -e git+https://github.com/orsinium/djburger.git#egg=djburger
In requirements.txt:
-e git+https://github.com/orsinium/djburger.git#egg=djburger
Components
Main components:
Validators (djburger.v). Can be used as prev and postv.
Bases (djburger.v.b).
Constructors (djburger.v.c).
Wrappers (djburger.v.w)
Controllers (djburger.c). Can be used as c.
Renderer (djburger.r). Can be used as prer, postr and r.
Some additional components:
djburger.exceptions – useful exceptions.
Interfaces
Decorator. Any decorator which can wrap Django view
Validator. Have same interfaces as Django Forms, but get request by initialization:
.__init__()
request – Request object
data – data from user (prev) or controller (postv)
**kwargs – any keyword arguments for validator
.is_valid() – return True if data is valid False otherwise.
.errors – errors if data is invalid.
.cleaned_data – cleaned data if input data is valid.
Controller. Any callable object. Kwargs:
request – Request object.
data – validated request data. 3 **kwargs – kwargs from url.
Renderer. Any callable object. Kwargs:
request – Request object.
data – validated controller data (only for r).
validator – validator which not be passed (only for prer and postr).
status_code – HTTP status code if validator raise djburger.e.StatusCodeError.
Usage example
View definition:
import djburger
class ExampleView(djburger.ViewBase):
rules = {
'get': djburger.rule(
c=lambda request, data, **kwargs: 'Hello, World!',
postv=djburger.v.c.IsStrValidator,
postr=djburger.s.ExceptionSerializer,
r=djburger.r.Template(template_name='index.html'),
),
}
External libraries support
-
djburger.v.b.RESTFramework
djburger.v.w.RESTFramework
djburger.r.RESTFramework
-
djburger.v.b.Marshmallow
djburger.v.w.Marshmallow
-
djburger.v.c.PySchemes
djburger.v.w.PySchemes
-
djburger.r.YAML
-
djburger.r.Tablib
-
djburger.p.BSON
djburger.r.BSON
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file djburger-0.7.1.tar.gz
.
File metadata
- Download URL: djburger-0.7.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c39819d83ea708c197cfd6daecfb1701c09815ef2f721959f10295c957309f4 |
|
MD5 | 773ea24d6f0f358fb3374d7e8feefce0 |
|
BLAKE2b-256 | 3e6297269020af86bdd228128370cbac793abfef40ac04e1962c2e0199fa9f34 |