Skip to content

Commit

Permalink
Remove unnecessary app config and make rest_framework an optional dep…
Browse files Browse the repository at this point in the history
…endency
  • Loading branch information
ajharry69 committed Aug 4, 2021
1 parent cd07848 commit 2fdbe86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
11 changes: 1 addition & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#!/usr/bin/env python
"""
Installation script:
To release a new version to PyPi:
- Ensure the version is correctly set in xently.__init__.py
- Run: make release
"""
import os
import re
import shutil
Expand Down Expand Up @@ -68,9 +61,7 @@ def get_version(package):
packages=find_packages(),
include_package_data=True,
python_requires=">=3.6",
install_requires=[
"djangorestframework",
],
install_requires=["django>=2.2"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
Expand Down
2 changes: 1 addition & 1 deletion xently/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.0.1"
14 changes: 2 additions & 12 deletions xently/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.urls import URLPattern, include, re_path, path
from rest_framework.routers import DefaultRouter

from xently.decorators import permissions_required
from xently.utils import get_installed_app_config

__all__ = ["AutoLoadURLsConfigMixin", "AppConfigMixin", "XentlyAppConfig"]


class AutoLoadURLsConfigMixin:
include_urls_in_parent = False
Expand Down Expand Up @@ -175,14 +176,3 @@ def urls(self):

class XentlyAppConfig(AutoLoadURLsConfigMixin, AppConfigMixin, AppConfig):
pass


class XentlyApiAppConfig(XentlyAppConfig):
router = DefaultRouter()

def register_routers(self):
pass

def ready(self):
super().ready()
self.register_routers()
10 changes: 7 additions & 3 deletions xently/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.contrib.auth.decorators import user_passes_test
from django.core import exceptions
from rest_framework import exceptions as api_exceptions

__all__ = ["check_permissions", "permissions_required"]

Expand Down Expand Up @@ -57,8 +56,13 @@ def _check_permissions(user):
outcome = check_permissions(user, permissions)
if not outcome and user.is_authenticated:
if api_exception:
raise exceptions.PermissionDenied
raise api_exceptions.PermissionDenied
try:
from rest_framework import exceptions as api_exceptions
except ImportError:
pass
else:
raise api_exceptions.PermissionDenied
raise exceptions.PermissionDenied
return outcome

return user_passes_test(_check_permissions, login_url=login_url)

0 comments on commit 2fdbe86

Please sign in to comment.