Skip to main content

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:

  1. Validation only before main logic.

  2. Reusable logic for many views.

  3. Reusable input and output data formats.

  4. More clear views.

Dataflow:

  1. Decorators (d).

  2. Parser (p). Parse request body.

  3. PreValidator (prev). Validate and clear request.

  4. PreRenderer (prer). Render and return PreValidation errors.

  5. Controller (c). Main logic: do some things.

  6. PostValidator (postv). Validate and clear response.

  7. PostRenderer (postr). Render and return PostValidation errors.

  8. Renderer (r). Render successfull response.

Scheme

Scheme

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:

  1. Validators (djburger.v). Can be used as prev and postv.

    1. Bases (djburger.v.b).

    2. Constructors (djburger.v.c).

    3. Wrappers (djburger.v.w)

  2. Controllers (djburger.c). Can be used as c.

  3. Renderer (djburger.r). Can be used as prer, postr and r.

Some additional components:

  1. djburger.exceptions – useful exceptions.

Interfaces

  1. Decorator. Any decorator which can wrap Django view

  2. Validator. Have same interfaces as Django Forms, but get request by initialization:

    1. .__init__()

      • request – Request object

      • data – data from user (prev) or controller (postv)

      • **kwargs – any keyword arguments for validator

    2. .is_valid() – return True if data is valid False otherwise.

    3. .errors – errors if data is invalid.

    4. .cleaned_data – cleaned data if input data is valid.

  3. Controller. Any callable object. Kwargs:

    1. request – Request object.

    2. data – validated request data. 3 **kwargs – kwargs from url.

  4. Renderer. Any callable object. Kwargs:

    1. request – Request object.

    2. data – validated controller data (only for r).

    3. validator – validator which not be passed (only for prer and postr).

    4. 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

  • Django REST Framework

    • djburger.v.b.RESTFramework

    • djburger.v.w.RESTFramework

    • djburger.r.RESTFramework

  • Marshmallow

    • djburger.v.b.Marshmallow

    • djburger.v.w.Marshmallow

  • PySchemes

    • djburger.v.c.PySchemes

    • djburger.v.w.PySchemes

  • PyYAML

    • djburger.r.YAML

  • Tablib

    • djburger.r.Tablib

  • BSON

    • djburger.p.BSON

    • djburger.r.BSON

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

djburger-0.7.1.tar.gz (12.8 kB view details)

Uploaded Source

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

Hashes for djburger-0.7.1.tar.gz
Algorithm Hash digest
SHA256 2c39819d83ea708c197cfd6daecfb1701c09815ef2f721959f10295c957309f4
MD5 773ea24d6f0f358fb3374d7e8feefce0
BLAKE2b-256 3e6297269020af86bdd228128370cbac793abfef40ac04e1962c2e0199fa9f34

See more details on using hashes here.

Supported by

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