def add(request): """ HTTP POST /leitner/add Data hanzi e.g. "u0x2345 u0x1111" """ hanziList = request.POST["hanzi"].split(" ") if hanziList == "": return for hanzi in hanziList: if hanzi == "": continue try: h = Leitner.objects.get(user=request.user, hanzi=hanzi) h.forget_times += 1 h.deck = "C" # Deck Current h.level = 0 # Level 1 h.save() except ObjectDoesNotExist: h = Leitner(user=request.user, hanzi=hanzi) h.save() return
def importFromStudyHistory(): for h in StudyHistory.objects.all(): q = Leitner.objects.filter(hanzi=h.vocabulary, user=h.user) if not q: if h.history_type == "N": # Deck Current, Level 0 l = Leitner( user=h.user, hanzi=h.vocabulary, last_study_date=h.revise_date, forget_times=h.studied_times, deck="C", level="0", ) l.save() elif h.history_type == "S": # Deck session (0), Level 1 l = Leitner( user=h.user, hanzi=h.vocabulary, last_study_date=h.revise_date, forget_times=h.studied_times, deck="0", level="1", ) l.save() elif h.history_type == "G": # Deck Retired, Level 5 l = Leitner( user=h.user, hanzi=h.vocabulary, last_study_date=h.revise_date, forget_times=h.studied_times, deck="R", level="5", ) l.save() else: raise Exception("Unknown history_type")