Skip to content

Commit

Permalink
feat(character): add "type" to Character
Browse files Browse the repository at this point in the history
  • Loading branch information
CapooL committed Mar 7, 2024
1 parent 1f32583 commit 840e575
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/character/dto/character_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def character_all(character: Character, word: Word, source: Pronunciation) -> di
"traditional": character.traditional,
"word": word,
"source": source,
"type": None if character.type is None else character.type,
}
return response
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def character_normal(character: Character) -> dict:
"county": character.county,
"town": character.town,
"traditional": character.traditional,
"type": None if character.type is None else character.type,
}
return response
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def character_simple(character: Character) -> dict:
"traditional": character.traditional,
"word": {"id": word_id} if word else None,
"source": {"source": source_value} if source else None,
"type": None if character.type is None else character.type,
}
)

Expand Down
8 changes: 5 additions & 3 deletions hinghwa-dict-backend/word/character/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def searchCharacters(request):
character_form = CharacterForm(body)
if character_form.is_valid():
character = character_form.save(commit=False)
if "type" in body:
character.type = body["type"]
character.save()
return JsonResponse({"id": character.id}, status=200)
else:
Expand Down Expand Up @@ -75,7 +77,7 @@ def searchCharactersPinyin(request):
pinyin_list = []
for item in characters:
if ((item.pinyin, item.character) not in result) or (
item.town == "城里" and item.county == "莆田"
item.town == "城里" and item.county == "莆田"
):
result[(item.pinyin, item.character, item.traditional)] = item
pinyin_list.append(item.pinyin)
Expand All @@ -86,13 +88,13 @@ def searchCharactersPinyin(request):
words_dict = {}
pronunciations_dict = {}
for item in Word.objects.filter(standard_pinyin__in=pinyin_list).filter(
visibility=True
visibility=True
):
if item.standard_pinyin not in words_dict:
words_dict[item.standard_pinyin] = []
words_dict[item.standard_pinyin].append(item)
for item in Pronunciation.objects.filter(pinyin__in=pinyin_list).filter(
visibility=True
visibility=True
):
if item.pinyin not in pronunciations_dict:
pronunciations_dict[item.pinyin] = item
Expand Down
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Meta:
"county",
"town",
"traditional",
"type",
)


Expand Down
15 changes: 15 additions & 0 deletions hinghwa-dict-backend/word/migrations/0007_character_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('word', '0006_list_ship'),
]

operations = [
migrations.AddField(
model_name='character',
name='type',
field=models.CharField(max_length=20, null=True, verbose_name='读音类型'),
),
]
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class Character(models.Model):
county = models.CharField(max_length=100, verbose_name="县区")
town = models.CharField(max_length=100, verbose_name="乡镇")
traditional = models.CharField(max_length=30, verbose_name="繁体字", default="")
type = models.CharField(max_length=20, verbose_name="读音类型", null=True)

def clean(self):
self.shengmu = self.shengmu.strip()
Expand Down

0 comments on commit 840e575

Please sign in to comment.