-
Notifications
You must be signed in to change notification settings - Fork 228
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
Updates outputs from the backend to camelCase for easy ingestion #1004
Changes from 1 commit
3e39f94
c5c508d
10162bb
48f9e5e
4556b4a
bdeb347
c6cf2d7
2d6eab5
dcd9e1d
62e907d
64724fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
django_stubs_ext.monkeypatch(extra_classes=(viewsets.ModelViewSet,)) | ||
dotenv.load_dotenv() | ||
|
||
# MARK: DB | ||
|
||
DATABASE_HOST = os.getenv("DATABASE_HOST") | ||
DATABASE_NAME = os.getenv("DATABASE_NAME") | ||
|
@@ -45,26 +46,29 @@ | |
"DJANGO_CSRF_TRUSTED_ORIGINS", "http://localhost" | ||
).split(" ") | ||
|
||
# Application definition | ||
# MARK: Apps | ||
|
||
INSTALLED_APPS = [ | ||
"rest_framework", | ||
"rest_framework.authtoken", | ||
"corsheaders", | ||
"django.contrib.admin", | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
"djangorestframework_camel_case", | ||
"drf_spectacular", | ||
"rest_framework", | ||
"rest_framework.authtoken", | ||
"backend", | ||
"authentication", | ||
"entities", | ||
"content", | ||
"events", | ||
"drf_spectacular", | ||
"corsheaders", | ||
] | ||
|
||
# MARK: Middleware | ||
|
||
MIDDLEWARE = [ | ||
"django.middleware.security.SecurityMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
|
@@ -75,14 +79,19 @@ | |
"django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
"corsheaders.middleware.CorsMiddleware", | ||
"django.middleware.common.CommonMiddleware", | ||
"djangorestframework_camel_case.middleware.CamelCaseMiddleWare", | ||
] | ||
|
||
# MARK: URLs | ||
|
||
CORS_ALLOWED_ORIGINS = [ | ||
"http://localhost:3000", | ||
] | ||
|
||
ROOT_URLCONF = "backend.urls" | ||
|
||
# MARK: Templates | ||
|
||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
|
@@ -100,7 +109,7 @@ | |
] | ||
|
||
|
||
# Database | ||
# MARK: Database | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
|
@@ -115,7 +124,7 @@ | |
} | ||
|
||
|
||
# Password validation | ||
# MARK: Pass Validation | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
|
@@ -135,7 +144,7 @@ | |
|
||
AUTH_USER_MODEL = "authentication.UserModel" | ||
|
||
# Internationalization | ||
# MARK: I18n | ||
# https://docs.djangoproject.com/en/4.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = "en-us" | ||
|
@@ -147,18 +156,18 @@ | |
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# MARK: Static Files | ||
# https://docs.djangoproject.com/en/4.2/howto/static-files/ | ||
|
||
STATIC_ROOT = BASE_DIR / "static/" | ||
STATIC_URL = "static/" | ||
|
||
# Default primary key field type | ||
# MARK: Primary Key | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" | ||
|
||
# Email Settings | ||
# MARK: Email | ||
# https://docs.djangoproject.com/en/5.0/topics/email/ | ||
|
||
EMAIL_HOST = os.getenv("EMAIL_HOST") | ||
|
@@ -169,6 +178,8 @@ | |
# DEVELOPMENT ONLY | ||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" | ||
|
||
# MARK: REST Framework | ||
|
||
REST_FRAMEWORK = { | ||
"DEFAULT_THROTTLE_CLASSES": [ | ||
"rest_framework.throttling.AnonRateThrottle", | ||
|
@@ -183,19 +194,36 @@ | |
"rest_framework.authentication.TokenAuthentication", | ||
], | ||
"EXCEPTION_HANDLER": "backend.exception_handler.bad_request_logger", | ||
"DEFAULT_RENDERER_CLASSES": ( | ||
"djangorestframework_camel_case.render.CamelCaseJSONRenderer", | ||
"djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer", | ||
), | ||
"DEFAULT_PARSER_CLASSES": ( | ||
"djangorestframework_camel_case.parser.CamelCaseFormParser", | ||
"djangorestframework_camel_case.parser.CamelCaseMultiPartParser", | ||
"djangorestframework_camel_case.parser.CamelCaseJSONParser", | ||
), | ||
} | ||
|
||
# MARK: Spectacular | ||
|
||
SPECTACULAR_SETTINGS = { | ||
"TITLE": "activist.org API", | ||
"DESCRIPTION": "Open-source, nonprofit activism platform", | ||
"DESCRIPTION": "An open-source activism platform", | ||
"VERSION": "0.1.0", | ||
"SERVE_INCLUDE_SCHEMA": False, | ||
"CAMELIZE_NAMES": False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see another comment where you noted you were still getting snake_case responses. Could this have something to do with it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good check :) This is specifically for the table names within the Swagger UI, not the results of the backend itself. Keeping the table names snake_case makes sense to me as they should have consistent identifiers. |
||
"POSTPROCESSING_HOOKS": [ | ||
"drf_spectacular.hooks.postprocess_schema_enums", | ||
"drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields", | ||
], | ||
"SWAGGER_UI_FAVICON_HREF": "https://github.com/activist-org/activist/blob/main/backend/static/swagger_favicon.png?raw=true", | ||
} | ||
|
||
# Workaround #471 / monkeypatch() is overriding the REST_FRAMEWORK dict. | ||
api_settings.reload() | ||
|
||
# Logging Configuration | ||
# MARK: Logging | ||
# https://docs.djangoproject.com/en/4.2/topics/logging/ | ||
|
||
LOGGING = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ class Meta: | |
|
||
|
||
class OrganizationTextSerializer(serializers.ModelSerializer[OrganizationText]): | ||
orgID = serializers.StringRelatedField(source="org_id.id") | ||
org_id = serializers.StringRelatedField(source="org_id.id") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to ignore a mypy type warning here in my PR |
||
|
||
class Meta: | ||
model = OrganizationText | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@to-sta, this is where I have the parser classes being defined as in the djangorestframework-camel-case docs, but we're still getting snake_case in responses in the frontend.