Skip to main content

Django Rest Framework collected classes for Mirmux

Project description

DRF-TOOLMUX: Django tools collection

Logo

purpose PyPI - Version License Python Version DRF Version

Overview

drf-toolmux is a collection of utilities designed to enhance your Django Rest Framework (DRF) projects. This package provides tools for connecting bots to projects for error reporting, calculating user distances, custom exception classes, lazy pagination, and custom responses.

Features

  • Bot Integration for Error Reporting: Connect your project to a bot to automatically send error notifications.
  • User Distance Calculation: Utilities to calculate distances between users.
  • Custom Exception Classes: Enhanced exception handling with custom exceptions.
  • Custom Lazy Pagination: Efficient pagination for large datasets.
  • Custom Responses: Simplified and consistent response formatting and socket responses.

Installation

Install the package using pip:

pip install drf-toolmux

How to use it

Default exception:

  • settings.py
REST_FRAMEWORK = {
    'EXCEPTION_HANDLER': 'drf_toolmux.exception.custom_exception_handler',
}

Usage custom response

You can include any key with a class attribute, and the response will include that key and the corresponding value.

CustomResponse(custom_key="Test")

  • views.py
from rest_framework.views import APIView
from drf_toolmux.responses import CustomResponse


class CreateView(APIView):

    def post(self, request, *args, **kwargs):
        return CustomResponse(message="Response message!")

Usage custom exception class

RESTException(custom_key="Test")

  • views.py
from rest_framework.views import APIView
from drf_toolmux.exception import RESTException


class CreateView(APIView):

    def post(self, request, *args, **kwargs):
        raise RESTException(message="Error message!")

Usage Lazy Scroll Pagination and PaginationView

This pagination class provides a ready-to-use solution for simple view pagination. It supports lazy scrolling by providing the next and previous values as integers for seamless navigation.

from rest_framework.views import APIView
from drf_toolmux.pagination import PaginationView


class View(PaginationView, APIView):
    pass
from rest_framework.generics import ListAPIView
from drf_toolmux.pagination import MyPagination


class View(ListAPIView):
    pagination_class = MyPagination

The results will be like this:

{
  "next": 3,
  "previous": 1,
  "page_size": 10,
  "count": 1,
  "total_pages": 3,
  "results": []
}

Socket Pagination Response

from drf_toolmux.pagination import SocketPaginationView


class ChatPrivateRoom(SocketPaginationView):

    def get_private_chat_list(self, *args, **kwargs):
        return self.send_pagination_response(queryset="queryset should be", serializer="serializer class",
                                             action="any action that you want")

Results will be like this:

{
  "action": "any action that you sent",
  "next": 3,
  "previous": 1,
  "current_page": 2,
  "page_size": 20,
  "count": 3,
  "total_pages": 3,
  "status": "success",
  "results": []
}

Find distance between two users:

from drf_toolmux.distance import define_distance

distance = define_distance(user1={"lat": "", "lng": ""}, user2={"lat": "", "lng": ""}, unit='km')

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

drf_toolmux-0.1.3.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

drf_toolmux-0.1.3-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file drf_toolmux-0.1.3.tar.gz.

File metadata

  • Download URL: drf_toolmux-0.1.3.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.9

File hashes

Hashes for drf_toolmux-0.1.3.tar.gz
Algorithm Hash digest
SHA256 edd1b5e8f261d5f15c3a58d56e8f0c53444b79b40d78b7b7d3ae0e13744be189
MD5 8983fbdbd2d3a4d16ff0c2b9abb22531
BLAKE2b-256 0da77b62db73f636f2eabe9c50dc870204c54bab98309648c3303f76d4ba2d08

See more details on using hashes here.

File details

Details for the file drf_toolmux-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: drf_toolmux-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.9

File hashes

Hashes for drf_toolmux-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 33f30a49a3efcacae2daa3b324fa3d721eb59ff9c859ba0e7b51d4f77005b422
MD5 0aeca497ba264a3acc8379ddb9414ef1
BLAKE2b-256 43bc6aaed0b6b6913ff2b98e726f7edc449c70ade3a4c4db3a508a11dcce87db

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