Skip to content

Commit

Permalink
chore: cleanup with black
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithEmad committed Apr 22, 2024
1 parent c99f619 commit 1aa0acb
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 221 deletions.
2 changes: 1 addition & 1 deletion notesapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
app_name = "notesapi.v1"

urlpatterns = [
path('v1/', include('notesapi.v1.urls', namespace='v1')),
path("v1/", include("notesapi.v1.urls", namespace="v1")),
]
9 changes: 6 additions & 3 deletions notesserver/docker_gunicorn_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
"""

import multiprocessing

preload_app = True
Expand All @@ -9,6 +10,7 @@

workers = 2


def pre_request(worker, req):
worker.log.info("%s %s" % (req.method, req.path))

Expand All @@ -22,13 +24,14 @@ def close_all_caches():
# 1.4 installations.
from django.conf import settings
from django.core import cache as django_cache
if hasattr(django_cache, 'caches'):

if hasattr(django_cache, "caches"):
get_cache = django_cache.caches.__getitem__
else:
get_cache = django_cache.get_cache
for cache_name in settings.CACHES:
cache = get_cache(cache_name)
if hasattr(cache, 'close'):
if hasattr(cache, "close"):
cache.close()

# The 1.4 global default cache object needs to be closed also: 1.4
Expand All @@ -37,7 +40,7 @@ def close_all_caches():
# you get with get_cache("default"), so it will have its own connection
# that needs to be closed.
cache = django_cache.cache
if hasattr(cache, 'close'):
if hasattr(cache, "close"):
cache.close()


Expand Down
146 changes: 80 additions & 66 deletions notesserver/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,94 @@
TEMPLATE_DEBUG = False
DISABLE_TOKEN_CHECK = False
USE_TZ = True
TIME_ZONE = 'UTC'
AUTH_USER_MODEL = 'auth.User'
TIME_ZONE = "UTC"
AUTH_USER_MODEL = "auth.User"

# This value needs to be overriden in production.
SECRET_KEY = 'CHANGEME'
ALLOWED_HOSTS = ['localhost']
SECRET_KEY = "CHANGEME"
ALLOWED_HOSTS = ["localhost"]

# ID and Secret used for authenticating JWT Auth Tokens
# should match those configured for `edx-notes` Client in EdX's /admin/oauth2/client/
CLIENT_ID = 'CHANGEME'
CLIENT_SECRET = 'CHANGEME'
CLIENT_ID = "CHANGEME"
CLIENT_SECRET = "CHANGEME"

ES_DISABLED = False

ELASTICSEARCH_DSL = {'default': {'hosts': '127.0.0.1:9200'}}
ELASTICSEARCH_DSL = {"default": {"hosts": "127.0.0.1:9200"}}

ELASTICSEARCH_DSL_INDEX_SETTINGS = {'number_of_shards': 1, 'number_of_replicas': 0}
ELASTICSEARCH_DSL_INDEX_SETTINGS = {"number_of_shards": 1, "number_of_replicas": 0}

# Name of the Elasticsearch index
ELASTICSEARCH_INDEX_NAMES = {'notesapi.v1.search_indexes.documents.note': 'edx_notes_api'}
ELASTICSEARCH_DSL_SIGNAL_PROCESSOR = 'django_elasticsearch_dsl.signals.RealTimeSignalProcessor'
ELASTICSEARCH_INDEX_NAMES = {
"notesapi.v1.search_indexes.documents.note": "edx_notes_api"
}
ELASTICSEARCH_DSL_SIGNAL_PROCESSOR = (
"django_elasticsearch_dsl.signals.RealTimeSignalProcessor"
)

# Number of rows to return by default in result.
RESULTS_DEFAULT_SIZE = 25

# Max number of rows to return in result.
RESULTS_MAX_SIZE = 250

ROOT_URLCONF = 'notesserver.urls'
ROOT_URLCONF = "notesserver.urls"

DEFAULT_HASHING_ALGORITHM = "sha1"

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"


MIDDLEWARE = (
'edx_django_utils.monitoring.CookieMonitoringMiddleware',
'edx_django_utils.monitoring.DeploymentMonitoringMiddleware',
'edx_django_utils.cache.middleware.RequestCacheMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'edx_rest_framework_extensions.middleware.RequestMetricsMiddleware',
'edx_rest_framework_extensions.auth.jwt.middleware.EnsureJWTAuthSettingsMiddleware',
"edx_django_utils.monitoring.CookieMonitoringMiddleware",
"edx_django_utils.monitoring.DeploymentMonitoringMiddleware",
"edx_django_utils.cache.middleware.RequestCacheMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"edx_rest_framework_extensions.middleware.RequestMetricsMiddleware",
"edx_rest_framework_extensions.auth.jwt.middleware.EnsureJWTAuthSettingsMiddleware",
)

ES_APPS = ('elasticsearch_dsl', 'django_elasticsearch_dsl', 'django_elasticsearch_dsl_drf',)
ES_APPS = (
"elasticsearch_dsl",
"django_elasticsearch_dsl",
"django_elasticsearch_dsl_drf",
)

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'drf_yasg',
'rest_framework',
'corsheaders',
'notesapi.v1',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.staticfiles",
"drf_yasg",
"rest_framework",
"corsheaders",
"notesapi.v1",
# additional release utilities to ease automation
'release_util',
"release_util",
]
if not ES_DISABLED:
INSTALLED_APPS.extend(ES_APPS)

STATIC_URL = '/static/'
STATIC_URL = "/static/"

WSGI_APPLICATION = 'notesserver.wsgi.application'
WSGI_APPLICATION = "notesserver.wsgi.application"

LOG_SETTINGS_LOG_DIR = '/var/tmp'
LOG_SETTINGS_LOGGING_ENV = 'no_env'
LOG_SETTINGS_LOG_DIR = "/var/tmp"
LOG_SETTINGS_LOGGING_ENV = "no_env"
LOG_SETTINGS_DEV_ENV = False
LOG_SETTINGS_DEBUG = False
LOG_SETTINGS_LOCAL_LOGLEVEL = 'INFO'
LOG_SETTINGS_LOCAL_LOGLEVEL = "INFO"
LOG_SETTINGS_EDX_FILENAME = "edx.log"
LOG_SETTINGS_SERVICE_VARIANT = 'edx-notes-api'
LOG_SETTINGS_SERVICE_VARIANT = "edx-notes-api"

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ['rest_framework.authentication.SessionAuthentication'],
'DEFAULT_PERMISSION_CLASSES': ['notesapi.v1.permissions.HasAccessToken'],
'DEFAULT_PAGINATION_CLASS': 'notesapi.v1.paginators.NotesPaginator',
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.SessionAuthentication"
],
"DEFAULT_PERMISSION_CLASSES": ["notesapi.v1.permissions.HasAccessToken"],
"DEFAULT_PAGINATION_CLASS": "notesapi.v1.paginators.NotesPaginator",
"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
}

Expand All @@ -92,26 +102,26 @@
# default permission class is HasAccessToken, which checks it.)
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = (
'x-requested-with',
'content-type',
'accept',
'origin',
'authorization',
'x-csrftoken',
'x-annotator-auth-token',
"x-requested-with",
"content-type",
"accept",
"origin",
"authorization",
"x-csrftoken",
"x-annotator-auth-token",
)

# Base project path, where manage.py lives.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True, # This ensures app templates are loadable, e.g. DRF views.
'DIRS': [
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True, # This ensures app templates are loadable, e.g. DRF views.
"DIRS": [
# The EdxNotes templates directory is not actually under any app
# directory, so specify its absolute path.
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, "templates"),
],
}
]
Expand All @@ -121,32 +131,36 @@
### Maximum number of allowed notes for each student per course ###
MAX_NOTES_PER_COURSE = 500

ELASTICSEARCH_URL = 'localhost:9200'
ELASTICSEARCH_INDEX = 'edx_notes'
ELASTICSEARCH_URL = "localhost:9200"
ELASTICSEARCH_INDEX = "edx_notes"

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'localhost',
'NAME': 'edx_notes_api',
'OPTIONS': {'connect_timeout': 10},
'PASSWORD': 'secret',
'PORT': 3306,
'USER': 'notes001',
"default": {
"ENGINE": "django.db.backends.mysql",
"HOST": "localhost",
"NAME": "edx_notes_api",
"OPTIONS": {"connect_timeout": 10},
"PASSWORD": "secret",
"PORT": 3306,
"USER": "notes001",
}
}

USERNAME_REPLACEMENT_WORKER = 'OVERRIDE THIS WITH A VALID USERNAME'
USERNAME_REPLACEMENT_WORKER = "OVERRIDE THIS WITH A VALID USERNAME"

JWT_AUTH = {
'JWT_AUTH_HEADER_PREFIX': 'JWT',
'JWT_ISSUER': [
{'AUDIENCE': 'SET-ME-PLEASE', 'ISSUER': 'http://127.0.0.1:8000/oauth2', 'SECRET_KEY': 'SET-ME-PLEASE'},
"JWT_AUTH_HEADER_PREFIX": "JWT",
"JWT_ISSUER": [
{
"AUDIENCE": "SET-ME-PLEASE",
"ISSUER": "http://127.0.0.1:8000/oauth2",
"SECRET_KEY": "SET-ME-PLEASE",
},
],
'JWT_PUBLIC_SIGNING_JWK_SET': None,
'JWT_AUTH_COOKIE_HEADER_PAYLOAD': 'edx-jwt-cookie-header-payload',
'JWT_AUTH_COOKIE_SIGNATURE': 'edx-jwt-cookie-signature',
'JWT_ALGORITHM': 'HS256',
"JWT_PUBLIC_SIGNING_JWK_SET": None,
"JWT_AUTH_COOKIE_HEADER_PAYLOAD": "edx-jwt-cookie-header-payload",
"JWT_AUTH_COOKIE_SIGNATURE": "edx-jwt-cookie-signature",
"JWT_ALGORITHM": "HS256",
}

CSRF_TRUSTED_ORIGINS = []
Expand Down
10 changes: 6 additions & 4 deletions notesserver/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
LOG_SETTINGS_DEBUG = True
LOG_SETTINGS_DEV_ENV = True

ELASTICSEARCH_INDEX_NAMES = {'notesapi.v1.search_indexes.documents.note': 'notes_index_dev'}
ELASTICSEARCH_INDEX_NAMES = {
"notesapi.v1.search_indexes.documents.note": "notes_index_dev"
}

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'default.db',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "default.db",
}
}

Expand Down
28 changes: 15 additions & 13 deletions notesserver/settings/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
LOG_SETTINGS_DEBUG = True
LOG_SETTINGS_DEV_ENV = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]

# These values are derived from provision-ida-user.sh in the edx/devstack repo.
CLIENT_ID = 'edx_notes_api-backend-service-key'
CLIENT_SECRET = 'edx_notes_api-backend-service-secret'
CLIENT_ID = "edx_notes_api-backend-service-key"
CLIENT_SECRET = "edx_notes_api-backend-service-secret"

ELASTICSEARCH_INDEX_NAMES = {'notesapi.v1.search_indexes.documents.note': 'notes_index'}
ELASTICSEARCH_DSL['default']['hosts'] = os.environ.get('ELASTICSEARCH_DSL', 'edx.devstack.elasticsearch7:9200')
ELASTICSEARCH_INDEX_NAMES = {"notesapi.v1.search_indexes.documents.note": "notes_index"}
ELASTICSEARCH_DSL["default"]["hosts"] = os.environ.get(
"ELASTICSEARCH_DSL", "edx.devstack.elasticsearch7:9200"
)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DB_NAME', 'notes'),
'USER': os.environ.get('DB_USER', 'notes001'),
'PASSWORD': os.environ.get('DB_PASSWORD', 'password'),
'HOST': os.environ.get('DB_HOST', 'edx.devstack.mysql'),
'PORT': os.environ.get('DB_PORT', 3306),
'CONN_MAX_AGE': 60,
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": os.environ.get("DB_NAME", "notes"),
"USER": os.environ.get("DB_USER", "notes001"),
"PASSWORD": os.environ.get("DB_PASSWORD", "password"),
"HOST": os.environ.get("DB_HOST", "edx.devstack.mysql"),
"PORT": os.environ.get("DB_PORT", 3306),
"CONN_MAX_AGE": 60,
}
}

Expand Down
Loading

0 comments on commit 1aa0acb

Please sign in to comment.