Ejemplo n.º 1
0
def get_vocab_by_kanji(kanji):
    v = Vocabulary.objects.filter(readings__character=kanji).distinct()
    number_of_vocabulary = v.count()
    if number_of_vocabulary > 1:
        error = "Found multiple Vocabulary with identical kanji with ids: [{}]".format(", ".join([str(vocab.id) for vocab in v]))
        logger.error(error)
        raise Vocabulary.MultipleObjectsReturned(error)
    elif number_of_vocabulary == 0:
        logger.error("While attempting to get vocabulary {} we could not find it!".format(kanji))
        raise Vocabulary.DoesNotExist("Couldn't find meaning: {}".format(kanji))
    else:
        return v.first()
Ejemplo n.º 2
0
 def get_vocab_by_kanji(self, kanji):
     v = Vocabulary.objects.filter(readings__character=kanji).distinct()
     number_of_vocabulary = v.count()
     if number_of_vocabulary > 1:
         error = f"Found multiple Vocabulary with identical kanji with ids: [{', '.join([str(vocab.id) for vocab in v])}]"
         logger.error(error)
         raise Vocabulary.MultipleObjectsReturned(error)
     elif number_of_vocabulary == 0:
         # TODO remove V1 syncer capability to ever update acutal infromation.
         # TODO leave this for the V2 syncer, as it is more accurate.
         logger.error(
             f"While attempting to get vocabulary {kanji} we could not find it!"
         )
         raise Vocabulary.DoesNotExist(f"Couldn't find meaning: {kanji}")
     else:
         return v.first()
Ejemplo n.º 3
0
def get_vocab_by_meaning(meaning):
    """
    Searches for a vocabulary object based on its meaning.

    :param meaning: meaning to search for
    :return: the vocabulary object, or None
    """
    try:
        v = Vocabulary.objects.get(meaning=meaning)
    except Vocabulary.DoesNotExist:
        logger.error("While attempting to get vocabulary {} we could not find it!".format(meaning))
        raise Vocabulary.DoesNotExist("Couldn't find meaning: {}".format(meaning))
    else:
        return v