def formatQA(cid, mid, fact, tags, cm, deck): "Return a dict of {id, question, answer}" d = {'id': cid} fields = {} for (k, v) in fact.items(): fields["text:"+k] = stripHTML(v[1]) if v[1]: fields[k] = '<span class="fm%s">%s</span>' % ( hexifyID(v[0]), v[1]) else: fields[k] = u"" fields['tags'] = tags[0] fields['Tags'] = tags[0] fields['modelTags'] = tags[1] fields['cardModel'] = tags[2] # render q & a ret = [] for (type, format) in (("question", cm.qformat), ("answer", cm.aformat)): # convert old style format = re.sub("%\((.+?)\)s", "{{\\1}}", format) # allow custom rendering functions & info fields = runFilter("prepareFields", fields, cid, mid, fact, tags, cm, deck) html = render(format, fields) d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm, deck) return d
def htmlQuestion(self, type="question", align=True): div = '''<div class="card%s" id="cm%s%s">%s</div>''' % ( type[0], type[0], hexifyID(self.cardModelId), getattr(self, type)) # add outer div & alignment (with tables due to qt's html handling) if not align: return div attr = type + 'Align' if getattr(self.cardModel, attr) == 0: align = "center" elif getattr(self.cardModel, attr) == 1: align = "left" else: align = "right" return (("<center><table width=95%%><tr><td align=%s>" % align) + div + "</td></tr></table></center>")
def syncOneWayDeckName(self): return (self.deck.s.scalar("select name from sources where id = :id", id=self.server.deckName) or hexifyID(int(self.server.deckName)))
def syncOneWayDeckName(self): return self.deck.s.scalar("select name from sources where id = :id", id=self.server.deckName) or hexifyID( int(self.server.deckName) )