Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(list): remove authorization from APIs and add admin pages #327

Merged
merged 3 commits into from
Sep 16, 2023
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
24 changes: 23 additions & 1 deletion hinghwa-dict-backend/word/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
1 change: 0 additions & 1 deletion hinghwa-dict-backend/word/lists/view/manage_all_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion hinghwa-dict-backend/word/lists/view/manage_single_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions hinghwa-dict-backend/word/migrations/0005_ListAdmin.py
Original file line number Diff line number Diff line change
@@ -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": "词单"},
),
]
6 changes: 5 additions & 1 deletion hinghwa-dict-backend/word/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="词单作者"
)
Expand All @@ -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 = "词单"