Skip to main content

All Basic

All Basic is a simple Django app to to add some basic functionality to use the DRF API. It consists of separating business logic and the application of nested data that comes from user requests and validations that support nested data.

Quick start

Add allbasic to your INSTALLED_APPS setting like this:

INSTALLED_APPS = [
    ...
    'allbasic',
]

Create an application (what name is up) and create several files:

myapp/
    domains.py
    presentations.py
    validations.py

In your validations.py:

from allbasic.validations import BaseValidation

class ValidationUserDetailUpdate(BaseValidation):
    def schema(self):
        return {
            'last_name': {
                'type': 'string',
                'required': True,
                'empty': False
            },
            'first_name': {
                'type': 'string',
                'required': True,
                'empty': False
            }
        }

In your domains.py:

from allbasic.domains import BaseDomain

class DomainUserUpdate(BaseDomain):
    @transaction.atomic()
    def apply(self):
        data = self.context.get('data')
        user = self.context.get('user')

        user.first_name = data.get('first_name', user.first_name)
        user.last_name = data.get('last_name', user.last_name)

        return user.save()

In your presentations.py:

from allbasic.presentations import BasePresentation

class UserDetailPresentation(BasePresentation):
    def present(self):
        user = self.context.get('user')

        return {
            'id': user.pk,
            'username': user.username,
            'email': user.email,
            'last_name': user.last_name,
            'first_name': user.first_name
        }

In your views.py:

from allbasic.domains import ContextDomain
from allbasic.presentations import ContextPresentation
from allbasic.validations import ContextValidation

class UserDetailView(APIView):
    authentication_classes = (
        JSONWebTokenAuthentication,
        SessionAuthentication,
        BasicAuthentication
    )
    permission_classes = (IsAuthenticated,)

    def put(self, request):
        validation = ContextValidation(ValidationUserDetailUpdate(request.data))

        if validation.validate():
            ContextDomain(DomainUserUpdate(context={'data': validation.data, 'user': request.user})).do_apply()
            presentation = ContextPresentation(UserDetailPresentation(context={'user': request.user}))
            return Response(presentation.do_present())

        return Response(validation.errors, status=status.HTTP_400_BAD_REQUEST)

Metadata

Release files for django-allbasic 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-allbasic 0.1
File Size Uploaded
django-allbasic-0.1.tar.gz 4.3 kB Details

Release files / django-allbasic-0.1.tar.gz

Download URL django-allbasic-0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
677fe34db3bf3b8808953ddf1759e7ade049807bd0c4b7172024dfede1a418f1
BLAKE2b-256 checksum
How to use checksums
17d5cb4e7cc2bebe2ad515c16b6a4bcf3ecd09f5964e1a7a1d20bb78c0d8d953
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page