Пример #1
0
 def rebuildQA(self, deck, media=True):
     # format qa
     d = {}
     for f in self.fact.model.fieldModels:
         d[f.name] = (f.id, self.fact[f.name])
     qa = formatQA(None, self.fact.modelId, d, self.splitTags(),
                   self.cardModel, deck)
     # find old media references
     files = {}
     for type in ("question", "answer"):
         for f in mediaFiles(getattr(self, type) or ""):
             if f in files:
                 files[f] -= 1
             else:
                 files[f] = -1
     # update q/a
     self.question = qa['question']
     self.answer = qa['answer']
     # determine media delta
     for type in ("question", "answer"):
         for f in mediaFiles(getattr(self, type)):
             if f in files:
                 files[f] += 1
             else:
                 files[f] = 1
     # update media counts if we're attached to deck
     if media:
         for (f, cnt) in files.items():
             updateMediaCount(deck, f, cnt)
     self.setModified()
Пример #2
0
 def __init__(self, fact=None, cardModel=None, due=None):
     self.tags = u""
     self.id = genID()
     # new cards start as new & due
     self.type = 2
     self.isDue = True
     self.timerStarted = False
     self.timerStopped = False
     self.modified = time.time()
     if due:
         self.due = due
     else:
         self.due = self.modified
     self.combinedDue = self.due
     if fact:
         self.fact = fact
     if cardModel:
         self.cardModel = cardModel
         # for non-orm use
         self.cardModelId = cardModel.id
         self.ordinal = cardModel.ordinal
         d = {}
         for f in self.fact.model.fieldModels:
             d[f.name] = (f.id, self.fact[f.name])
         qa = formatQA(None, fact.modelId, d, self.splitTags(), cardModel)
         self.question = qa['question']
         self.answer = qa['answer']
Пример #3
0
 def __init__(self, fact=None, cardModel=None, created=None):
     self.tags = u""
     self.id = genID()
     # new cards start as new & due
     self.type = 2
     self.isDue = True
     self.timerStarted = False
     self.timerStopped = False
     self.modified = time.time()
     if created:
         self.created = created
         self.due = created
     else:
         self.due = self.modified
     self.combinedDue = self.due
     if fact:
         self.fact = fact
     if cardModel:
         self.cardModel = cardModel
         # for non-orm use
         self.cardModelId = cardModel.id
         self.ordinal = cardModel.ordinal
         d = {}
         for f in self.fact.model.fieldModels:
             d[f.name] = (f.id, self.fact[f.name])
         qa = formatQA(None, fact.modelId, d, self.splitTags(), cardModel)
         self.question = qa['question']
         self.answer = qa['answer']
Пример #4
0
 def rebuildQA(self, deck, media=True):
     # format qa
     d = {}
     for f in self.fact.model.fieldModels:
         d[f.name] = (f.id, self.fact[f.name])
     qa = formatQA(None, self.fact.modelId, d, self.splitTags(), self.cardModel, deck)
     # find old media references
     files = {}
     for type in ("question", "answer"):
         for f in mediaFiles(getattr(self, type) or ""):
             if f in files:
                 files[f] -= 1
             else:
                 files[f] = -1
     # update q/a
     self.question = qa["question"]
     self.answer = qa["answer"]
     # determine media delta
     for type in ("question", "answer"):
         for f in mediaFiles(getattr(self, type)):
             if f in files:
                 files[f] += 1
             else:
                 files[f] = 1
     # update media counts if we're attached to deck
     if media:
         for (f, cnt) in files.items():
             updateMediaCount(deck, f, cnt)
     self.setModified()
Пример #5
0
 def setModified(self, textChanged=False):
     "Mark modified and update cards."
     self.modified = time.time()
     if textChanged:
         d = {}
         for f in self.model.fieldModels:
             d[f.name] = (f.id, self[f.name])
         for card in self.cards:
             qa = formatQA(None, self.modelId, d, card.splitTags(), card.cardModel)
             card.question = qa['question']
             card.answer = qa['answer']
             card.setModified()
Пример #6
0
 def setModified(self, textChanged=False):
     "Mark modified and update cards."
     self.modified = time.time()
     if textChanged:
         d = {}
         for f in self.model.fieldModels:
             d[f.name] = (f.id, self[f.name])
         for card in self.cards:
             qa = formatQA(None, self.modelId, d, card.splitTags(),
                           card.cardModel)
             card.question = qa['question']
             card.answer = qa['answer']
             card.setModified()
Пример #7
0
 def setModified(self, textChanged=False):
     "Mark modified and update cards."
     self.modified = time.time()
     if textChanged:
         d = {}
         for f in self.model.fieldModels:
             d[f.name] = (f.id, self[f.name])
         self.spaceUntil = stripHTMLMedia(u" ".join([x[1] for x in d.values()]))
         for card in self.cards:
             qa = formatQA(None, self.modelId, d, card.splitTags(), card.cardModel)
             card.question = qa['question']
             card.answer = qa['answer']
             card.setModified()