Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions comments/services/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def create_comment(
return obj


def update_comment(comment: Comment, text: str = None):
def update_comment(
comment: Comment, text: str = None, included_forecast: Forecast = None
):
differ = difflib.Differ()

diff = list(differ.compare(comment.text.splitlines(), text.splitlines()))
Expand All @@ -148,10 +150,19 @@ def update_comment(comment: Comment, text: str = None):
comment.text = text
comment.text_edited_at = timezone.now()

if included_forecast:
comment.included_forecast = included_forecast

should_soft_delete = check_and_handle_comment_spam(comment.author, comment)

comment.save(
update_fields=["text", "edit_history", "text_edited_at", "is_soft_deleted"]
update_fields=[
"text",
"edit_history",
"text_edited_at",
"is_soft_deleted",
"included_forecast",
]
)

if should_soft_delete:
Expand Down
16 changes: 15 additions & 1 deletion comments/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,25 @@ def comment_edit_api_view(request: Request, pk: int):
# Small validation
comment = get_object_or_404(Comment, pk=pk)
text = serializers.CharField().run_validation(request.data.get("text"))
include_forecast = serializers.BooleanField(
required=False, allow_null=True
).run_validation(request.data.get("include_forecast"))

if not (comment.author == request.user):
raise PermissionDenied("You do not have permission to edit this comment.")

update_comment(comment, text)
post = comment.on_post
forecast = None

if include_forecast and not comment.included_forecast and post and post.question_id:
forecast = (
post.question.user_forecasts.filter(author=comment.author)
.filter_active_at(comment.created_at)
.order_by("-start_time")
.first()
)

update_comment(comment, text, included_forecast=forecast)

return Response({}, status=status.HTTP_200_OK)

Expand Down
4 changes: 4 additions & 0 deletions front_end/messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1818,5 +1818,9 @@
"tournamentsTabArchived": "Archivováno",
"tournamentTimelineClosed": "Čekání na vyřešení",
"questionsPreviouslyPredicted": "{count, plural, =1 {# otázka} other {# otázek}} dříve předpovězených",
"includeMyForecastAtTheTime": "Zahrnout mou předpověď v daném čase",
"tournamentsInfoTitle": "Jsme <predmarket>nepredikční trh</predmarket>. Můžete se účastnit zdarma a vyhrát peněžní ceny za přesnost.",
"tournamentsInfoScoringLink": "Co jsou předpovídací skóre?",
"tournamentsInfoPrizesLink": "Jak jsou rozdělovány ceny?",
"othersCount": "Ostatní ({count})"
}
1 change: 1 addition & 0 deletions front_end/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@
"legacyPeerDisclaimer": "The Peer Accuracy leaderboards used slightly different math before 2024. See details <link>here</link>.",
"namesPrediction": "<name>{username}'s</name> Prediction",
"includeMyForecast": "include your current forecast in this comment",
"includeMyForecastAtTheTime": "Include my prediction at the time",
"privateComment": "private comment",
"groupVariable": "Group Variable",
"questionUnit": "Question Unit",
Expand Down
4 changes: 4 additions & 0 deletions front_end/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1818,5 +1818,9 @@
"tournamentsTabArchived": "Archivado",
"tournamentTimelineClosed": "Esperando resoluciones",
"questionsPreviouslyPredicted": "{count, plural, =1 {# pregunta} other {# preguntas}} previamente previstas",
"includeMyForecastAtTheTime": "Incluir mi predicción en ese momento",
"tournamentsInfoTitle": "Nosotros <predmarket>no somos un mercado de predicciones</predmarket>. Puedes participar gratis y ganar premios en efectivo por ser preciso.",
"tournamentsInfoScoringLink": "¿Qué son las puntuaciones de predicción?",
"tournamentsInfoPrizesLink": "¿Cómo se distribuyen los premios?",
"othersCount": "Otros ({count})"
}
4 changes: 4 additions & 0 deletions front_end/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,5 +1816,9 @@
"tournamentsTabArchived": "Arquivado",
"tournamentTimelineClosed": "Aguardando resoluções",
"questionsPreviouslyPredicted": "{count, plural, =1 {# pergunta} other {# perguntas}} previamente previstas",
"includeMyForecastAtTheTime": "Incluir minha previsão no momento",
"tournamentsInfoTitle": "Nós <predmarket>não somos um mercado de previsões</predmarket>. Você pode participar gratuitamente e ganhar prêmios em dinheiro por ser preciso.",
"tournamentsInfoScoringLink": "O que são pontuações de previsão?",
"tournamentsInfoPrizesLink": "Como os prêmios são distribuídos?",
"othersCount": "Outros ({count})"
}
4 changes: 4 additions & 0 deletions front_end/messages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -1815,5 +1815,9 @@
"tournamentsTabArchived": "已存檔",
"tournamentTimelineClosed": "等待裁定",
"questionsPreviouslyPredicted": "先前預測的{count, plural, =1 {# 個問題} other {# 個問題}}",
"includeMyForecastAtTheTime": "包括我當時的預測",
"tournamentsInfoTitle": "我們 <predmarket>不是預測市場</predmarket>。您可以免費參加並因精確的預測贏取現金獎勵。",
"tournamentsInfoScoringLink": "什麼是預測得分?",
"tournamentsInfoPrizesLink": "獎品如何分配?",
"withdrawAfterPercentSetting2": "問題總生命周期後撤回"
}
4 changes: 4 additions & 0 deletions front_end/messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1820,5 +1820,9 @@
"tournamentsTabArchived": "已归档",
"tournamentTimelineClosed": "等待解决",
"questionsPreviouslyPredicted": "之前预测的{count, plural, =1 {# 个问题} other {# 个问题}}",
"includeMyForecastAtTheTime": "包含我当时的预测",
"tournamentsInfoTitle": "我们<predmarket>不是一个预测市场</predmarket>。您可以免费参与,并因精准的预测赢得现金奖品。",
"tournamentsInfoScoringLink": "什么是预测分数?",
"tournamentsInfoPrizesLink": "奖品如何分配?",
"othersCount": "其他({count})"
}
Loading