Skip to content

Commit

Permalink
style(quiz): reformat the code
Browse files Browse the repository at this point in the history
  • Loading branch information
CapooL committed Jan 26, 2024
1 parent bf8fb66 commit 4cc01df
Show file tree
Hide file tree
Showing 24 changed files with 185 additions and 64 deletions.
9 changes: 7 additions & 2 deletions hinghwa-dict-backend/HinghwaDict/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import logging
import os

Expand Down Expand Up @@ -188,8 +189,12 @@
"token",
)
# parameter of Tencent cos
COS_SECRET_ID = env.str("COS_SECRET_ID", "DEFAULT_COS_SECRET_ID") # 替换为用户的 secretId
COS_SECRET_KEY = env.str("COS_SECRET_KEY", "DEFAULT_COS_SECRET_KEY") # 替换为用户的 secretKey
COS_SECRET_ID = env.str(
"COS_SECRET_ID", "DEFAULT_COS_SECRET_ID"
) # 替换为用户的 secretId
COS_SECRET_KEY = env.str(
"COS_SECRET_KEY", "DEFAULT_COS_SECRET_KEY"
) # 替换为用户的 secretKey
COS_BUCKET = env.str("COS_BUCKET", "DEFAULT_COS_BUCKET") # BucketName-APPID
COS_REGION = env.str("COS_REGION", "DEFAULT_COS_REGION")

Expand Down
1 change: 1 addition & 0 deletions hinghwa-dict-backend/HinghwaDict/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include

Expand Down
14 changes: 11 additions & 3 deletions hinghwa-dict-backend/article/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class Migration(migrations.Migration):
),
(
"views",
models.IntegerField(default=0, editable=False, verbose_name="阅读量"),
models.IntegerField(
default=0, editable=False, verbose_name="阅读量"
),
),
(
"publish_time",
Expand All @@ -39,7 +41,10 @@ class Migration(migrations.Migration):
),
("content", models.TextField(verbose_name="正文")),
("cover", models.URLField(verbose_name="图片地址")),
("visibility", models.BooleanField(default=False, verbose_name="是否审核")),
(
"visibility",
models.BooleanField(default=False, verbose_name="是否审核"),
),
(
"author",
models.ForeignKey(
Expand Down Expand Up @@ -78,7 +83,10 @@ class Migration(migrations.Migration):
),
),
("content", models.TextField(max_length=500, verbose_name="内容")),
("time", models.DateTimeField(auto_now_add=True, verbose_name="评论时间")),
(
"time",
models.DateTimeField(auto_now_add=True, verbose_name="评论时间"),
),
(
"article",
models.ForeignKey(
Expand Down
5 changes: 4 additions & 1 deletion hinghwa-dict-backend/article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class Comment(models.Model):
verbose_name="父评论",
)
article = models.ForeignKey(
Article, on_delete=models.CASCADE, related_name="comments", verbose_name="评论文章"
Article,
on_delete=models.CASCADE,
related_name="comments",
verbose_name="评论文章",
)
like_users = models.ManyToManyField(
User,
Expand Down
12 changes: 10 additions & 2 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def post(self, request) -> JsonResponse:
article.save()
content = f"我创建了文章(id={article.id}),请及时去审核"
sendNotification(
article.author, None, content, title="【提醒】文章待审核", action_object=article
article.author,
None,
content,
title="【提醒】文章待审核",
action_object=article,
)
return JsonResponse({"id": article.id}, status=200)

Expand Down Expand Up @@ -165,7 +169,11 @@ def put(self, request, id) -> JsonResponse:
article.save()
content = f"我修改了文章(id={article.id}),请及时去审核"
sendNotification(
article.author, None, content, title="【提醒】文章待审核", action_object=article
article.author,
None,
content,
title="【提醒】文章待审核",
action_object=article,
)
return JsonResponse({}, status=200)

Expand Down
5 changes: 4 additions & 1 deletion hinghwa-dict-backend/music/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class Migration(migrations.Migration):
("title", models.CharField(max_length=100, verbose_name="曲名")),
("artist", models.CharField(max_length=100, verbose_name="作者")),
("cover", models.URLField(verbose_name="音乐封面地址")),
("visibility", models.BooleanField(default=False, verbose_name="是否可见")),
(
"visibility",
models.BooleanField(default=False, verbose_name="是否可见"),
),
(
"contributor",
models.ForeignKey(
Expand Down
5 changes: 4 additions & 1 deletion hinghwa-dict-backend/quiz/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Migration(migrations.Migration):
),
("answer", models.IntegerField(default=0, verbose_name="答案序号")),
("explanation", models.TextField(verbose_name="答案解析")),
("visibility", models.BooleanField(default=False, verbose_name="是否审核")),
(
"visibility",
models.BooleanField(default=False, verbose_name="是否审核"),
),
],
options={
"verbose_name": "测试题",
Expand Down
4 changes: 3 additions & 1 deletion hinghwa-dict-backend/quiz/migrations/0004_quiz_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Migration(migrations.Migration):
fields=[
(
"title",
models.CharField(blank=True, max_length=50, verbose_name="试卷标题"),
models.CharField(
blank=True, max_length=50, verbose_name="试卷标题"
),
),
(
"id",
Expand Down
4 changes: 3 additions & 1 deletion hinghwa-dict-backend/quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class Quiz(models.Model):
answer = models.IntegerField(default=0, verbose_name="答案序号", editable=True)
explanation = models.TextField(verbose_name="答案解析")
visibility = models.BooleanField(default=False, verbose_name="是否审核")
voice_source = models.URLField(max_length=200, verbose_name="播报语音链接", default="")
voice_source = models.URLField(
max_length=200, verbose_name="播报语音链接", default=""
)
type = models.CharField(blank=True, max_length=50, verbose_name="问题类型")

def __str__(self):
Expand Down
4 changes: 3 additions & 1 deletion hinghwa-dict-backend/rewards/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Migration(migrations.Migration):
),
(
"details",
models.TextField(blank=True, max_length=200, verbose_name="商品详情"),
models.TextField(
blank=True, max_length=200, verbose_name="商品详情"
),
),
(
"id",
Expand Down
8 changes: 5 additions & 3 deletions hinghwa-dict-backend/user/dto/user_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def user_all(user: User) -> dict:

response.update(
{
"login_time": localtime(user.last_login).__format__("%Y-%m-%d %H:%M:%S")
if user.last_login
else "",
"login_time": (
localtime(user.last_login).__format__("%Y-%m-%d %H:%M:%S")
if user.last_login
else ""
),
}
)
return response
12 changes: 9 additions & 3 deletions hinghwa-dict-backend/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ class Migration(migrations.Migration):
),
(
"wechat",
models.CharField(blank=True, max_length=128, verbose_name="微信标识码"),
models.CharField(
blank=True, max_length=128, verbose_name="微信标识码"
),
),
(
"qq",
models.CharField(blank=True, max_length=128, verbose_name="qq标识码"),
models.CharField(
blank=True, max_length=128, verbose_name="qq标识码"
),
),
(
"nickname",
models.CharField(blank=True, max_length=100, verbose_name="昵称"),
),
(
"birthday",
models.DateField(blank=True, default="1970-1-1", verbose_name="生日"),
models.DateField(
blank=True, default="1970-1-1", verbose_name="生日"
),
),
(
"telephone",
Expand Down
3 changes: 2 additions & 1 deletion hinghwa-dict-backend/utils/exception/types/bad_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ReturnUsersNumException(BadRequestException):
"""

def __init__(
self, msg="请在return_users_num字段中加入请求的点赞人数,要求为正整数,或者不发送return_users_num字段"
self,
msg="请在return_users_num字段中加入请求的点赞人数,要求为正整数,或者不发送return_users_num字段",
):
super().__init__(msg)
25 changes: 20 additions & 5 deletions hinghwa-dict-backend/website/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ class Migration(migrations.Migration):
),
),
("english", models.CharField(max_length=255, verbose_name="英文表达")),
("mandarin", models.CharField(max_length=255, verbose_name="普通话表达")),
("character", models.CharField(max_length=255, verbose_name="方言表达")),
(
"mandarin",
models.CharField(max_length=255, verbose_name="普通话表达"),
),
(
"character",
models.CharField(max_length=255, verbose_name="方言表达"),
),
("pinyin", models.CharField(max_length=255, verbose_name="方言拼音")),
],
options={
Expand All @@ -41,9 +47,18 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("announcements", models.TextField(default="[]", verbose_name="本站公告")),
("hot_articles", models.TextField(default="[]", verbose_name="热门文章")),
("word_of_the_day", models.TextField(default="1", verbose_name="每日一词")),
(
"announcements",
models.TextField(default="[]", verbose_name="本站公告"),
),
(
"hot_articles",
models.TextField(default="[]", verbose_name="热门文章"),
),
(
"word_of_the_day",
models.TextField(default="1", verbose_name="每日一词"),
),
("carousel", models.TextField(default="[]", verbose_name="精品推荐")),
],
options={
Expand Down
12 changes: 9 additions & 3 deletions hinghwa-dict-backend/website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@


class Website(models.Model):
announcements = models.TextField(verbose_name="本站公告", default="[]") # list[文章id]
hot_articles = models.TextField(verbose_name="热门文章", default="[]") # list[文章id]
announcements = models.TextField(
verbose_name="本站公告", default="[]"
) # list[文章id]
hot_articles = models.TextField(
verbose_name="热门文章", default="[]"
) # list[文章id]
word_of_the_day = models.TextField(verbose_name="每日一词", default="1") # int
carousel = models.TextField(verbose_name="精品推荐", default="[]") # dict{id,source}
carousel = models.TextField(
verbose_name="精品推荐", default="[]"
) # dict{id,source}

class Meta:
verbose_name_plural = "网页内容"
Expand Down
4 changes: 3 additions & 1 deletion hinghwa-dict-backend/word/application/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def put(self, request, id) -> JsonResponse:
"""
WD0404 修改申请
"""
user = token_user(token_pass(request.headers, -1)) # user = 操作用户(仅限管理员)
user = token_user(
token_pass(request.headers, -1)
) # user = 操作用户(仅限管理员)
application = find_application(id)
application.verifier = user
feedback = None
Expand Down
34 changes: 26 additions & 8 deletions hinghwa-dict-backend/word/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,30 @@ class Migration(migrations.Migration):
("annotation", models.TextField(blank=True, verbose_name="附注")),
(
"mandarin",
models.TextField(blank=True, default="[]", verbose_name="对应普通话词语"),
models.TextField(
blank=True, default="[]", verbose_name="对应普通话词语"
),
),
(
"standard_ipa",
models.CharField(blank=True, max_length=30, verbose_name="标准IPA"),
),
(
"standard_pinyin",
models.CharField(blank=True, max_length=30, verbose_name="标准拼音"),
models.CharField(
blank=True, max_length=30, verbose_name="标准拼音"
),
),
(
"views",
models.IntegerField(default=0, editable=False, verbose_name="访问量"),
models.IntegerField(
default=0, editable=False, verbose_name="访问量"
),
),
(
"visibility",
models.BooleanField(default=False, verbose_name="是否审核"),
),
("visibility", models.BooleanField(default=False, verbose_name="是否审核")),
(
"contributor",
models.ForeignKey(
Expand Down Expand Up @@ -127,10 +136,15 @@ class Migration(migrations.Migration):
("pinyin", models.CharField(max_length=50, verbose_name="拼音")),
("county", models.CharField(max_length=100, verbose_name="县区")),
("town", models.CharField(max_length=100, verbose_name="乡镇")),
("visibility", models.BooleanField(default=False, verbose_name="是否可见")),
(
"visibility",
models.BooleanField(default=False, verbose_name="是否可见"),
),
(
"views",
models.IntegerField(default=0, editable=False, verbose_name="访问量"),
models.IntegerField(
default=0, editable=False, verbose_name="访问量"
),
),
(
"contributor",
Expand Down Expand Up @@ -192,15 +206,19 @@ class Migration(migrations.Migration):
("annotation", models.TextField(blank=True, verbose_name="附注")),
(
"mandarin",
models.TextField(blank=True, default="[]", verbose_name="对应普通话词语"),
models.TextField(
blank=True, default="[]", verbose_name="对应普通话词语"
),
),
(
"standard_ipa",
models.CharField(blank=True, max_length=30, verbose_name="标准IPA"),
),
(
"standard_pinyin",
models.CharField(blank=True, max_length=30, verbose_name="标准拼音"),
models.CharField(
blank=True, max_length=30, verbose_name="标准拼音"
),
),
(
"contributor",
Expand Down
14 changes: 11 additions & 3 deletions hinghwa-dict-backend/word/migrations/0004_word_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("createTime", models.DateTimeField(blank=True, verbose_name="创建时间")),
("updateTime", models.DateTimeField(blank=True, verbose_name="更新时间")),
(
"createTime",
models.DateTimeField(blank=True, verbose_name="创建时间"),
),
(
"updateTime",
models.DateTimeField(blank=True, verbose_name="更新时间"),
),
(
"description",
models.CharField(blank=True, max_length=100, verbose_name="词单简介"),
models.CharField(
blank=True, max_length=100, verbose_name="词单简介"
),
),
(
"author",
Expand Down
Loading

0 comments on commit 4cc01df

Please sign in to comment.