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 @@ + + +
+ + +ここにDrag & Dropエリアを配置予定。
+ +| 利用日 | +利用先 | +金額 | +店舗区分 | +経費区分 | +会社/家計 | +備考 | +
|---|---|---|---|---|---|---|
| データはここに表示されます。 | +||||||
集計結果をここに表示。
+集計結果をここに表示。
+未分類件数の警告をここに表示。
+PDF出力用テンプレートです。
+ +