Skip to content

Commit

Permalink
👌 [open-zaak/open-zaak#1629] PR feedback
Browse files Browse the repository at this point in the history
* remove unused lines
* replace os usage with pathlib
  • Loading branch information
stevenbal committed May 14, 2024
1 parent da4d2b6 commit 985ff2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
44 changes: 16 additions & 28 deletions open_api_framework/conf/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import warnings
from pathlib import Path
from typing import Callable

from django.urls import reverse_lazy
Expand All @@ -22,9 +23,8 @@
# Build paths inside the project, so further paths can be defined relative to
# the code root.
DJANGO_PROJECT_DIR = get_django_project_dir()
BASE_DIR = os.path.abspath(
os.path.join(DJANGO_PROJECT_DIR, os.path.pardir, os.path.pardir)
)
BASE_DIR = Path(DJANGO_PROJECT_DIR).resolve().parents[1]


#
# Core Django settings
Expand Down Expand Up @@ -117,7 +117,6 @@
"django.contrib.messages",
"django.contrib.staticfiles",
# Optional applications.
"ordered_model",
"django_admin_index",
"django.contrib.admin",
# External applications.
Expand Down Expand Up @@ -149,7 +148,6 @@
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
# 'django.middleware.locale.LocaleMiddleware',
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand All @@ -172,7 +170,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")],
"DIRS": [Path(DJANGO_PROJECT_DIR) / "templates"],
"APP_DIRS": False, # conflicts with explicity specifying the loaders
"OPTIONS": {
"context_processors": [
Expand All @@ -190,18 +188,18 @@
WSGI_APPLICATION = f"{PROJECT_DIRNAME}.wsgi.application"

# Translations
LOCALE_PATHS = (os.path.join(DJANGO_PROJECT_DIR, "conf", "locale"),)
LOCALE_PATHS = (Path(DJANGO_PROJECT_DIR) / "conf" / "locale",)

#
# SERVING of static and media files
#

STATIC_URL = "/static/"

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_ROOT = Path(BASE_DIR) / "static"

# Additional locations of static files
STATICFILES_DIRS = [os.path.join(DJANGO_PROJECT_DIR, "static")]
STATICFILES_DIRS = [Path(DJANGO_PROJECT_DIR) / "static"]

# List of finder classes that know how to find static files in
# various locations.
Expand All @@ -210,13 +208,13 @@
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_ROOT = Path(BASE_DIR) / "media"

MEDIA_URL = "/media/"

FILE_UPLOAD_PERMISSIONS = 0o644

FIXTURE_DIRS = (os.path.join(DJANGO_PROJECT_DIR, "fixtures"),)
FIXTURE_DIRS = (Path(DJANGO_PROJECT_DIR) / "fixtures",)

#
# Sending EMAIL
Expand Down Expand Up @@ -245,7 +243,7 @@
RuntimeWarning,
)

LOGGING_DIR = os.path.join(BASE_DIR, "log")
LOGGING_DIR = Path(BASE_DIR) / "log"

logging_root_handlers = ["console"] if LOG_STDOUT else ["project"]
logging_django_handlers = ["console"] if LOG_STDOUT else ["django"]
Expand Down Expand Up @@ -286,31 +284,31 @@
"django": {
"level": LOG_LEVEL,
"class": "logging.handlers.RotatingFileHandler",
"filename": os.path.join(LOGGING_DIR, "django.log"),
"filename": Path(LOGGING_DIR) / "django.log",
"formatter": "verbose",
"maxBytes": 1024 * 1024 * 10, # 10 MB
"backupCount": 10,
},
"project": {
"level": LOG_LEVEL,
"class": "logging.handlers.RotatingFileHandler",
"filename": os.path.join(LOGGING_DIR, f"{PROJECT_DIRNAME}.log"),
"filename": Path(LOGGING_DIR) / f"{PROJECT_DIRNAME}.log",
"formatter": "verbose",
"maxBytes": 1024 * 1024 * 10, # 10 MB
"backupCount": 10,
},
"performance": {
"level": "INFO",
"class": "logging.handlers.RotatingFileHandler",
"filename": os.path.join(LOGGING_DIR, "performance.log"),
"filename": Path(LOGGING_DIR) / "performance.log",
"formatter": "performance",
"maxBytes": 1024 * 1024 * 10, # 10 MB
"backupCount": 10,
},
"requests": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"filename": os.path.join(LOGGING_DIR, "requests.log"),
"filename": Path(LOGGING_DIR) / "requests.log",
"formatter": "timestamped",
"maxBytes": 1024 * 1024 * 10, # 10 MB
"backupCount": 10,
Expand Down Expand Up @@ -449,7 +447,7 @@
if "GIT_SHA" in os.environ:
GIT_SHA = config("GIT_SHA", "")
# in docker (build) context, there is no .git directory
elif os.path.exists(os.path.join(BASE_DIR, ".git")):
elif (Path(BASE_DIR) / ".git").exists():
try:
import git
except ImportError:
Expand Down Expand Up @@ -510,16 +508,6 @@
"REMOTE_ADDR",
)

#
# DJANGO-HIJACK
#
HIJACK_LOGIN_REDIRECT_URL = reverse_lazy("home")
HIJACK_LOGOUT_REDIRECT_URL = reverse_lazy("admin:accounts_user_changelist")
HIJACK_REGISTER_ADMIN = False
# This is a CSRF-security risk.
# See: http://django-hijack.readthedocs.io/en/latest/configuration/#allowing-get-method-for-hijack-views
HIJACK_ALLOW_GET_REQUESTS = True

#
# DJANGO-CORS-MIDDLEWARE
#
Expand Down Expand Up @@ -556,7 +544,7 @@
#
# DJANGO-PRIVATES -- safely serve files after authorization
#
PRIVATE_MEDIA_ROOT = os.path.join(BASE_DIR, "private-media")
PRIVATE_MEDIA_ROOT = Path(BASE_DIR) / "private-media"
PRIVATE_MEDIA_URL = "/private-media/"


Expand Down
4 changes: 2 additions & 2 deletions open_api_framework/conf/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import sys
from pathlib import Path
from typing import Any
from urllib.parse import urlparse

Expand Down Expand Up @@ -60,4 +60,4 @@ def get_project_dirname() -> str:
def get_django_project_dir() -> str:
# Get the path of the importing module
base_dirname = get_project_dirname()
return os.path.dirname(sys.modules[base_dirname].__file__)
return Path(sys.modules[base_dirname].__file__).parent

0 comments on commit 985ff2a

Please sign in to comment.