diff --git a/.gitignore b/.gitignore index 0518c51..9bcb4ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ venv/ env/ .venv/ -.pyc +*.pyc # 数据库文件 db.sqlite3 diff --git a/core/__pycache__/forms.cpython-313.pyc b/core/__pycache__/forms.cpython-313.pyc index 61454b3..bf01b5a 100644 Binary files a/core/__pycache__/forms.cpython-313.pyc and b/core/__pycache__/forms.cpython-313.pyc differ diff --git a/core/__pycache__/urls.cpython-313.pyc b/core/__pycache__/urls.cpython-313.pyc index 84b50cc..613685e 100644 Binary files a/core/__pycache__/urls.cpython-313.pyc and b/core/__pycache__/urls.cpython-313.pyc differ diff --git a/core/__pycache__/views.cpython-313.pyc b/core/__pycache__/views.cpython-313.pyc index 5be0e97..af19e40 100644 Binary files a/core/__pycache__/views.cpython-313.pyc and b/core/__pycache__/views.cpython-313.pyc differ diff --git a/core/forms.py b/core/forms.py index 6b7d8d6..6f02b10 100644 --- a/core/forms.py +++ b/core/forms.py @@ -28,7 +28,7 @@ class InsightRecordForm(forms.ModelForm): model = InsightRecord fields = ['content', 'file'] widgets = { - 'content': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'placeholder': '请输入今日感悟'}), + 'content': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'placeholder': '请输入感悟'}), 'file': forms.FileInput(attrs={'class': 'form-control'}), } diff --git a/core/templates/core/index.html b/core/templates/core/index.html index 943e9b6..08836ff 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -61,19 +61,20 @@ -
-
-
快捷操作
-
-
- -
diff --git a/core/templates/core/today_records.html b/core/templates/core/today_records.html new file mode 100644 index 0000000..6eeaa5c --- /dev/null +++ b/core/templates/core/today_records.html @@ -0,0 +1,107 @@ +{% extends 'core/base.html' %} + +{% block content %} +

今日记录 ({{ today }})

+ + +
+ 添加阅读记录 + 添加感悟记录 +
+ +
+ +
+
+
+
阅读记录
+
+
+ {% if reading_records %} + + + + + + + + + + + + + {% for reading in reading_records %} + + + + + + + + + {% endfor %} + +
类型标题来源进度笔记操作
{{ reading.get_type_display }}{{ reading.title }}{{ reading.source|default:"-" }}{{ reading.progress|default:"-" }}{{ reading.note|truncatechars:50|default:"-" }} + {% if reading.file %} + + + + {% endif %} + + + + + + +
+ {% else %} +

今日没有阅读记录,点击上方按钮添加

+ {% endif %} +
+
+
+ + +
+
+
+
感悟记录
+
+
+ {% if insight_records %} + + + + + + + + + {% for insight in insight_records %} + + + + + {% endfor %} + +
内容操作
{{ insight.content }} + {% if insight.file %} + + + + {% endif %} + + + + + + +
+ {% else %} +

今日没有感悟记录,点击上方按钮添加

+ {% endif %} +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/core/urls.py b/core/urls.py index a5939a4..73874dc 100644 --- a/core/urls.py +++ b/core/urls.py @@ -14,6 +14,15 @@ urlpatterns = [ path('yesterday/insight//edit/', views.edit_insight, name='edit_insight'), path('yesterday/insight//delete/', views.delete_insight, name='delete_insight'), + # 今日记录 + path('today/', views.today_records, name='today_records'), + path('today/reading/add/', views.add_today_reading, name='add_today_reading'), + path('today/reading//edit/', views.edit_today_reading, name='edit_today_reading'), + path('today/reading//delete/', views.delete_today_reading, name='delete_today_reading'), + path('today/insight/add/', views.add_today_insight, name='add_today_insight'), + path('today/insight//edit/', views.edit_today_insight, name='edit_today_insight'), + path('today/insight//delete/', views.delete_today_insight, name='delete_today_insight'), + # 家庭事项 path('family-tasks/', views.family_tasks, name='family_tasks'), path('family-tasks/add/', views.add_family_task, name='add_family_task'), diff --git a/core/views.py b/core/views.py index 85c8fb5..7b99fbf 100644 --- a/core/views.py +++ b/core/views.py @@ -179,6 +179,116 @@ def delete_insight(request, pk): context = {'insight': insight} return render(request, 'core/delete_insight.html', context) +# 今日记录视图 +def today_records(request): + """今日记录""" + logger.info("用户访问今日记录页面") + today = timezone.now().date() + + # 获取今日阅读记录 + reading_records = ReadingRecord.objects.filter(date=today) + + # 获取今日感悟记录 + insight_records = InsightRecord.objects.filter(date=today) + + context = { + 'today': today, + 'reading_records': reading_records, + 'insight_records': insight_records, + } + + return render(request, 'core/today_records.html', context) + +# 添加今日阅读记录 +def add_today_reading(request): + """添加今日阅读记录""" + if request.method == 'POST': + form = ReadingRecordForm(request.POST, request.FILES) + if form.is_valid(): + reading = form.save(commit=False) + reading.date = timezone.now().date() + reading.save() + logger.info(f"添加今日阅读记录: {form.cleaned_data['title']}") + return redirect('today_records') + else: + form = ReadingRecordForm() + + context = {'form': form} + return render(request, 'core/add_reading.html', context) + +# 编辑今日阅读记录 +def edit_today_reading(request, pk): + """编辑今日阅读记录""" + reading = get_object_or_404(ReadingRecord, pk=pk) + if request.method == 'POST': + form = ReadingRecordForm(request.POST, request.FILES, instance=reading) + if form.is_valid(): + form.save() + logger.info(f"编辑今日阅读记录: {form.cleaned_data['title']}") + return redirect('today_records') + else: + form = ReadingRecordForm(instance=reading) + + context = {'form': form, 'reading': reading} + return render(request, 'core/edit_reading.html', context) + +# 删除今日阅读记录 +def delete_today_reading(request, pk): + """删除今日阅读记录""" + reading = get_object_or_404(ReadingRecord, pk=pk) + if request.method == 'POST': + reading.delete() + logger.info(f"删除今日阅读记录: {reading.title}") + return redirect('today_records') + + context = {'reading': reading} + return render(request, 'core/delete_reading.html', context) + +# 添加今日感悟记录 +def add_today_insight(request): + """添加今日感悟记录""" + if request.method == 'POST': + form = InsightRecordForm(request.POST, request.FILES) + if form.is_valid(): + insight = form.save(commit=False) + insight.date = timezone.now().date() + insight.save() + logger.info("添加今日感悟记录") + return redirect('today_records') + else: + form = InsightRecordForm() + + context = {'form': form} + return render(request, 'core/add_insight.html', context) + +# 编辑今日感悟记录 +def edit_today_insight(request, pk): + """编辑今日感悟记录""" + insight = get_object_or_404(InsightRecord, pk=pk) + if request.method == 'POST': + form = InsightRecordForm(request.POST, request.FILES, instance=insight) + if form.is_valid(): + form.save() + logger.info("编辑今日感悟记录") + return redirect('today_records') + else: + form = InsightRecordForm(instance=insight) + + context = {'form': form, 'insight': insight} + return render(request, 'core/edit_insight.html', context) + +# 删除今日感悟记录 +def delete_today_insight(request, pk): + """删除今日感悟记录""" + insight = get_object_or_404(InsightRecord, pk=pk) + if request.method == 'POST': + insight.delete() + logger.info("删除今日感悟记录") + return redirect('today_records') + + context = {'insight': insight} + return render(request, 'core/delete_insight.html', context) + # 家庭事项视图 def family_tasks(request): """家庭事项"""