Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async support to PermissionRequiredMixin #809

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

g-nie
Copy link

@g-nie g-nie commented Nov 14, 2023

The end goal is to be able to do:

from asgiref.sync import sync_to_async


class MyView(PermissionRequiredMixin, View):
    permission_required = 'some_perm'
    raise_exception = True

    async def get_permission_object(self):
        return await MyModel.objects.aget(slug='awesome-slug')

    async def get(self, request, *args, **kwargs):
        return await sync_to_async(render_to_string)('some_template.html')

Django >= 4.1.2 is needed (as indicated by the skipIf's in tests as well), since that seems to be a stable point of async views in Django. For reference, a bugfix related to non-allowed HTTP methods was fixed in 4.1.2 (release notes, ticket)

- add maybe_async to utils
- refactor methods to async and make use of maybe_async
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant