~ubuntu-branches/ubuntu/lucid/anki/lucid-updates

« back to all changes in this revision

Viewing changes to libanki/anki/cards.py

  • Committer: Bazaar Package Importer
  • Author(s): Mackenzie Morgan
  • Date: 2010-05-31 15:55:50 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100531155550-wj3tag8bvp6fwhpo
Tags: 0.9.9.8.6-2~lucid1
Backport from maverick to fix FTBFS (LP: #550145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
class Card(object):
69
69
    "A card."
70
70
 
71
 
    def __init__(self, fact=None, cardModel=None):
 
71
    def __init__(self, fact=None, cardModel=None, created=None):
72
72
        self.tags = u""
73
73
        self.id = genID()
74
74
        # new cards start as new & due
77
77
        self.timerStarted = False
78
78
        self.timerStopped = False
79
79
        self.modified = time.time()
80
 
        self.due = self.modified
81
 
        self.combinedDue = self.modified
 
80
        if created:
 
81
            self.created = created
 
82
            self.due = created
 
83
        else:
 
84
            self.due = self.modified
 
85
        self.combinedDue = self.due
82
86
        if fact:
83
87
            self.fact = fact
84
88
        if cardModel:
85
89
            self.cardModel = cardModel
 
90
            # for non-orm use
 
91
            self.cardModelId = cardModel.id
86
92
            self.ordinal = cardModel.ordinal
87
93
            d = {}
88
94
            for f in self.fact.model.fieldModels:
110
116
        "Generate a random offset to spread intervals."
111
117
        self.fuzz = random.uniform(0.95, 1.05)
112
118
 
113
 
    def htmlQuestion(self, type="question"):
114
 
        div = '''<div id="cm%s%s">%s</div>''' % (
115
 
            type[0], hexifyID(self.cardModel.id), getattr(self, type))
 
119
    def htmlQuestion(self, type="question", align=True):
 
120
        div = '''<div class="card%s" id="cm%s%s">%s</div>''' % (
 
121
            type[0], type[0], hexifyID(self.cardModelId),
 
122
            getattr(self, type))
116
123
        # add outer div & alignment (with tables due to qt's html handling)
 
124
        if not align:
 
125
            return div
117
126
        attr = type + 'Align'
118
127
        if getattr(self.cardModel, attr) == 0:
119
128
            align = "center"
124
133
        return (("<center><table width=95%%><tr><td align=%s>" % align) +
125
134
                div + "</td></tr></table></center>")
126
135
 
127
 
    def htmlAnswer(self):
128
 
        return self.htmlQuestion(type="answer")
 
136
    def htmlAnswer(self, align=True):
 
137
        return self.htmlQuestion(type="answer", align=align)
129
138
 
130
139
    def updateStats(self, ease, state):
131
140
        self.reps += 1