Skip to content
Merged
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
27 changes: 25 additions & 2 deletions comments/views/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import transaction
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.utils import timezone
from rest_framework import serializers, status
from rest_framework.decorators import api_view, permission_classes
from rest_framework.exceptions import PermissionDenied, ValidationError
Expand Down Expand Up @@ -166,13 +167,35 @@ 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

return Response({}, status=status.HTTP_200_OK)
if include_forecast and not comment.included_forecast and post and post.question_id:
active_time = comment.created_at
question = post.question

# If question was closed, take the forecast active on the date of closure
if question.actual_close_time and question.actual_close_time <= timezone.now():
active_time = question.actual_close_time

forecast = (
question.user_forecasts.filter(author=comment.author)
.filter_active_at(active_time)
.order_by("-start_time")
.first()
)

update_comment(comment, text, included_forecast=forecast)
comment.refresh_from_db()

return Response(serialize_comment(comment), status=status.HTTP_200_OK)


@api_view(["POST"])
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 @@ -1819,5 +1819,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 <strong>({forecast})</strong>",
"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 <strong>({forecast})</strong>",
"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 @@ -1819,5 +1819,9 @@
"tournamentsTabArchived": "Archivado",
"tournamentTimelineClosed": "Esperando resoluciones",
"questionsPreviouslyPredicted": "{count, plural, =1 {# pregunta} other {# preguntas}} previamente previstas",
"includeMyForecastAtTheTime": "Incluir mi predicción en ese momento <strong>({forecast})</strong>",
"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 @@ -1817,5 +1817,9 @@
"tournamentsTabArchived": "Arquivado",
"tournamentTimelineClosed": "Aguardando resoluções",
"questionsPreviouslyPredicted": "{count, plural, =1 {# pergunta} other {# perguntas}} previamente previstas",
"includeMyForecastAtTheTime": "Incluir minha previsão no momento <strong>({forecast})</strong>",
"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 @@ -1816,5 +1816,9 @@
"tournamentsTabArchived": "已存檔",
"tournamentTimelineClosed": "等待裁定",
"questionsPreviouslyPredicted": "先前預測的{count, plural, =1 {# 個問題} other {# 個問題}}",
"includeMyForecastAtTheTime": "包括我當時的預測 <strong>({forecast})</strong>",
"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 @@ -1821,5 +1821,9 @@
"tournamentsTabArchived": "已归档",
"tournamentTimelineClosed": "等待解决",
"questionsPreviouslyPredicted": "之前预测的{count, plural, =1 {# 个问题} other {# 个问题}}",
"includeMyForecastAtTheTime": "包含我当时的预测 <strong>({forecast})</strong>",
"tournamentsInfoTitle": "我们<predmarket>不是一个预测市场</predmarket>。您可以免费参与,并因精准的预测赢得现金奖品。",
"tournamentsInfoScoringLink": "什么是预测分数?",
"tournamentsInfoPrizesLink": "奖品如何分配?",
"othersCount": "其他({count})"
}
Loading