diff --git a/djangochannelsrestframework/__init__.py b/djangochannelsrestframework/__init__.py index b5fdc75..493f741 100644 --- a/djangochannelsrestframework/__init__.py +++ b/djangochannelsrestframework/__init__.py @@ -1 +1 @@ -__version__ = "0.2.2" +__version__ = "0.3.0" diff --git a/djangochannelsrestframework/generics.py b/djangochannelsrestframework/generics.py index 939c142..39adb7e 100644 --- a/djangochannelsrestframework/generics.py +++ b/djangochannelsrestframework/generics.py @@ -17,7 +17,7 @@ class GenericAsyncAPIConsumer(AsyncAPIConsumer): queryset: will be accesed when the method `get_queryset` is called. serializer_class: it should correspond with the `queryset` model, it will be useded for the return response. lookup_field: field used in the `get_object` method. Optional. - lookup_url_kwarg: url parameter used it for the lookup. + lookup_url_kwarg: url parameter used it for the lookup. """ # You'll need to either set these attributes, @@ -56,7 +56,7 @@ def get_queryset(self, **kwargs) -> QuerySet: Args: kwargs: keyworded dictionary. - + Returns: Queryset attribute. """ diff --git a/djangochannelsrestframework/mixins.py b/djangochannelsrestframework/mixins.py index fb2c44a..b92894b 100644 --- a/djangochannelsrestframework/mixins.py +++ b/djangochannelsrestframework/mixins.py @@ -34,8 +34,8 @@ def create(self, data: dict, **kwargs) -> Tuple[ReturnDict, int]: class LiveConsumer(CreateModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -67,7 +67,7 @@ class LiveConsumer(CreateModelMixin, GenericAsyncAPIConsumer): "request_id": 150060530, "data": {'username': 'test', 'id': 42,}, } - */ + */ """ serializer = self.get_serializer(data=data, action_kwargs=kwargs) @@ -81,7 +81,7 @@ def perform_create(self, serializer, **kwargs): class ListModelMixin: """List model mixin""" - + @action() def list(self, **kwargs) -> Tuple[ReturnList, int]: """List action. @@ -102,8 +102,8 @@ def list(self, **kwargs) -> Tuple[ReturnList, int]: class LiveConsumer(ListModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -133,7 +133,7 @@ class LiveConsumer(ListModelMixin, GenericAsyncAPIConsumer): {"email": "45@example.com", "id": 2, "username": "test2"}, ], } - */ + */ """ queryset = self.filter_queryset(self.get_queryset(**kwargs), **kwargs) serializer = self.get_serializer( @@ -144,7 +144,7 @@ class LiveConsumer(ListModelMixin, GenericAsyncAPIConsumer): class RetrieveModelMixin: """Retrieve model mixin""" - + @action() def retrieve(self, **kwargs) -> Tuple[ReturnDict, int]: """Retrieve action. @@ -165,8 +165,8 @@ def retrieve(self, **kwargs) -> Tuple[ReturnDict, int]: class LiveConsumer(RetrieveModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -194,7 +194,7 @@ class LiveConsumer(RetrieveModelMixin, GenericAsyncAPIConsumer): "request_id": 1500000, "data": {"email": "42@example.com", "id": 1, "username": "test1"}, } - */ + */ """ instance = self.get_object(**kwargs) serializer = self.get_serializer(instance=instance, action_kwargs=kwargs) @@ -224,8 +224,8 @@ def update(self, data: dict, **kwargs) -> Tuple[ReturnDict, int]: class LiveConsumer(UpdateModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -256,7 +256,7 @@ class LiveConsumer(UpdateModelMixin, GenericAsyncAPIConsumer): "request_id": 1500000, "data": {"email": "42@example.com", "id": 1, "username": "test edited"}, } - */ + */ """ instance = self.get_object(data=data, **kwargs) @@ -301,8 +301,8 @@ def patch(self, data: dict, **kwargs) -> Tuple[ReturnDict, int]: class LiveConsumer(PatchModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -333,7 +333,7 @@ class LiveConsumer(PatchModelMixin, GenericAsyncAPIConsumer): "request_id": 150000, "data": {"email": "00@example.com", "id": 1, "username": "test1"}, } - */ + */ """ instance = self.get_object(data=data, **kwargs) @@ -378,8 +378,8 @@ def delete(self, **kwargs) -> Tuple[None, int]: class LiveConsumer(DeleteModelMixin, GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - permission_classes = (permissions.AllowAny,) - + permission_classes = (permissions.AllowAny,) + .. code-block:: python #! routing.py @@ -407,7 +407,7 @@ class LiveConsumer(DeleteModelMixin, GenericAsyncAPIConsumer): "request_id": 150000, "data": null, } - */ + */ """ instance = self.get_object(**kwargs) @@ -451,9 +451,7 @@ def paginator(self) -> Optional[any]: self._paginator = self.pagination_class() return self._paginator - def paginate_queryset( - self, queryset, **kwargs: Dict - ) -> Optional[Any]: + def paginate_queryset(self, queryset, **kwargs: Dict) -> Optional[Any]: if self.paginator is None: return None return self.paginator.paginate_queryset( diff --git a/djangochannelsrestframework/observer/base_observer.py b/djangochannelsrestframework/observer/base_observer.py index c9b4a53..414b908 100644 --- a/djangochannelsrestframework/observer/base_observer.py +++ b/djangochannelsrestframework/observer/base_observer.py @@ -4,6 +4,8 @@ from djangochannelsrestframework.consumers import AsyncAPIConsumer from djangochannelsrestframework.observer.utils import ObjPartial + + class BaseObserver: """Base observer class""" @@ -59,7 +61,7 @@ def serializer(self, func): TODO path to examples? .. code-block:: python - + # models.py from django.db import models from django.contrib.auth.models import AbstractUser @@ -102,7 +104,7 @@ class Meta: class MyConsumer(GenericAsyncAPIConsumer): queryset = User.objects.all() serializer_class = UserSerializer - + @model_observer(Comments) async def comment_activity(self, message, observer=None, **kwargs): await self.send_json(message) @@ -132,7 +134,7 @@ async def subscribe_to_comment_activity(self, **kwargs): } In the IPython shell we will create some comments for differnt users and in the browser console we will se the log. - + .. note:: At this point we should have some users in our database, otherwise create them diff --git a/djangochannelsrestframework/observer/observer.py b/djangochannelsrestframework/observer/observer.py index 2af6169..ddf98d3 100644 --- a/djangochannelsrestframework/observer/observer.py +++ b/djangochannelsrestframework/observer/observer.py @@ -8,16 +8,17 @@ from typing import Dict, Generator, Optional + class Observer(BaseObserver): """Observer - + Attributes: signal: signal that is fired by django signals. signal_kwargs: the keyworded dictionary for the signal connection. """ - signal : Signal - signal_kwargs : Optional[Dict] + signal: Signal + signal_kwargs: Optional[Dict] def __init__(self, func, signal: Signal = None, kwargs=None, partition: str = "*"): super().__init__(func, partition=partition) @@ -32,7 +33,7 @@ def handle(self, signal, *args, **kwargs): """Handler method pass to the signal connection This method if fired by the signal, it sends the serialized message, to each group name. - + Args: signal: signal instance # TODO args: listed arguments. diff --git a/djangochannelsrestframework/pagination.py b/djangochannelsrestframework/pagination.py index e5c6317..a600a06 100644 --- a/djangochannelsrestframework/pagination.py +++ b/djangochannelsrestframework/pagination.py @@ -48,11 +48,7 @@ def get_paginated_response( ) def paginate_queryset( - self, - queryset, - scope: Dict[any, any], - view=None, - **kwargs: Dict[any, any] + self, queryset, scope: Dict[any, any], view=None, **kwargs: Dict[any, any] ) -> Optional[List[Optional[Any]]]: """Paginates a given queryset, based on the kwargs `limit` and `offset`. diff --git a/djangochannelsrestframework/permissions.py b/djangochannelsrestframework/permissions.py index 9cf88b8..cee7e74 100644 --- a/djangochannelsrestframework/permissions.py +++ b/djangochannelsrestframework/permissions.py @@ -5,13 +5,14 @@ class BasePermission: """Base permision class - + Notes: You should extend this class and overide the `has_permision` method to create your own permission class. Methods: - async has_permision (scope, consumer, action, **kwargs) + async has_permision (scope, consumer, action, **kwargs) """ + async def has_permission( self, scope: Dict[str, Any], consumer: AsyncConsumer, action: str, **kwargs ) -> bool: @@ -20,6 +21,7 @@ async def has_permission( class AllowAny(BasePermission): """Allow any permision class""" + async def has_permission( self, scope: Dict[str, Any], consumer: AsyncConsumer, action: str, **kwargs ) -> bool: @@ -28,6 +30,7 @@ async def has_permission( class IsAuthenticated(BasePermission): """Allow authenticated only class""" + async def has_permission( self, scope: Dict[str, Any], consumer: AsyncConsumer, action: str, **kwargs ) -> bool: diff --git a/docs/conf.py b/docs/conf.py index ee94aa8..71ccb6e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,21 +12,23 @@ # import os import sys -sys.path.insert(0, os.path.abspath('..')) -__version__ = "0.2.0" +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.3.0" # Setup Django from django.conf import settings + settings.configure() import djangochannelsrestframework # -- Project information ----------------------------------------------------- -project = 'djangochannelsrestframework' -copyright = '2021, hishnash' -author = 'hishnash' +project = "djangochannelsrestframework" +copyright = "2021, hishnash" +author = "hishnash" # -- General configuration --------------------------------------------------- @@ -35,20 +37,23 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", ] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- @@ -56,12 +61,12 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The short X.Y version. @@ -71,4 +76,4 @@ # Output file base name for HTML help builder. -htmlhelp_basename = 'djangochannelsrestframework' \ No newline at end of file +htmlhelp_basename = "djangochannelsrestframework" diff --git a/setup.py b/setup.py index 20f769c..6900f45 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="djangochannelsrestframework", - version="0.2.2", + version="0.3.0", url="https://github.com/hishnash/djangochannelsrestframework", author="Matthaus Woolard", author_email="matthaus.woolard@gmail.com",