From 5978a0eb1e975a07565b92fefd6493297834b71b Mon Sep 17 00:00:00 2001 From: taoky Date: Fri, 25 Oct 2024 14:45:20 +0800 Subject: [PATCH] Allow setting feedback content without code change --- frontend/admin.py | 4 +-- frontend/migrations/0011_feedback.py | 33 ++++++++++++++++++++++ frontend/models.py | 8 ++++++ frontend/templates/challenge_feedback.html | 13 ++------- frontend/views.py | 32 +++++++++------------ 5 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 frontend/migrations/0011_feedback.py diff --git a/frontend/admin.py b/frontend/admin.py index ba6692c..8cb1e60 100644 --- a/frontend/admin.py +++ b/frontend/admin.py @@ -9,9 +9,9 @@ from server.terms.models import Terms from server.trigger.models import Trigger from server.user.models import User -from .models import Page, Account, Code, AccountLog, SpecialProfileUsedRecord, Qa, Credits, UnidirectionalFeedback +from .models import Page, Account, Code, AccountLog, SpecialProfileUsedRecord, Qa, Credits, UnidirectionalFeedback, Feedback -admin.site.register([Page, Account, Code, Qa, Credits, SpecialProfileUsedRecord, UnidirectionalFeedback]) +admin.site.register([Page, Account, Code, Qa, Credits, SpecialProfileUsedRecord, UnidirectionalFeedback, Feedback]) class PermissionListFilter(admin.SimpleListFilter): diff --git a/frontend/migrations/0011_feedback.py b/frontend/migrations/0011_feedback.py new file mode 100644 index 0000000..4181acf --- /dev/null +++ b/frontend/migrations/0011_feedback.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.16 on 2024-10-25 06:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("frontend", "0010_unidirectionalfeedback"), + ] + + operations = [ + migrations.CreateModel( + name="Feedback", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "content", + models.TextField( + blank=True, help_text="会被放入 div 的 HTML" + ), + ), + ], + ), + ] diff --git a/frontend/models.py b/frontend/models.py index 60f0735..17b6047 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -119,6 +119,14 @@ def get(cls): return cls.objects.get_or_create()[0] +class Feedback(models.Model): + content = models.TextField(blank=True, help_text='会被放入 div 的 HTML') + + @classmethod + def get(cls): + return cls.objects.get_or_create()[0] + + class UnidirectionalFeedback(models.Model): """ User could submit feedback for a specific challenge. diff --git a/frontend/templates/challenge_feedback.html b/frontend/templates/challenge_feedback.html index db8b6cd..0c567b4 100644 --- a/frontend/templates/challenge_feedback.html +++ b/frontend/templates/challenge_feedback.html @@ -12,16 +12,11 @@ {% endblock %} {% block content %} -{% verbatim %} +

提交对题目 {{challenge_name}} 的反馈

-

提示:

- +
{{ feedback.content|safe }}
+{% verbatim %}
{% endverbatim %}
@@ -40,14 +35,12 @@

提交对题目 {{challenge_name}} 的反馈

{% endverbatim %} -{{ challenge_name|json_script:'challenge-name' }} {{ too_frequent|json_script:'too-frequent' }} {{ latest_submit|json_script:'latest-submit' }}