Skip to content

Commit

Permalink
Merge pull request #83 from hishnash/bump/v0.3.0
Browse files Browse the repository at this point in the history
Bump version and run black formating
  • Loading branch information
hishnash committed Jun 20, 2021
2 parents 3659a47 + 09fe9f1 commit c34f4ab
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 53 deletions.
2 changes: 1 addition & 1 deletion djangochannelsrestframework/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2"
__version__ = "0.3.0"
4 changes: 2 additions & 2 deletions djangochannelsrestframework/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_queryset(self, **kwargs) -> QuerySet:
Args:
kwargs: keyworded dictionary.
Returns:
Queryset attribute.
"""
Expand Down
44 changes: 21 additions & 23 deletions djangochannelsrestframework/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -144,7 +144,7 @@ class LiveConsumer(ListModelMixin, GenericAsyncAPIConsumer):

class RetrieveModelMixin:
"""Retrieve model mixin"""

@action()
def retrieve(self, **kwargs) -> Tuple[ReturnDict, int]:
"""Retrieve action.
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -407,7 +407,7 @@ class LiveConsumer(DeleteModelMixin, GenericAsyncAPIConsumer):
"request_id": 150000,
"data": null,
}
*/
*/
"""
instance = self.get_object(**kwargs)

Expand Down Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions djangochannelsrestframework/observer/base_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from djangochannelsrestframework.consumers import AsyncAPIConsumer
from djangochannelsrestframework.observer.utils import ObjPartial


class BaseObserver:
"""Base observer class"""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions djangochannelsrestframework/observer/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions djangochannelsrestframework/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
7 changes: 5 additions & 2 deletions djangochannelsrestframework/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
29 changes: 17 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand All @@ -35,33 +37,36 @@
# 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 -------------------------------------------------

# 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.
Expand All @@ -71,4 +76,4 @@


# Output file base name for HTML help builder.
htmlhelp_basename = 'djangochannelsrestframework'
htmlhelp_basename = "djangochannelsrestframework"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c34f4ab

Please sign in to comment.