Skip to main content

Generic views for Model View Serializer (MVS) pattern

Project description

Django Generic Ellis Views

Django Generic Ellis Views provides generic views for Create, Retrieve, Update, and Delete operations, requiring only the definition of serializer, model, and authorization methods.

Table of Contents

  • Quick Start
  • Usage Example
  • Features
  • Contributing
  • License

Quick Start

  1. Add 'ellis_django_views' to your INSTALLED_APPS in settings.py:

    # django-project/settings.py
    
    INSTALLED_APPS = [
        'ellis_django_views',
    ]
    
  2. Include test URLs for testing purposes in your project's urls.py:

    # django-project/urls.py
    
    from django.urls import path, include
    from ellis_django_views.tests import urls as TestUrls
    from ellis_django_views.utils import url_paths as test_url_paths
    
    urlpatterns = [
        path(test_url_paths.TEST, include(TestUrls)),
    ]
    
  3. Run migrations:

    python manage.py makemigrations
    python manage.py migrate
    
  4. Run tests:

    python manage.py test ellis_django_views
    

Usage Example

  1. Import CRUD views from 'ellis_django_views.views_implementation' and your own models and serializers:

    # django-project/django-app/views.py
    from DjangoApp.models import YourModel
    from DjangoApp.serializers import YourSerializer
    from ellis_django_views.views_implementation import (
        CreateViewImpl,
        RequestViewImpl,
        UpdateViewImpl,
        DeleteViewImpl
    )
    
  2. Create an is_authorised function which retrieves 'HTTP_AUTHORIZATION' from request headers:

    def is_authorised(self, auth_token):
        "Placeholder for authorization"
        return True
    
  3. Create CRUD views with imported 'ellis_django_views.views_implementation' views and your is_authorised function:

    # django-project/django-app/views.py
    class CreateView(CreateViewImpl):
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class RequestView(RequestViewImpl):
        model = YourModel
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class UpdateView(UpdateViewImpl):
        model = YourModel
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class DeleteView(DeleteViewImpl):
        model = YourModel
        is_authorised = is_authorised
    
  4. Add the CRUD views to your urls.py:

    # django-project/django-app/urls.py
    from django.urls import path
    from DjangoApp.views import CreateView, RequestView, UpdateView, DeleteView
    
    urlpatterns = [
        path('post/', CreateView.as_view(), name='create'),
        path('get/', RequestView.as_view(), name='get'),
        path('put/', UpdateView.as_view(), name='put'),
        path('delete/', DeleteView.as_view(), name='delete'),
    ]
    

Features

  • Simplified CRUD Operations: Easily create, retrieve, update, and delete views with minimal setup.
  • Authorization Support: Implement custom authorization logic.
  • Serializer Integration: Define serializers for your models to handle validation and representation.
  • Test URLs: Built-in support for testing your views.

Contributing

If you have any suggestions or would like to contribute, please get in contact with Carl Ellis.

License

This project is licensed under the GNU General Public License Version 3 - see the LICENSE file for details.

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

ellis_django_views-0.233.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ellis_django_views-0.233-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file ellis_django_views-0.233.tar.gz.

File metadata

  • Download URL: ellis_django_views-0.233.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.6

File hashes

Hashes for ellis_django_views-0.233.tar.gz
Algorithm Hash digest
SHA256 5ef35f55c583c97bf1be809a5702860f5ca6acc5dcf592e46d005fb7e31f3204
MD5 dedc78707e71f3e90520b7c047d7d083
BLAKE2b-256 08a433cb40d47545d731e11d6913b5488dcc162d8722a2476062ef145abda76e

See more details on using hashes here.

File details

Details for the file ellis_django_views-0.233-py3-none-any.whl.

File metadata

File hashes

Hashes for ellis_django_views-0.233-py3-none-any.whl
Algorithm Hash digest
SHA256 4312dd140df42f5fb5aba5a3eb79014cd336b6edaa2182380507cc66b527bca4
MD5 ebdf4a9325236dce37800c5b0fbbcc7c
BLAKE2b-256 4c6fee345d22c00642c025ea62ddd259ec9f05477fa9644e2773fadeb0f0ecea

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