增加今天信息模块的功能
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,7 +2,7 @@
|
|||||||
venv/
|
venv/
|
||||||
env/
|
env/
|
||||||
.venv/
|
.venv/
|
||||||
.pyc
|
*.pyc
|
||||||
|
|
||||||
# 数据库文件
|
# 数据库文件
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -28,7 +28,7 @@ class InsightRecordForm(forms.ModelForm):
|
|||||||
model = InsightRecord
|
model = InsightRecord
|
||||||
fields = ['content', 'file']
|
fields = ['content', 'file']
|
||||||
widgets = {
|
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'}),
|
'file': forms.FileInput(attrs={'class': 'form-control'}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="btn-group-vertical w-100">
|
<div class="btn-group-vertical w-100">
|
||||||
|
<a href="{% url 'today_records' %}" class="btn btn-outline-primary mb-2">添加今日信息</a>
|
||||||
<a href="{% url 'yesterday_records' %}" class="btn btn-outline-primary mb-2">追加昨日信息</a>
|
<a href="{% url 'yesterday_records' %}" class="btn btn-outline-primary mb-2">追加昨日信息</a>
|
||||||
<a href="{% url 'today_plan' %}" class="btn btn-outline-primary mb-2">管理今日计划</a>
|
<a href="{% url 'today_plan' %}" class="btn btn-outline-primary mb-2">管理今日计划</a>
|
||||||
<a href="{% url 'generate_report' %}" class="btn btn-outline-primary mb-2">查看今日报告</a>
|
<a href="{% url 'generate_report' %}" class="btn btn-outline-primary mb-2">查看今日报告</a>
|
||||||
|
|||||||
107
core/templates/core/today_records.html
Normal file
107
core/templates/core/today_records.html
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
{% extends 'core/base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>今日记录 ({{ today }})</h2>
|
||||||
|
|
||||||
|
<!-- 添加记录按钮 -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<a href="{% url 'add_today_reading' %}" class="btn btn-primary">添加阅读记录</a>
|
||||||
|
<a href="{% url 'add_today_insight' %}" class="btn btn-success">添加感悟记录</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<!-- 阅读记录 -->
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header bg-primary text-white">
|
||||||
|
<h5 class="card-title mb-0">阅读记录</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% if reading_records %}
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>类型</th>
|
||||||
|
<th>标题</th>
|
||||||
|
<th>来源</th>
|
||||||
|
<th>进度</th>
|
||||||
|
<th>笔记</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for reading in reading_records %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ reading.get_type_display }}</td>
|
||||||
|
<td>{{ reading.title }}</td>
|
||||||
|
<td>{{ reading.source|default:"-" }}</td>
|
||||||
|
<td>{{ reading.progress|default:"-" }}</td>
|
||||||
|
<td>{{ reading.note|truncatechars:50|default:"-" }}</td>
|
||||||
|
<td>
|
||||||
|
{% if reading.file %}
|
||||||
|
<a href="{{ reading.file.url }}" class="btn btn-sm btn-info" title="查看附件" target="_blank">
|
||||||
|
<i class="bi bi-file-earmark"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{% url 'edit_today_reading' reading.id %}" class="btn btn-sm btn-warning" title="编辑">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'delete_today_reading' reading.id %}" class="btn btn-sm btn-danger" title="删除">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-muted">今日没有阅读记录,点击上方按钮添加</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 感悟记录 -->
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header bg-success text-white">
|
||||||
|
<h5 class="card-title mb-0">感悟记录</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% if insight_records %}
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>内容</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for insight in insight_records %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ insight.content }}</td>
|
||||||
|
<td>
|
||||||
|
{% if insight.file %}
|
||||||
|
<a href="{{ insight.file.url }}" class="btn btn-sm btn-info" title="查看附件" target="_blank">
|
||||||
|
<i class="bi bi-file-earmark"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{% url 'edit_today_insight' insight.id %}" class="btn btn-sm btn-warning" title="编辑">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'delete_today_insight' insight.id %}" class="btn btn-sm btn-danger" title="删除">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-muted">今日没有感悟记录,点击上方按钮添加</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -14,6 +14,15 @@ urlpatterns = [
|
|||||||
path('yesterday/insight/<int:pk>/edit/', views.edit_insight, name='edit_insight'),
|
path('yesterday/insight/<int:pk>/edit/', views.edit_insight, name='edit_insight'),
|
||||||
path('yesterday/insight/<int:pk>/delete/', views.delete_insight, name='delete_insight'),
|
path('yesterday/insight/<int:pk>/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/<int:pk>/edit/', views.edit_today_reading, name='edit_today_reading'),
|
||||||
|
path('today/reading/<int:pk>/delete/', views.delete_today_reading, name='delete_today_reading'),
|
||||||
|
path('today/insight/add/', views.add_today_insight, name='add_today_insight'),
|
||||||
|
path('today/insight/<int:pk>/edit/', views.edit_today_insight, name='edit_today_insight'),
|
||||||
|
path('today/insight/<int:pk>/delete/', views.delete_today_insight, name='delete_today_insight'),
|
||||||
|
|
||||||
# 家庭事项
|
# 家庭事项
|
||||||
path('family-tasks/', views.family_tasks, name='family_tasks'),
|
path('family-tasks/', views.family_tasks, name='family_tasks'),
|
||||||
path('family-tasks/add/', views.add_family_task, name='add_family_task'),
|
path('family-tasks/add/', views.add_family_task, name='add_family_task'),
|
||||||
|
|||||||
110
core/views.py
110
core/views.py
@@ -179,6 +179,116 @@ def delete_insight(request, pk):
|
|||||||
context = {'insight': insight}
|
context = {'insight': insight}
|
||||||
return render(request, 'core/delete_insight.html', context)
|
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):
|
def family_tasks(request):
|
||||||
"""家庭事项"""
|
"""家庭事项"""
|
||||||
|
|||||||
Reference in New Issue
Block a user