Skip to content

Commit

Permalink
fix(global-notice): seperate korean, english versions of title and co…
Browse files Browse the repository at this point in the history
…ntent
  • Loading branch information
ddungiii committed Jan 2, 2024
1 parent 225aec9 commit 23bd73e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 31 deletions.
10 changes: 7 additions & 3 deletions apps/global_notice/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


@admin.register(GlobalNotice)
class FAQAdmin(MetaDataModelAdmin):
list_display = ("title", "content", "started_at", "expired_at")
search_fields = ("title", "content")
class GlobalNoticeAdmin(MetaDataModelAdmin):
list_display = ("ko_title", "en_title", "started_at", "expired_at")
fields = (
("ko_title", "ko_content"),
("en_title", "en_content"),
("started_at", "expired_at"),
)
9 changes: 6 additions & 3 deletions apps/global_notice/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-09 13:13
# Generated by Django 4.2.5 on 2024-01-02 14:41

import datetime

Expand Down Expand Up @@ -48,13 +48,16 @@ class Migration(migrations.Migration):
verbose_name="삭제 시간",
),
),
("title", models.CharField(max_length=256, verbose_name="제목")),
("content", models.TextField(verbose_name="본문")),
("ko_title", models.CharField(max_length=256, verbose_name="한글 제목")),
("en_title", models.CharField(max_length=256, verbose_name="영문 제목")),
("ko_content", models.TextField(verbose_name="한글 본문")),
("en_content", models.TextField(verbose_name="영문 본문")),
("started_at", models.DateTimeField(verbose_name="모달 노출 시작 시간")),
("expired_at", models.DateTimeField(verbose_name="모달 노출 종료 시간")),
],
options={
"verbose_name": "글로벌 공지",
"verbose_name_plural": "글로벌 공지 목록",
"ordering": ("-created_at",),
"abstract": False,
},
Expand Down
6 changes: 4 additions & 2 deletions apps/global_notice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Meta(MetaDataModel.Meta):
verbose_name = "글로벌 공지"
verbose_name_plural = "글로벌 공지 목록"

title = models.CharField(verbose_name="제목", max_length=256)
content = models.TextField(verbose_name="본문")
ko_title = models.CharField(verbose_name="한글 제목", max_length=256)
en_title = models.CharField(verbose_name="영문 제목", max_length=256)
ko_content = models.TextField(verbose_name="한글 본문")
en_content = models.TextField(verbose_name="영문 본문")
started_at = models.DateTimeField(verbose_name="모달 노출 시작 시간")
expired_at = models.DateTimeField(verbose_name="모달 노출 종료 시간")
9 changes: 8 additions & 1 deletion apps/global_notice/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
class GlobalNoticeSerializer(MetaDataModelSerializer):
class Meta:
model = GlobalNotice
fields = ["title", "content", "started_at", "expired_at"]
fields = [
"ko_title",
"en_title",
"ko_content",
"en_content",
"started_at",
"expired_at",
]
60 changes: 38 additions & 22 deletions tests/test_global_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def test_list(self):
"""
for i in range(self.N):
GlobalNotice.objects.create(
title=f"global_notice title {i}",
content=f"global_notice content {i}",
ko_title=f"글로벌 공지 제목 {i}",
en_title=f"global_notice title {i}",
ko_content=f"글로벌 공지 본문 {i}",
en_content=f"global_notice content {i}",
started_at=timezone.now() - timezone.timedelta(days=1),
expired_at=timezone.now() + timezone.timedelta(days=1),
)
Expand All @@ -32,30 +34,38 @@ def test_get(self):
비로그인도 허용
"""
global_notice = GlobalNotice.objects.create(
title=f"global_notice title",
content=f"global_notice content",
ko_title="글로벌 공지 제목",
en_title="global_notice title",
ko_content="글로벌 공지 본문",
en_content="global_notice content",
started_at=timezone.now() - timezone.timedelta(days=1),
expired_at=timezone.now() + timezone.timedelta(days=1),
)
res = self.http_request(self.user, "get", f"global_notices/{global_notice.id}")
assert res.data["title"] == global_notice.title
assert res.data["ko_title"] == global_notice.ko_title
assert res.data["en_title"] == global_notice.en_title

res = self.http_request(None, "get", f"global_notices/{global_notice.id}")
assert res.data["title"] == global_notice.title
assert res.data["ko_title"] == global_notice.ko_title
assert res.data["en_title"] == global_notice.en_title

def test_filter(self):
"""
expired, not started 필터링 테스트
"""
global_notice_expired = GlobalNotice.objects.create(
title="global_notice title",
content="global_notice content",
ko_title="글로벌 공지 제목",
en_title="global_notice title",
ko_content="글로벌 공지 본문",
en_content="global_notice content",
started_at=timezone.now() - timezone.timedelta(days=2),
expired_at=timezone.now() - timezone.timedelta(days=1),
)
global_notice_not_started = GlobalNotice.objects.create(
title="global_notice title",
content="global_notice content",
ko_title="글로벌 공지 제목",
en_title="global_notice title",
ko_content="글로벌 공지 본문",
en_content="global_notice content",
started_at=timezone.now() + timezone.timedelta(days=1),
expired_at=timezone.now() + timezone.timedelta(days=2),
)
Expand All @@ -72,8 +82,10 @@ def test_filter(self):

def test_create(self):
notice_data = {
"title": "global_notice title",
"content": "global_notice content",
"ko_title": "글로벌 공지 제목",
"en_title": "global_notice title",
"ko_content": "글로벌 공지 본문",
"en_content": "global_notice content",
"started_at": timezone.now() - timezone.timedelta(days=1),
"expired_at": timezone.now() + timezone.timedelta(days=1),
}
Expand All @@ -90,36 +102,40 @@ def test_create(self):

def test_update(self):
global_notice = GlobalNotice.objects.create(
title="global_notice title",
content="global_notice content",
ko_title="글로벌 공지 제목",
en_title="global_notice title",
ko_content="글로벌 공지 본문",
en_content="global_notice content",
started_at=timezone.now() - timezone.timedelta(days=1),
expired_at=timezone.now() + timezone.timedelta(days=1),
)
new_title = "new title"
new_content = "new content"
new_ko_title = "새로운 제목"
new_ko_content = "새로운 본문"

res_user = self.http_request(
self.user,
"patch",
f"global_notices/{global_notice.id}",
{"title": new_title, "content": new_content},
{"ko_title": new_ko_title, "ko_content": new_ko_content},
)
assert res_user.status_code == status.HTTP_403_FORBIDDEN

res_admin = self.http_request(
self.admin,
"patch",
f"global_notices/{global_notice.id}",
{"title": new_title, "content": new_content},
{"ko_title": new_ko_title, "ko_content": new_ko_content},
)
assert res_admin.status_code == status.HTTP_200_OK
assert res_admin.data["title"] == new_title
assert res_admin.data["content"] == new_content
assert res_admin.data["ko_title"] == new_ko_title
assert res_admin.data["ko_content"] == new_ko_content

def test_destroy(self):
global_notice = GlobalNotice.objects.create(
title="global_notice title",
content="global_notice content",
ko_title="글로벌 공지 제목",
en_title="global_notice title",
ko_content="글로벌 공지 본문",
en_content="global_notice content",
started_at=timezone.now() - timezone.timedelta(days=1),
expired_at=timezone.now() + timezone.timedelta(days=1),
)
Expand Down

0 comments on commit 23bd73e

Please sign in to comment.