Skip to content

Commit

Permalink
Merge pull request #457 from sparcs-kaist/master
Browse files Browse the repository at this point in the history
Apply notification anonymous name hotfix to develop branch
  • Loading branch information
injoonH committed Mar 12, 2024
2 parents 14bdb10 + 9e8f6dd commit 744c4b8
Show file tree
Hide file tree
Showing 28 changed files with 495 additions and 135 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,5 @@ config.cnf
# End of https://www.gitignore.io/api/visualstudiocode

docker-compose.yml

___*
10 changes: 4 additions & 6 deletions apps/core/management/scripts/portal_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ def _save_portal_image(html, session):
soup = bs(html, "lxml")
for child in soup.find_all("img", {}):
old_url = child.attrs.get("src")
try:
new_url = _get_new_url_and_save_to_s3(old_url, session)
child["src"] = new_url
except Exception as exc:
log.info(child)
raise exec
if old_url is None:
continue
new_url = _get_new_url_and_save_to_s3(old_url, session)
child["src"] = new_url

return str(soup)

Expand Down
2 changes: 1 addition & 1 deletion apps/core/management/scripts/reminder_email_for_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

if env("DJANGO_ENV") == "production":
django_env = ""
BASE_URL = "https://newara.sparcs.org/post"
BASE_URL = "https://newara-api.sparcs.org/post"
else:
django_env = "[DEV]"
BASE_URL = "https://newara.dev.sparcs.org/post"
Expand Down
33 changes: 0 additions & 33 deletions apps/core/migrations/0044_portalviewcount.py

This file was deleted.

22 changes: 0 additions & 22 deletions apps/core/migrations/0045_article_add_latest_portal_view_count.py

This file was deleted.

29 changes: 0 additions & 29 deletions apps/core/migrations/0046_alter_portal_crawl_related_field.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Generated by Django 4.2.9 on 2024-03-06 07:05

import datetime

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0057_alter_article_name_type_and_more"),
]

operations = [
migrations.AddField(
model_name="article",
name="latest_portal_view_count",
field=models.PositiveIntegerField(
blank=True, default=None, null=True, verbose_name="포탈 조회수"
),
),
migrations.AlterField(
model_name="article",
name="url",
field=models.URLField(
blank=True,
db_index=True,
default=None,
max_length=256,
null=True,
verbose_name="포탈 링크",
),
),
migrations.CreateModel(
name="PortalViewCount",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created_at",
models.DateTimeField(
db_index=True,
default=django.utils.timezone.now,
verbose_name="생성 시간",
),
),
(
"updated_at",
models.DateTimeField(
auto_now=True, db_index=True, verbose_name="수정 시간"
),
),
(
"deleted_at",
models.DateTimeField(
db_index=True,
default=datetime.datetime(
1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc
),
verbose_name="삭제 시간",
),
),
(
"view_count",
models.PositiveIntegerField(default=0, verbose_name="조회수"),
),
(
"article",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="게시물",
to="core.article",
),
),
],
options={
"ordering": ("-created_at",),
"abstract": False,
},
),
]
12 changes: 0 additions & 12 deletions apps/core/migrations/0058_merge_20240109_2331.py

This file was deleted.

10 changes: 5 additions & 5 deletions apps/core/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ class Article(MetaDataModel):
)

url = models.URLField(
null=True,
blank=True,
default=None,
verbose_name="포탈 링크",
max_length=256,
blank=True,
null=True,
db_index=True,
default=None,
)

latest_portal_view_count = models.PositiveIntegerField(
null=True,
verbose_name="포탈 조회수",
blank=True,
null=True,
default=None,
verbose_name="포탈조회수",
)

content_updated_at = models.DateTimeField(
Expand Down
54 changes: 38 additions & 16 deletions apps/core/models/notification.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django.db import models
from django.utils.functional import cached_property

from apps.core.models import Article, Comment
from apps.core.models.board import NameType
from ara.db.models import MetaDataModel
from ara.firebase import fcm_notify_comment

if TYPE_CHECKING:
from apps.user.models import UserProfile

TYPE_CHOICES = (
("default", "default"),
("article_commented", "article_commented"),
Expand All @@ -12,41 +21,41 @@


class Notification(MetaDataModel):
class Meta(MetaDataModel.Meta):
verbose_name = "알림"
verbose_name_plural = "알림 목록"

type = models.CharField(
verbose_name="알림 종류",
choices=TYPE_CHOICES,
default="default",
max_length=32,
verbose_name="알림 종류",
)
title = models.CharField(
max_length=256,
verbose_name="제목",
max_length=256,
)
content = models.TextField(
verbose_name="내용",
)

related_article = models.ForeignKey(
on_delete=models.CASCADE,
verbose_name="알림 관련 제보",
to="core.Article",
on_delete=models.CASCADE,
related_name="notification_set",
null=True,
db_index=True,
related_name="notification_set",
verbose_name="알림 관련 제보",
)
related_comment = models.ForeignKey(
on_delete=models.CASCADE,
verbose_name="알림 관련 댓글",
to="core.Comment",
on_delete=models.CASCADE,
related_name="notification_set",
null=True,
db_index=True,
related_name="notification_set",
verbose_name="알림 관련 댓글",
)

class Meta(MetaDataModel.Meta):
verbose_name = "알림"
verbose_name_plural = "알림 목록"

@cached_property
def data(self) -> dict:
return {
Expand All @@ -56,12 +65,23 @@ def data(self) -> dict:
"click_action": "",
}

@staticmethod
def get_display_name(article: Article, profile: UserProfile):
if article.name_type == NameType.REALNAME:
return profile.realname
elif article.name_type == NameType.REGULAR:
return profile.nickname
else:
return "익명"

@classmethod
def notify_commented(cls, comment):
from apps.core.models import NotificationReadLog

def notify_article_commented(_parent_article, _comment):
title = f"{_comment.created_by.profile.nickname} 님이 새로운 댓글을 작성했습니다."
def notify_article_commented(_parent_article: Article, _comment: Comment):
name = cls.get_display_name(_parent_article, _comment.created_by.profile)
title = f"{name} 님이 새로운 댓글을 작성했습니다."

NotificationReadLog.objects.create(
read_by=_parent_article.created_by,
notification=cls.objects.create(
Expand All @@ -79,8 +99,10 @@ def notify_article_commented(_parent_article, _comment):
f"post/{_parent_article.id}",
)

def notify_comment_commented(_parent_article, _comment):
title = f"{_comment.created_by.profile.nickname} 님이 새로운 대댓글을 작성했습니다."
def notify_comment_commented(_parent_article: Article, _comment: Comment):
name = cls.get_display_name(_parent_article, _comment.created_by.profile)
title = f"{name} 님이 새로운 대댓글을 작성했습니다."

NotificationReadLog.objects.create(
read_by=_comment.parent_comment.created_by,
notification=cls.objects.create(
Expand Down
15 changes: 5 additions & 10 deletions apps/core/models/portal_view_count.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
from django.db import models

from ara.db.models import MetaDataModel
from django.utils import timezone


class PortalViewCount(MetaDataModel):
article = models.ForeignKey(
on_delete=models.CASCADE,
to="core.Article",
null=False,
on_delete=models.CASCADE,
related_name="게시물",
null=False,
)

view_count = models.IntegerField(
view_count = models.PositiveIntegerField(
verbose_name="조회수",
default=0,
verbose_name="조회수 값",
)

created_at = models.DateTimeField(
default=timezone.now,
verbose_name="생성 시간",
)
2 changes: 1 addition & 1 deletion apps/core/views/viewsets/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_queryset(self):
def send_email_for_article_report(request):
django_env = "PROD" if env("DJANGO_ENV") == "production" else "DEV"
article_link = (
"newara.sparcs.org"
"newara-api.sparcs.org"
if env("DJANGO_ENV") == "production"
else "newara.dev.sparcs.org"
)
Expand Down
Loading

0 comments on commit 744c4b8

Please sign in to comment.