Skip to content

Commit 035a0de

Browse files
authored
[25.07.31 / TASK-237] Modify - 주간 인사이트 어드민 뷰에 변경된 스키마 반영 (#38)
* modify: 주간 인사이트 어드민 뷰에 변경된 스키마 반영 * revert: empty_insight 복구
1 parent ed03ddc commit 035a0de

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

insight/admin/user_weekly_trend_admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UserWeeklyTrendAdmin(
2323
"created_at",
2424
)
2525
list_filter = ("is_processed", "week_start_date")
26-
search_fields = ("user__email", "insight")
26+
search_fields = ("user__username", "insight")
2727
readonly_fields = (
2828
"processed_at",
2929
"formatted_insight",
@@ -68,7 +68,7 @@ def user_info(self, obj: UserWeeklyTrend):
6868
return format_html(
6969
'<a href="{}" target="_blank">{}</a>',
7070
user_url,
71-
obj.user.email or f"사용자 {obj.user.id}",
71+
obj.user.username or f"사용자 {obj.user.id}",
7272
)
7373

7474
@admin.action(description="선택된 항목을 처리 완료로 표시하기")

insight/tests/test_json_preview_mixin_admin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,27 @@ def test_formatted_insight_user_weekly_trend(
4444
mixin = JsonPreviewMixin()
4545
result = mixin.formatted_insight(user_weekly_trend)
4646

47+
assert "사용자 주간 통계" in result
4748
assert "트렌드 분석" in result
4849
assert "핵심 키워드" in result
4950
for keyword in sample_trend_analysis.hot_keywords:
5051
assert keyword in result
5152
assert "작성 게시글 요약" in result
5253
assert "Django 모델 최적화하기" in result
5354

55+
def test_formatted_insight_user_weekly_trend_with_reminder(
56+
self, inactive_user_weekly_trend: UserWeeklyTrend
57+
):
58+
"""주간 글 미작성 UserWeeklyTrend의 formatted_insight 테스트"""
59+
mixin = JsonPreviewMixin()
60+
result = mixin.formatted_insight(inactive_user_weekly_trend)
61+
62+
assert "리마인더" in result
63+
assert "사용자 주간 통계" in result
64+
assert "트렌드 분석" not in result
65+
assert "핵심 키워드" not in result
66+
assert "작성 게시글 요약" not in result
67+
5468
def test_formatted_insight_empty(self, empty_insight_weekly_trend):
5569
"""빈 인사이트 데이터에 대한 formatted_insight 테스트"""
5670
mixin = JsonPreviewMixin()

insight/tests/test_user_weekly_trend_admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_user_info(self, user_weekly_trend_admin, user_weekly_trend):
2929
)
3030
result = user_weekly_trend_admin.user_info(user_weekly_trend)
3131

32-
assert user_weekly_trend.user.email in result
32+
assert user_weekly_trend.user.username in result
3333

3434
def test_week_range(
3535
self, user_weekly_trend_admin, user_weekly_trend: UserWeeklyTrend

templates/insights/insight_preview.html

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
<div class="module aligned">
2+
{% if user and insight.user_weekly_stats %}
3+
<h2 style="margin-top: 20px;">사용자 주간 통계</h2>
4+
<div style="margin-left: 15px;">
5+
<p><strong>전체 게시글 수:</strong> {{ insight.user_weekly_stats.posts }}</p>
6+
<p><strong>새 게시글 수:</strong> {{ insight.user_weekly_stats.new_posts }}</p>
7+
<p><strong>조회수 증가:</strong> {{ insight.user_weekly_stats.views }}</p>
8+
<p><strong>좋아요 증가:</strong> {{ insight.user_weekly_stats.likes }}</p>
9+
</div>
10+
{% endif %}
11+
212
{% if insight.trend_analysis %}
313
<h2 style="margin-top: 10px;">트렌드 분석</h2>
414
<div style="margin-left: 15px;">
@@ -28,16 +38,27 @@ <h3>인사이트</h3>
2838

2939
{% if insight.trending_summary %}
3040
<h2 style="margin-top: 20px;">{% if user %}작성 게시글 요약{% else %}트렌딩 요약{% endif %}</h2>
31-
{% for summary in insight.trending_summary %}
41+
{% for item in insight.trending_summary %}
3242
<div style="margin: 15px 0; padding-left: 15px; border-left: 3px solid #ddd;">
33-
<h3 style="margin-bottom: 5px;">{{ forloop.counter }}. {{ summary.title }}</h3>
34-
<p style="line-height: 1.5; margin-bottom: 8px;">{{ summary.summary }}</p>
35-
{% if summary.key_points %}
36-
<p><strong>핵심 포인트:</strong> {{ summary.key_points|join:", " }}</p>
43+
<h3 style="margin-bottom: 5px;">{{ forloop.counter }}. {{ item.title }}</h3>
44+
<p style="line-height: 1.5; margin-bottom: 8px;">{{ item.summary }}</p>
45+
{% if item.key_points %}
46+
<p><strong>핵심 키워드:</strong> {{ item.key_points|join:", " }}</p>
3747
{% endif %}
48+
<p><strong>작성자:</strong> {{ item.username }}</p>
49+
<p><strong>URL:</strong> <a href="https://velog.io/@{{item.username}}/{{item.slug}}" target="_blank">https://velog.io/@{{item.username}}/{{item.slug}}</a></p>
50+
{% if item.thumbnail %}
51+
<p><strong>썸네일:</strong> <img src="{{item.thumbnail}}" alt="썸네일" style="width: 150px;"></p>
52+
{% endif %}
3853
</div>
3954
{% endfor %}
40-
{% else %}
41-
<p>요약 데이터 없음</p>
55+
{% endif %}
56+
57+
{% if user and insight.user_weekly_reminder %}
58+
<h2 style="margin-top: 20px;">리마인더</h2>
59+
<div style="margin-left: 15px;">
60+
<p><strong>마지막 작성 글:</strong> {{ insight.user_weekly_reminder.title }}</p>
61+
<p><strong>마지막 작성일:</strong> {{ insight.user_weekly_reminder.days_ago }}일 전</p>
62+
</div>
4263
{% endif %}
4364
</div>

0 commit comments

Comments
 (0)