Esempio n. 1
0
def _save_result_to_db(result):
    from easy_english.models import (Translation, WordPronunciation,
        WordAssociationPicture, ForeignWord)

    if not len(result.translations) or not result.word:
        return

    fw = ForeignWord(title=result.word, transcription=result.transcription)
    fw.save()
    for tr in result.translations:
        translation = Translation(title=tr.word, votes=tr.votes,
                                  foreign_word=fw)
        translation.save()
        for pic in tr.pictures:
            WordAssociationPicture(name=pic,
                                   translation_word=translation).save()

    for pron in result.pronunciations:
        if pron and len(pron.strip()):
            WordPronunciation(name=pron, foreign_word=fw).save()
    for pic in result.pictures:
        if pic and len(pic.strip()):
            WordAssociationPicture(name=pic, foreign_word=fw).save()
Esempio n. 2
0
    def test_foreign_word_create_successfully(self):
        foreign_word = ForeignWord()
        foreign_word.title = 'appropriate'
        foreign_word.type = StructTypes.unknown.value
        foreign_word.language = Lang.english.value
        foreign_word.save()

        foreign_word = ForeignWord.objects.get(id=1)
        self.assertEqual('appropriate', foreign_word.title,
                         'Foreign word title != appropriate')