From 5fc2a31f50474147a3bf33f982123d617ce5d4c2 Mon Sep 17 00:00:00 2001 From: president Date: Fri, 19 Dec 2025 15:30:38 +0900 Subject: [PATCH] =?UTF-8?q?Django=E3=83=97=E3=83=AD=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=81=AE=E5=88=9D=E6=9C=9F=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82=E7=92=B0=E5=A2=83=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E3=81=AB=E5=9F=BA=E3=81=A5=E3=81=8F=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=82=92settings.py=E3=81=AB=E5=AE=9F=E8=A3=85=E3=81=97?= =?UTF-8?q?=E3=80=81ASGI=E3=81=8A=E3=82=88=E3=81=B3WSGI=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=80=82expenses=E3=82=A2=E3=83=97=E3=83=AA=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=97=E3=80=81=E5=9F=BA=E6=9C=AC=E7=9A=84=E3=81=AA?= =?UTF-8?q?URL=E3=83=AB=E3=83=BC=E3=83=86=E3=82=A3=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=81=A8=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=82=92=E6=95=B4=E5=82=99=E3=80=82=E4=BD=9C=E6=A5=AD=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92diary.md=E3=81=AB=E8=BF=BD=E8=A8=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursorrules | 10 +- .env.example | 8 +- Doc/diary.md | 6 +- config/__init__.py | 0 config/asgi.py | 16 +++ config/settings.py | 133 +++++++++++++++++++++ config/urls.py | 23 ++++ config/wsgi.py | 16 +++ expenses/__init__.py | 0 expenses/admin.py | 3 + expenses/apps.py | 6 + expenses/migrations/__init__.py | 0 expenses/models.py | 3 + expenses/tests.py | 3 + expenses/urls.py | 11 ++ expenses/views.py | 17 +++ manage.py | 22 ++++ templates/base.html | 21 ++++ templates/expenses/csv_upload.html | 17 +++ templates/expenses/expense_list.html | 27 +++++ templates/expenses/monthly_report.html | 27 +++++ templates/expenses/monthly_report_pdf.html | 17 +++ 22 files changed, 379 insertions(+), 7 deletions(-) create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/settings.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100644 expenses/__init__.py create mode 100644 expenses/admin.py create mode 100644 expenses/apps.py create mode 100644 expenses/migrations/__init__.py create mode 100644 expenses/models.py create mode 100644 expenses/tests.py create mode 100644 expenses/urls.py create mode 100644 expenses/views.py create mode 100755 manage.py create mode 100644 templates/base.html create mode 100644 templates/expenses/csv_upload.html create mode 100644 templates/expenses/expense_list.html create mode 100644 templates/expenses/monthly_report.html create mode 100644 templates/expenses/monthly_report_pdf.html diff --git a/.cursorrules b/.cursorrules index bd6ae72..3ffaea7 100644 --- a/.cursorrules +++ b/.cursorrules @@ -1,10 +1,10 @@ # Cursor project rules - 回答言語: 常に日本語で応答 - コーディング: 既存のコードスタイル・命名規則に従う -- プロジェクト概要:クレジットカードCSVデータを分類、レポートを作るWebアプリケーション -- 注意点(任意):仕様書の確認する -- /Doc/diary.md に、作業ログ記録 何をやったかを箇条書きでOK -- この端末にはpostgreのCLIがインストールされています 本体は https:labo.sunamura-llc.com に設置 +- プロジェクト概要: クレジットカードCSVデータを分類、レポートを作るWebアプリケーション +- 注意点(任意): 仕様書の確認をする +- /Doc/diary.md に作業ログ記録(毎回追記、何をやったかを箇条書きでOK) +- この端末にはPostgreSQLのCLIがインストールされています 本体は https://labo.sunamura-llc.com に設置 - sample-data/ 想定されるCSVデータなど設置 - sample-data/ 必要に応じ参照 -- sample-data/ 追加されている場合がある \ No newline at end of file +- sample-data/ 追加されている場合がある diff --git a/.env.example b/.env.example index bd7ffc4..54b67c4 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,9 @@ DJANGO_SECRET_KEY=change-me DJANGO_DEBUG=true -DATABASE_URL=postgresql://postgres:postgres@localhost:5432/card_data_sorting +DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 +DB_ENGINE=django.db.backends.postgresql +DB_NAME=card_data_sorting +DB_USER=postgres +DB_PASSWORD=postgres +DB_HOST=localhost +DB_PORT=5432 diff --git a/Doc/diary.md b/Doc/diary.md index f1199b5..5363cb5 100644 --- a/Doc/diary.md +++ b/Doc/diary.md @@ -1 +1,5 @@ -# 作業日誌 (作業ログです) \ No newline at end of file +# 作業日誌 (作業ログです) +- Djangoプロジェクト作成(config)とexpensesアプリ作成 +- settings.pyに環境変数ベース設定・PostgreSQL設定・日本語/東京タイムゾーン追加 +- ルーティングとテンプレート骨子を追加(CSV取込/明細編集/レポート/PDF) +- .env.exampleをDB設定に合わせて更新 diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..787b362 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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', 'config.settings') + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..394ae2e --- /dev/null +++ b/config/settings.py @@ -0,0 +1,133 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 4.2.27. + +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/ +""" + +import os +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 = os.environ.get('DJANGO_SECRET_KEY', 'django-insecure-change-me') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = os.environ.get('DJANGO_DEBUG', 'false').lower() == 'true' + +ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',') + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'expenses', +] + +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', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / 'templates'], + '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 = 'config.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.postgresql'), + 'NAME': os.environ.get('DB_NAME', 'card_data_sorting'), + 'USER': os.environ.get('DB_USER', 'postgres'), + 'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'), + 'HOST': os.environ.get('DB_HOST', 'localhost'), + 'PORT': os.environ.get('DB_PORT', '5432'), + } +} + + +# 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 = 'ja' + +TIME_ZONE = 'Asia/Tokyo' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'staticfiles' + +MEDIA_URL = 'media/' +MEDIA_ROOT = BASE_DIR / 'media' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..b7c2e81 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for config 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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('expenses.urls')), +] diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..8ae71e3 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config 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', 'config.settings') + +application = get_wsgi_application() diff --git a/expenses/__init__.py b/expenses/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/expenses/admin.py b/expenses/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/expenses/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/expenses/apps.py b/expenses/apps.py new file mode 100644 index 0000000..be2adc1 --- /dev/null +++ b/expenses/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ExpensesConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'expenses' diff --git a/expenses/migrations/__init__.py b/expenses/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/expenses/models.py b/expenses/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/expenses/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/expenses/tests.py b/expenses/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/expenses/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/expenses/urls.py b/expenses/urls.py new file mode 100644 index 0000000..cca2f2d --- /dev/null +++ b/expenses/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from . import views + + +urlpatterns = [ + path('', views.csv_upload, name='csv_upload'), + path('expenses/', views.expense_list, name='expense_list'), + path('reports/monthly/', views.monthly_report, name='monthly_report'), + path('reports/monthly/pdf/', views.monthly_report_pdf, name='monthly_report_pdf'), +] diff --git a/expenses/views.py b/expenses/views.py new file mode 100644 index 0000000..fda43eb --- /dev/null +++ b/expenses/views.py @@ -0,0 +1,17 @@ +from django.shortcuts import render + + +def csv_upload(request): + return render(request, 'expenses/csv_upload.html') + + +def expense_list(request): + return render(request, 'expenses/expense_list.html') + + +def monthly_report(request): + return render(request, 'expenses/monthly_report.html') + + +def monthly_report_pdf(request): + return render(request, 'expenses/monthly_report_pdf.html') diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8e7ac79 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..89cad92 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,21 @@ + + + + + + {% block title %}Card Data Sorting{% endblock %} + + +
+

Card Data Sorting

+ +
+
+ {% block content %}{% endblock %} +
+ + diff --git a/templates/expenses/csv_upload.html b/templates/expenses/csv_upload.html new file mode 100644 index 0000000..d5ab24b --- /dev/null +++ b/templates/expenses/csv_upload.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} + +{% block title %}CSV取込{% endblock %} + +{% block content %} +
+

CSV取込

+
+

ここにDrag & Dropエリアを配置予定。

+
+ {% csrf_token %} + + +
+
+
+{% endblock %} diff --git a/templates/expenses/expense_list.html b/templates/expenses/expense_list.html new file mode 100644 index 0000000..7861343 --- /dev/null +++ b/templates/expenses/expense_list.html @@ -0,0 +1,27 @@ +{% extends 'base.html' %} + +{% block title %}明細編集{% endblock %} + +{% block content %} +
+

明細編集

+ + + + + + + + + + + + + + + + + +
利用日利用先金額店舗区分経費区分会社/家計備考
データはここに表示されます。
+
+{% endblock %} diff --git a/templates/expenses/monthly_report.html b/templates/expenses/monthly_report.html new file mode 100644 index 0000000..51e2a60 --- /dev/null +++ b/templates/expenses/monthly_report.html @@ -0,0 +1,27 @@ +{% extends 'base.html' %} + +{% block title %}月次レポート{% endblock %} + +{% block content %} +
+

月次レポート

+
+ + +
+
+

店舗別合計

+

集計結果をここに表示。

+
+
+

経費区分別合計

+

集計結果をここに表示。

+
+
+

未分類件数の警告をここに表示。

+
+
+{% endblock %} diff --git a/templates/expenses/monthly_report_pdf.html b/templates/expenses/monthly_report_pdf.html new file mode 100644 index 0000000..b47ef1f --- /dev/null +++ b/templates/expenses/monthly_report_pdf.html @@ -0,0 +1,17 @@ + + + + + 月次レポートPDF + + + +

月次レポート

+

PDF出力用テンプレートです。

+ +