Skip to content
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

Feature/lint python redo #603

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
max-line-length = 88
extend-ignore = E203, W503
exclude =
.git,
__pycache__,
migrations,
venv,
settings.py
1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.4
2 changes: 1 addition & 1 deletion backend/backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")

application = get_asgi_application()
112 changes: 59 additions & 53 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"""

from pathlib import Path

from decouple import config

VERSION = '1.0.0'
VERSION = "1.0.0"

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -23,68 +24,68 @@
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')
SECRET_KEY = config("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=bool)
DEBUG = config("DEBUG", default=False, cast=bool)

ALLOWED_HOSTS = config("DJANGO_ALLOWED_HOSTS", default="localhost").split(" ")

# Application definition

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ctj_api.apps.CtjApiConfig',
'rest_framework',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"ctj_api.apps.CtjApiConfig",
"rest_framework",
"django_vite",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'backend.urls'
ROOT_URLCONF = "backend.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'frontend/templates/frontend'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "frontend/templates/frontend"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'backend.wsgi.application'
WSGI_APPLICATION = "backend.wsgi.application"


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

DATABASES = {
'default': {
'ENGINE': config('SQL_ENGINE'),
'NAME': config('SQL_DATABASE'),
'USER': config('SQL_USER'),
'PASSWORD': config('SQL_PASSWORD'),
'HOST': config('SQL_HOST'),
'PORT': config('SQL_PORT'),
"default": {
"ENGINE": config("SQL_ENGINE"),
"NAME": config("SQL_DATABASE"),
"USER": config("SQL_USER"),
"PASSWORD": config("SQL_PASSWORD"),
"HOST": config("SQL_HOST"),
"PORT": config("SQL_PORT"),
}
}

Expand All @@ -93,26 +94,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -122,27 +123,32 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

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

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


# django-vite settings
# https://github.com/MrBin99/django-vite
DJANGO_VITE = {
"default": {
# enable vite HMR in dev mode
"dev_mode": config("DEBUG", default=False, cast=bool),
"dev_server_port": 5175,
# resolve static asset paths in production
"manifest_path": Path(BASE_DIR / "frontend" / "static" / "vite_assets_dist" / ".vite" / "manifest.json").resolve()
}
"default": {
# enable vite HMR in dev mode
"dev_mode": config("DEBUG", default=False, cast=bool),
"dev_server_port": 5175,
# resolve static asset paths in production
"manifest_path": Path(
BASE_DIR
/ "frontend"
/ "static"
/ "vite_assets_dist"
/ ".vite"
/ "manifest.json"
).resolve(),
}
}
# Add the build.outDir from vite.config.js to STATICFILES_DIRS
# so that collectstatic can collect your compiled vite assets.
STATICFILES_DIRS = [
BASE_DIR / 'frontend/static/vite_assets_dist'
]
STATICFILES_DIRS = [BASE_DIR / "frontend/static/vite_assets_dist"]
27 changes: 16 additions & 11 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,33 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
# from django.contrib import admin
from django.urls import path, re_path, include

from django.http import JsonResponse

# from django.contrib import admin
from django.urls import include, path, re_path
from django.views.generic import TemplateView


# Custom handler for incorrect API routes
def api_not_found(request, exception=None):
return JsonResponse({
'error': 'API endpoint not found',
'status_code': 404,
'message': 'The requested API endpoint does not exist'
}, status=404)
return JsonResponse(
{
"error": "API endpoint not found",
"status_code": 404,
"message": "The requested API endpoint does not exist",
},
status=404,
)


urlpatterns = [
path('api/', include('ctj_api.urls'), name="api"),
path("api/", include("ctj_api.urls"), name="api"),
# Custom error handler for invalid API routes
re_path(r'^api/.*$', api_not_found), # Catch-all for incorrect API routes

re_path(r"^api/.*$", api_not_found), # Catch-all for incorrect API routes
# Catch-all for frontend (React)
re_path(
r'^.*$',
r"^.*$",
TemplateView.as_view(template_name="index.html"),
name="index",
),
Expand Down
2 changes: 1 addition & 1 deletion backend/backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")

application = get_wsgi_application()
3 changes: 3 additions & 0 deletions backend/ctj_api/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin

from .models import Opportunities

# Register your models here.
admin.site.register(Opportunities)
4 changes: 2 additions & 2 deletions backend/ctj_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class CtjApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ctj_api'
default_auto_field = "django.db.models.BigAutoField"
name = "ctj_api"
3 changes: 2 additions & 1 deletion backend/ctj_api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 5.0.6 on 2024-07-13 10:05

import django.utils.timezone
import uuid

import django.utils.timezone
from django.db import migrations, models


Expand Down
4 changes: 2 additions & 2 deletions backend/ctj_api/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import uuid

from django.db import models
from django.utils import timezone

import uuid


class Opportunities(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Expand Down
4 changes: 3 additions & 1 deletion backend/ctj_api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from rest_framework import serializers

from ctj_api.models import Opportunities


class OpportunitiesSerializer(serializers.ModelSerializer):
class Meta:
model = Opportunities
fields = ['id','role', 'subrole','project']
fields = ["id", "role", "subrole", "project"]
2 changes: 1 addition & 1 deletion backend/ctj_api/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
# from django.test import TestCase

# Create your tests here.
8 changes: 4 additions & 4 deletions backend/ctj_api/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.urls import path
from ctj_api import views

from ctj_api import views

urlpatterns = [
path('opportunities/', views.OpportunitiesList.as_view()),
path('opportunities/<uuid:pk>/', views.OpportunitiesDetails.as_view()),
path('healthcheck', views.Healthcheck.as_view(), name='healthcheck')
path("opportunities/", views.OpportunitiesList.as_view()),
path("opportunities/<uuid:pk>/", views.OpportunitiesDetails.as_view()),
path("healthcheck", views.Healthcheck.as_view(), name="healthcheck"),
]
24 changes: 15 additions & 9 deletions backend/ctj_api/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import time

from django.conf import settings
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.views import APIView

from ctj_api.models import Opportunities
from ctj_api.serializers import OpportunitiesSerializer
from django.conf import settings
import time


class OpportunitiesList(generics.ListCreateAPIView):
queryset = Opportunities.objects.all()
Expand All @@ -15,6 +18,7 @@ class OpportunitiesDetails(generics.RetrieveUpdateDestroyAPIView):
queryset = Opportunities.objects.all()
serializer_class = OpportunitiesSerializer


class Healthcheck(APIView):
start_time = time.time()

Expand All @@ -23,10 +27,12 @@ def get(self, request):
uptime_hours = uptime_seconds / 3600
hostname = request.get_host()

return Response({
"message": "healthcheck",
"uptime": f"{uptime_hours:.2f} hours",
# "uptime": f"{uptime_seconds:.1f} seconds",
"version": settings.VERSION,
"hostname": hostname
})
return Response(
{
"message": "healthcheck",
"uptime": f"{uptime_hours:.2f} hours",
# "uptime": f"{uptime_seconds:.1f} seconds",
"version": settings.VERSION,
"hostname": hostname,
}
)
4 changes: 2 additions & 2 deletions backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading