Djangoプロジェクトの初期設定を追加。環境変数に基づく設定をsettings.pyに実装し、ASGIおよびWSGI設定ファイルを作成。expensesアプリを追加し、基本的なURLルーティングとテンプレートを整備。作業ログをdiary.mdに追記。

This commit is contained in:
president
2025-12-19 15:30:38 +09:00
parent bfca4ee185
commit 5fc2a31f50
22 changed files with 379 additions and 7 deletions

View File

@@ -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/ 追加されている場合がある
- sample-data/ 追加されている場合がある

View File

@@ -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

View File

@@ -1 +1,5 @@
# 作業日誌 (作業ログです)
# 作業日誌 (作業ログです)
- Djangoプロジェクト作成configとexpensesアプリ作成
- settings.pyに環境変数ベース設定・PostgreSQL設定・日本語/東京タイムゾーン追加
- ルーティングとテンプレート骨子を追加CSV取込/明細編集/レポート/PDF
- .env.exampleをDB設定に合わせて更新

0
config/__init__.py Normal file
View File

16
config/asgi.py Normal file
View File

@@ -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()

133
config/settings.py Normal file
View File

@@ -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'

23
config/urls.py Normal file
View File

@@ -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')),
]

16
config/wsgi.py Normal file
View File

@@ -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()

0
expenses/__init__.py Normal file
View File

3
expenses/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
expenses/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ExpensesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'expenses'

View File

3
expenses/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
expenses/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

11
expenses/urls.py Normal file
View File

@@ -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'),
]

17
expenses/views.py Normal file
View File

@@ -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')

22
manage.py Executable file
View File

@@ -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()

21
templates/base.html Normal file
View File

@@ -0,0 +1,21 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Card Data Sorting{% endblock %}</title>
</head>
<body>
<header>
<h1>Card Data Sorting</h1>
<nav>
<a href="{% url 'csv_upload' %}">CSV取込</a>
<a href="{% url 'expense_list' %}">明細編集</a>
<a href="{% url 'monthly_report' %}">月次レポート</a>
</nav>
</header>
<main>
{% block content %}{% endblock %}
</main>
</body>
</html>

View File

@@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% block title %}CSV取込{% endblock %}
{% block content %}
<section>
<h2>CSV取込</h2>
<div>
<p>ここにDrag & Dropエリアを配置予定。</p>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="csv_file">
<button type="submit">アップロード</button>
</form>
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% block title %}明細編集{% endblock %}
{% block content %}
<section>
<h2>明細編集</h2>
<table>
<thead>
<tr>
<th>利用日</th>
<th>利用先</th>
<th>金額</th>
<th>店舗区分</th>
<th>経費区分</th>
<th>会社/家計</th>
<th>備考</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7">データはここに表示されます。</td>
</tr>
</tbody>
</table>
</section>
{% endblock %}

View File

@@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% block title %}月次レポート{% endblock %}
{% block content %}
<section>
<h2>月次レポート</h2>
<form method="get">
<label>
年月
<input type="month" name="target_month">
</label>
<button type="submit">表示</button>
</form>
<div>
<h3>店舗別合計</h3>
<p>集計結果をここに表示。</p>
</div>
<div>
<h3>経費区分別合計</h3>
<p>集計結果をここに表示。</p>
</div>
<div>
<p>未分類件数の警告をここに表示。</p>
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>月次レポートPDF</title>
<style>
body { font-family: sans-serif; }
h1, h2 { margin: 0 0 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #333; padding: 6px; }
</style>
</head>
<body>
<h1>月次レポート</h1>
<p>PDF出力用テンプレートです。</p>
</body>
</html>