def add_pairs_to_cats(pairs, cats): for sp, eng in pairs: t = select_or_create(models.Triplet, l1=eng, l2=sp) t.save() for c in cats: cl = models.CategoryLink(triplet=t, category=c) cl.save()
def second_newest_categories(*args): smII = select_or_create(models.Category, name=u'Spanish II Semester II Vocabulary') smII.save() cat = select_or_create(models.Category, name=u'Lengua de las mariposas - I', parent=smII) cat.save() ifi = file(u'lengua1.txt', u'r') for l in ifi.readlines(): words = l.split(':') words = [w.strip() for w in words] t = select_or_create(models.Triplet, l1=words[1], l2=words[0]) t.save() cl = models.CategoryLink(triplet=t, category=cat) cl.save() cl = models.CategoryLink(triplet=t, category=smII) cl.save()
def add_verbs(verblist, spanish_func, english_func, category): print u'Creating verbs for u', category.name for sp, eng in conjugations.make_verb_quiz(verblist, spanish_func, english_func): t = select_or_create(models.Triplet, l1=eng, l2=sp) t.save() if type(category) != list: category = [category] for c in category: cl = models.CategoryLink(triplet=t, category=c) cl.save() print u'Done!'
def make_quiz(name, categories, description=None): qg = select_or_create(models.QuizGroup, name=name) if description: qg.description = description qg.save() allc = models.Category(name=name + u' (all)') allc.save() for c in categories: qgl = select_or_create(models.QuizGroupLink, category=c, quizgroup=qg) qgl.save() for cl in models.CategoryLink.objects.filter(category=c): new_cl = models.CategoryLink(category=allc, triplet=cl.triplet) new_cl.save() qgl = select_or_create(models.QuizGroupLink, category=allc, quizgroup=qg) qgl.save()
def init(*args): models.Category.objects.all().delete() print u'DELTED ALL CATS' #for o in models.Triplet.objects.all(): o.delete() #print u'DELTED ALL TRIPLETS' models.CategoryLink.objects.all().delete() print u'DELTED ALL CATLINKS' cleanup_old_mistakes() cat = models.Category(name=u'Spanish II Semester I Vocabulary') cat.save() ifi = file(u'unordered_first_161_words.txt', u'r') for l in ifi.readlines(): words = l.split(':') words = [w.strip() for w in words] t = select_or_create(models.Triplet, l1=words[1], l2=words[0]) t.save() cl = models.CategoryLink(triplet=t, category=cat) cl.save() verb_forms() init_quizzes() return HttpResponseRedirect(u'/quiz/')