Пример #1
0
def search(request):
    keyword = request.POST.get('keyword')
    characters_1 = Character.objects.filter(
        Q(pinyin__unaccent__iexact=keyword) | Q(chinese__exact=keyword))
    characters_2 = Character.objects.filter(
        Q(definition_1__icontains=keyword) | Q(definition_2__icontains=keyword)
        | Q(definition_3__icontains=keyword)
        | Q(pinyin__unaccent__icontains=keyword)).difference(characters_1)
    return JsonResponse({
        'characters':
        chenyx_serialize(characters_1) + chenyx_serialize(characters_2)
    })
Пример #2
0
def get_radical(request):
    radical_id = request.POST.get('radical_id')
    radical = Radical.objects.get(pk=radical_id)
    return JsonResponse({'radical': chenyx_serialize(radical)})
Пример #3
0
def get_character(request):
    character_id = request.POST.get('character_id')
    character = Character.objects.get(pk=character_id)
    return JsonResponse({'character': chenyx_serialize(character)})
Пример #4
0
def get_available_sets(request):
    sets = []
    for set in CharacterSet.objects.all():
        if not request.user.user_character_tags.filter(name=set.name).exists():
            sets.append(set)
    return JsonResponse({'sets': chenyx_serialize(sets, ['characters'])})