-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeckCreationWizard.py
56 lines (43 loc) · 1.26 KB
/
DeckCreationWizard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from model.Card import PrivateCard
class DeckCreationWizard(object):
def __init__(self, author, deck):
self.author = author
self.deck = deck
def save(self, exception=False):
try:
self.author.save()
except Exception:
if exception:
raise
def add_card(self, c: PrivateCard):
self.deck.add_card(c)
self.save()
def new_card(self):
d = PrivateCard(question='', answer='')
self.add_card(d)
return d
def set_name(self, name: str):
self.deck.name = name
def delete_card(self, index):
del self.cards[index]
for i, c in enumerate(self.cards):
c.dc_id = i
self.save()
@property
def name(self):
return self.deck.name
@property
def cards(self):
return self.deck.cards
@property
def size(self):
return self.deck.size
def load_csv(self, filename):
from pandas import read_csv
df = read_csv(filename, sep=';')
for (q, a) in zip(df['question'], df['answer']):
self.add_card(PrivateCard(question=q, answer=a))
def share(self):
self.deck.share()
def __del__(self):
self.save(exception=True)