Skip to content

Commit

Permalink
Merge pull request #1004 from activist-org/backend-case-output
Browse files Browse the repository at this point in the history
Updates outputs from the backend to camelCase for easy ingestion
  • Loading branch information
andrewtavis authored Nov 13, 2024
2 parents 4d374bf + 64724fa commit 33b22fa
Show file tree
Hide file tree
Showing 95 changed files with 474 additions and 390 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ git remote add upstream https://github.com/activist-org/activist.git
4. Start your docker images with the following:

```bash
# --build only necessary with new dependencies or backend model changes
# --build only necessary with new dependencies or backend model changes.
docker compose --env-file .env.dev up --build

# And to stop the containers when you're done working:
Expand Down
4 changes: 4 additions & 0 deletions backend/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class Meta:
# MARK: Methods


class DeleteUserResponseSerializer(serializers.Serializer[UserModel]):
message = serializers.CharField(max_length=200)


class SignupSerializer(serializers.ModelSerializer[UserModel]):
password_confirmed = serializers.CharField(write_only=True)

Expand Down
2 changes: 2 additions & 0 deletions backend/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
UserTopic,
)
from .serializers import (
DeleteUserResponseSerializer,
LoginSerializer,
PasswordResetSerializer,
SignupSerializer,
Expand Down Expand Up @@ -239,6 +240,7 @@ def post(self, request: Request) -> Response:
class DeleteUserView(APIView):
queryset = UserModel.objects.all()
permission_classes = (IsAuthenticated,)
serializer_class = DeleteUserResponseSerializer

def delete(self, request: Request, pk: UUID | str) -> Response:
user = UserModel.objects.get(pk=pk)
Expand Down
71 changes: 52 additions & 19 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

import django_stubs_ext
import dotenv
from rest_framework import viewsets
from rest_framework.settings import api_settings

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")
Expand All @@ -45,26 +43,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",
Expand All @@ -75,14 +76,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",
Expand All @@ -100,7 +106,7 @@
]


# Database
# MARK: Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
Expand All @@ -115,7 +121,7 @@
}


# Password validation
# MARK: Pass Validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
Expand All @@ -135,7 +141,7 @@

AUTH_USER_MODEL = "authentication.UserModel"

# Internationalization
# MARK: I18n
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"
Expand All @@ -147,18 +153,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")
Expand All @@ -169,6 +175,8 @@
# DEVELOPMENT ONLY
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

# MARK: REST Framework

REST_FRAMEWORK = {
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.AnonRateThrottle",
Expand All @@ -183,19 +191,33 @@
"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,
"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 = {
Expand Down Expand Up @@ -225,3 +247,14 @@
},
},
}

# MARK: API Settings

from rest_framework import viewsets # noqa: E402

django_stubs_ext.monkeypatch(extra_classes=(viewsets.ModelViewSet,))

from rest_framework.settings import api_settings # noqa: E402

# Workaround #471 / monkeypatch() is overriding the REST_FRAMEWORK dict.
api_settings.reload()
8 changes: 4 additions & 4 deletions backend/entities/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@
# MARK: Methods


class GroupAdmin(admin.ModelAdmin):
class GroupAdmin(admin.ModelAdmin[Group]):
list_display = ["group_name", "name"]


class GroupTextAdmin(admin.ModelAdmin):
class GroupTextAdmin(admin.ModelAdmin[GroupText]):
list_display = ["id", "group_id"]


class OrganizationAdmin(admin.ModelAdmin):
class OrganizationAdmin(admin.ModelAdmin[Organization]):
list_display = ["org_name", "name"]


class OrganizationTextAdmin(admin.ModelAdmin):
class OrganizationTextAdmin(admin.ModelAdmin[OrganizationText]):
list_display = ["id", "org_id"]


Expand Down
1 change: 1 addition & 0 deletions backend/entities/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Meta:
name = factory.Faker("word")
tagline = factory.Faker("word")
social_links = ["https://www.instagram.com/activist_org/"]
get_involved_url = "https://activist.org/"
created_by = factory.SubFactory("authentication.factories.UserFactory")
terms_checked = factory.Faker("boolean")
status = factory.SubFactory("entities.factories.StatusTypeFactory", name="Active")
Expand Down
3 changes: 2 additions & 1 deletion backend/entities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Meta:


class OrganizationTextSerializer(serializers.ModelSerializer[OrganizationText]):
orgID = serializers.StringRelatedField(source="org_id.id")
# mypy thinks a generic type argument is needed for StringRelatedField.
org_id = serializers.StringRelatedField(source="org_id.id") # type: ignore[var-annotated]

class Meta:
model = OrganizationText
Expand Down
8 changes: 4 additions & 4 deletions backend/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# In order to add, delete or modify a dependency, please update
# the reference here and then run:
# the reference here and then the following in ./backend:
#
# - `pip-compile --rebuild requirements.in`
# - `pip-compile --rebuild requirements-dev.in`
# - pip-compile --rebuild requirements.in
# - pip-compile --rebuild requirements-dev.in
#
# Make sure we use production deps for constraining installed dev packages. This
# is important as otherwise we could be running tests with different versions
# than production.
#

-r requirements.txt

factory-boy
Expand Down
2 changes: 2 additions & 0 deletions backend/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ djangorestframework==3.15.2
# via
# -r requirements.txt
# drf-spectacular
djangorestframework-camel-case==1.4.2
# via -r requirements.txt
djangorestframework-stubs==3.14.4
# via -r requirements.txt
drf-spectacular==0.26.5
Expand Down
8 changes: 4 additions & 4 deletions backend/requirements.in
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# In order to add, delete or modify a dependency, please update
# the reference here and then run:
#
# - `pip-compile --rebuild requirements.in`
# - `pip-compile --rebuild requirements-dev.in`
# the reference here and then run the following in ./backend:
#
# - pip-compile --rebuild requirements.in
# - pip-compile --rebuild requirements-dev.in

Django
django-cors-headers
django-stubs
django-stubs-ext
djangorestframework
djangorestframework-camel-case
djangorestframework-stubs
drf-spectacular
gunicorn
Expand Down
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ djangorestframework==3.15.2
# via
# -r requirements.in
# drf-spectacular
djangorestframework-camel-case==1.4.2
# via -r requirements.in
djangorestframework-stubs==3.14.4
# via -r requirements.in
drf-spectacular==0.26.5
Expand Down
21 changes: 21 additions & 0 deletions frontend/assets/css/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dark: {
"layer-0":rgba(6, 8, 15, 1);
"layer-1":rgba(19, 19, 22, 1);
"layer-2":rgba(22, 27, 34, 1);
"section-div":rgba(43, 50, 59, 1);
"primary-text":rgba(255, 255, 255, 0.8);
"primary-text-over-layer-2":rgba(208, 209, 211, 1);
"distinct-text":rgba(150, 150, 150, 0.85);
"distinct-text-over-layer-2":rgba(131, 132, 133, 1);
"link-text":rgba(86, 167, 252, 0.9);
"link-text-hover":rgba(134, 192, 253, 0.9);
"menu-selection":rgba(200, 200, 200, 1);
interactive: rgba(133, 126, 123, 1);
"highlight":rgba(70, 70, 70, 0.25);
"highlight-lighter":rgba(120, 120, 120, 0.50);
"cta-orange":rgba(241, 156, 65, 1);
"action-red":rgba(238, 90, 88, 1);
"learn-blue":rgba(62, 146, 204, 1);
"accepted-green":rgba(97, 139, 37, 1);
"warn-yellow":rgba(255, 209, 102, 1);
}
21 changes: 21 additions & 0 deletions frontend/assets/css/light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
light: {
"layer-0":rgba(255, 255, 255, 1);
"layer-1":rgba(246, 248, 250, 1);
"layer-2":rgba(240, 240, 235, 1);
"section-div":rgba(216, 222, 228, 1);
"primary-text":rgba(0, 0, 0, 0.85);
"primary-text-over-layer-2":rgba(36, 36, 35, 1);
"distinct-text":rgba(90, 90, 90, 0.9);
"distinct-text-over-layer-2":rgba(105, 105, 105, 1);
"link-text":rgba(0, 92, 184, 0.9);
"link-text-hover":rgba(0, 59, 119, 0.9);
"menu-selection":rgba(50, 50, 50, 1);
interactive: rgba(75, 75, 67, 1);
"highlight":rgba(140, 140, 140, 0.20);
"highlight-lighter":rgba(120, 120, 120, 0.30);
"cta-orange":rgba(242, 166, 84, 1);
"action-red":rgba(186, 61, 59, 1);
"learn-blue":rgba(33, 118, 174, 1);
"accepted-green":rgba(62, 137, 20, 1);
"warn-yellow":rgba(255, 191, 0, 1);
}
2 changes: 1 addition & 1 deletion frontend/components/EmptyState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="flex w-full flex-col items-center bg-light-layer-0 text-light-text dark:bg-dark-layer-0 dark:text-dark-text"
>
<PageContent
:imgURL="BOOTSTRAP_CLOUD_MOON_URL"
:imgUrl="BOOTSTRAP_CLOUD_MOON_URL"
imgAltText="components.empty_state.img_alt_text"
>
<div>
Expand Down
Loading

0 comments on commit 33b22fa

Please sign in to comment.