From 7b5d47049284e36cef38f58fbc41a0330e08fee6 Mon Sep 17 00:00:00 2001 From: CapooL <111524029+CapooL@users.noreply.github.com> Date: Sat, 16 Sep 2023 17:39:04 +0800 Subject: [PATCH] fix(list): remove authorization from APIs and add admin pages (#327) * feat(words): create ListAdmin * feat(list): delete token_pass from WD0604 and WD0605 * style(word): reformat for black --- hinghwa-dict-backend/word/admin.py | 24 ++++++++++++++++++- .../word/lists/view/manage_all_list.py | 1 - .../word/lists/view/manage_single_list.py | 1 - .../word/migrations/0005_ListAdmin.py | 16 +++++++++++++ hinghwa-dict-backend/word/models.py | 6 ++++- 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 hinghwa-dict-backend/word/migrations/0005_ListAdmin.py diff --git a/hinghwa-dict-backend/word/admin.py b/hinghwa-dict-backend/word/admin.py index 55b9e516..fc7b780c 100644 --- a/hinghwa-dict-backend/word/admin.py +++ b/hinghwa-dict-backend/word/admin.py @@ -2,7 +2,7 @@ from django.contrib import messages from django.utils.translation import ngettext -from .models import Word, Character, Pronunciation, Application +from .models import Word, Character, Pronunciation, Application, List from website.views import sendNotification @@ -183,7 +183,29 @@ class ApplicationAdmin(admin.ModelAdmin): raw_id_fields = ("contributor", "verifier", "word") +class ListsAdmin(admin.ModelAdmin): + list_display = [ + "id", + "name", + "createTime", + "updateTime", + "description", + "author", + "include_words", + ] + list_filter = ["name", "author"] + search_fields = ["words_word", "name", "description", "author" "id"] + ordering = ["-id"] + list_per_page = 50 + # filter_horizontal = ["words_included_word"] + raw_id_fields = ["words"] + + def include_words(self, obj): + return [bt.word for bt in obj.words.all()] + + admin.site.register(Word, WordAdmin) admin.site.register(Character, CharacterAdmin) admin.site.register(Pronunciation, PronunciationAdmin) admin.site.register(Application, ApplicationAdmin) +admin.site.register(List, ListsAdmin) diff --git a/hinghwa-dict-backend/word/lists/view/manage_all_list.py b/hinghwa-dict-backend/word/lists/view/manage_all_list.py index 5ba0ed2d..2c59f778 100644 --- a/hinghwa-dict-backend/word/lists/view/manage_all_list.py +++ b/hinghwa-dict-backend/word/lists/view/manage_all_list.py @@ -35,7 +35,6 @@ def post(self, request): # WD0605查找词单(多) def get(self, request): - token_pass(request.headers, 0) total_list = List.objects.all() result = [] for list in total_list: diff --git a/hinghwa-dict-backend/word/lists/view/manage_single_list.py b/hinghwa-dict-backend/word/lists/view/manage_single_list.py index 1945e311..43411b4b 100644 --- a/hinghwa-dict-backend/word/lists/view/manage_single_list.py +++ b/hinghwa-dict-backend/word/lists/view/manage_single_list.py @@ -46,7 +46,6 @@ def put(self, request, list_id): # WD0604查看词单(单) def get(self, request, list_id): - token_pass(request.headers, 0) list = List.objects.filter(id=list_id) if not list.exists(): raise ListsNotFoundException() diff --git a/hinghwa-dict-backend/word/migrations/0005_ListAdmin.py b/hinghwa-dict-backend/word/migrations/0005_ListAdmin.py new file mode 100644 index 00000000..7466a2d9 --- /dev/null +++ b/hinghwa-dict-backend/word/migrations/0005_ListAdmin.py @@ -0,0 +1,16 @@ +# Generated by Django 3.1.14 on 2023-09-16 08:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("word", "0004_word_list"), + ] + + operations = [ + migrations.AlterModelOptions( + name="list", + options={"verbose_name": "词单", "verbose_name_plural": "词单"}, + ), + ] diff --git a/hinghwa-dict-backend/word/models.py b/hinghwa-dict-backend/word/models.py index 51ce2882..9251d72e 100644 --- a/hinghwa-dict-backend/word/models.py +++ b/hinghwa-dict-backend/word/models.py @@ -209,7 +209,7 @@ class Meta: class List(models.Model): - name = models.CharField(blank=True, max_length=30, verbose_name="类型") + name = models.CharField(blank=True, max_length=30, verbose_name="词单名称") author = models.ForeignKey( User, on_delete=models.CASCADE, related_name="list_words", verbose_name="词单作者" ) @@ -223,3 +223,7 @@ class List(models.Model): createTime = models.DateTimeField(blank=True, verbose_name="创建时间") updateTime = models.DateTimeField(blank=True, verbose_name="更新时间") description = models.CharField(blank=True, max_length=100, verbose_name="词单简介") + + class Meta: + verbose_name_plural = "词单" + verbose_name = "词单"