Skip to content

Commit

Permalink
Merge pull request #13 from AnimalFoodBank/wip/oct30-django-vite
Browse files Browse the repository at this point in the history
Added Vue 3 Composition API
  • Loading branch information
delano authored Nov 1, 2023
2 parents e628da7 + 9e51e3e commit cccbc19
Show file tree
Hide file tree
Showing 124 changed files with 4,328 additions and 230 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ local_settings.py
db.sqlite3
.vscode/
tmp/*
node_modules/
21 changes: 11 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
# pre-commit run --all-files
#
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

# TODO: Enable black after formatting is standardized.
# - repo: https://github.com/psf/black
# rev: 22.10.0
# hooks:
# - id: black

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3.11
Empty file added afb-vite/afb/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions afb-vite/afb/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for afb project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "afb.settings")

application = get_asgi_application()
208 changes: 208 additions & 0 deletions afb-vite/afb/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
"""
Django settings for afb project.
Generated by 'django-admin startproject' using Django 4.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-k3nma!u)7oz(lt346n-=rx=rt%u_^j8-rdz3p(y3o$ot0%soqh"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition
# http://127.0.0.1:8000/static/src/assets/logo.png

INSTALLED_APPS = [
"unfold", # https://github.com/unfoldadmin/django-unfold
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"phonenumber_field",
"crispy_forms",
# 'tailwind',
"django_vite",
"crispy_tailwind",
# 'theme', # python manage.py tailwind init
"afbcore",
"django_browser_reload",
]

# correspond to your build.outDir in your ViteJS configuration.
DJANGO_VITE_ASSETS_PATH = BASE_DIR / "ui" / "dist"

# ViteJS webserver protocol (default : http).
DJANGO_VITE_DEV_SERVER_PROTOCOL = "http"

# ViteJS webserver hostname (default : localhost).
DJANGO_VITE_DEV_SERVER_HOST = "127.0.0.1"

# ViteJS webserver port (default : 3000)
DJANGO_VITE_DEV_SERVER_PORT = "3000"

# assets are included as modules using the ViteJS webserver. This will enable HMR for your assets.
DJANGO_VITE_DEV_MODE = True

# ViteJS webserver path to the HMR client used in the vite_hmr_client tag (default : @vite/client).
DJANGO_VITE_WS_CLIENT_URL = "@vite/client"

# Absolute path (including filename) to your ViteJS manifest file. This
# file is generated in your DJANGO_VITE_ASSETS_PATH. But if you are in
# production (DEBUG is false) then it is in your STATIC_ROOT after you
# collected your static files (supports pathlib.Path or str).
DJANGO_VITE_MANIFEST_PATH = DJANGO_VITE_ASSETS_PATH / "manifest.json"

# prefix directory of your static files built by Vite. (default : "")
# Use it if you want to avoid conflicts with other static files in your project.
DJANGO_VITE_STATIC_URL_PREFIX = ""

VITE_INPUT_CSS = "input.css"
VITE_OUTPUT_CSS = "output.css"

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-STATIC_ROOT
# https://docs.djangoproject.com/en/4.2/howto/static-files/#deployment
# This should be an initially empty destination directory. it is not a place to
# store your static files permanently.
STATIC_ROOT = BASE_DIR / "staticfiles"

# For prod:
# https://docs.djangoproject.com/en/4.2/howto/static-files/deployment/#staticfiles-from-cdn
# https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-STORAGES
STATIC_URL = "static/"

STATICFILES_DIRS = [
BASE_DIR / "static",
BASE_DIR / "ui" / "dist",
BASE_DIR / "ui" / "public",
DJANGO_VITE_ASSETS_PATH,
]


# https://github.com/django-crispy-forms/crispy-tailwind
CRISPY_ALLOWED_TEMPLATE_PACKS = "tailwind"

CRISPY_TEMPLATE_PACK = "tailwind"


PHONENUMBER_DB_FORMAT = "INTERNATIONAL"
PHONENUMBER_DEFAULT_FORMAT = "E164"
PHONENUMBER_DEFAULT_REGION = "CA"


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_browser_reload.middleware.BrowserReloadMiddleware",
]

ROOT_URLCONF = "afb.urls"

# Django-Tailwind
# https://django-tailwind.readthedocs.io/en/latest/installation.html#configuration

# TAILWIND_APP_NAME = "theme"

AUTH_USER_MODEL = "afbcore.User"

INTERNAL_IPS = [
# Add local IP addresses here for tailwind to work, then run:
# * (Dev) `python manage.py tailwind install`
# * (Production) `python manage.py tailwind build`
"127.0.0.1",
]

# Templates
# https://docs.djangoproject.com/en/4.2/ref/settings/#templates

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"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 = "afb.wsgi.application"


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

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


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

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


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

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
34 changes: 34 additions & 0 deletions afb-vite/afb/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
URL configuration for afb project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
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 include, path

from afbcore.views import AboutView, ClientSignupFormView, DashboardView, MyLoginView
from afbcore.views import ClientRequestView

urlpatterns = [
path("admin/", admin.site.urls),
path("dashboard", DashboardView.as_view(), name="dashboard"),
path("", DashboardView.as_view()),
path("join/", ClientSignupFormView.as_view()),
# Part of django-tailwind
# See https://django-tailwind.readthedocs.io/en/latest/installation.html#configuration
path("__reload__/", include("django_browser_reload.urls")),
path("request/", ClientRequestView.as_view(), name="create_request"),
path("login/", MyLoginView.as_view(), name="login"),
path("about/", AboutView.as_view()),
]
16 changes: 16 additions & 0 deletions afb-vite/afb/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for afb project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "afb.settings")

application = get_wsgi_application()
Empty file added afb-vite/afbcore/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions afb-vite/afbcore/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Client, Manager, Volunteer, User

admin.site.register(User, UserAdmin)
admin.site.register(Client)
admin.site.register(Manager)
admin.site.register(Volunteer)


# Register your models here.
6 changes: 6 additions & 0 deletions afb-vite/afbcore/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AfbcoreConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "afbcore"
10 changes: 10 additions & 0 deletions afb-vite/afbcore/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#

from django import forms

from .client import ClientSignupForm


class LoginForm(forms.Form):
username = forms.CharField(max_length=100)
password = forms.CharField(widget=forms.PasswordInput)
16 changes: 16 additions & 0 deletions afb-vite/afbcore/forms/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.forms import ModelForm

from afbcore.models import Client


class ClientSignupForm(ModelForm):
class Meta:
model = Client
fields = [
"first_name",
"last_name",
"email",
"address",
"phone_number",
# "status",
]
Loading

0 comments on commit cccbc19

Please sign in to comment.