home · contact · privacy
Refactor.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 15 Nov 2020 18:05:22 +0000 (19:05 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 15 Nov 2020 18:05:22 +0000 (19:05 +0100)
guiltcards.py
views/card.tpl
views/card_form.tpl

index 0487843cbdb53b4c6d304937da71e7da23ab8b5a..7d900df1e3fca444d26f334e0e7c4c7a9387e71b 100755 (executable)
@@ -84,10 +84,7 @@ def show_card(deck_id, card_id):
     data = get_card_data(deck_id, card_id, None)
     return dict(web_path=web_path,
                 deck_id=deck_id,
-                card_type=data['type'],
-                title=data['title'],
-                paragraphs=data['paragraphs'],
-                answers=data['answers'])
+                card=data)
 
 @post(web_path + '/decks/<deck_id>/cards/<card_id>')
 def update_card(deck_id, card_id):
@@ -96,10 +93,7 @@ def update_card(deck_id, card_id):
         os.makedirs(cards_dir)
     path_card = cards_dir + '/' + card_id
     card_type = request.forms.get('type')
-    json_dict = {'type': request.forms.get('type'),
-                 'title': '',
-                 'answers': [],
-                 'paragraphs': []}
+    json_dict = {'type': request.forms.get('type')}
     if card_type == 'action':
         json_dict['title'] = request.forms.get('title')
         json_dict['paragraphs'] = request.forms.getall('paragraph')
@@ -125,10 +119,7 @@ def card_form(deck_id, card_id):
     return dict(web_path=web_path,
                 card_id=card_id,
                 deck_id=deck_id,
-                card_type=data['type'],
-                title=data['title'],
-                paragraphs=data['paragraphs'],
-                answers=data['answers'],
+                card=data,
                 deletable=deletable)
 
 @get(web_path + '/decks/<deck_id>/cards/<card_id>/delete')
index eeae380755efa41a3c539d9bfb8404209795712f..31749f4b2ee0b42f55844a4db71fc91fad191fce 100644 (file)
@@ -9,18 +9,18 @@
 </style>
 <body>
   <div class="card">
-    % if card_type == 'guilt':
+    % if card["type"] == 'guilt':
     <h1 id="title">GUILT CARD</h1>
     <p id="prompt">Choose at least one of these guilts as your own:</p>
     <ul id="answers">
-    % for answer in answers:
+    % for answer in card["answers"]:
       <li>{{ answer }}</li>
     % end
     <ul/>
     % end
-    % if card_type == 'action':
-    <h1 id="title">ACTION CARD<br />{{ title }}</h1>
-    % for paragraph in paragraphs:
+    % if card["type"] == 'action':
+    <h1 id="title">ACTION CARD<br />{{ card["title"] }}</h1>
+    % for paragraph in card["paragraphs"]:
     <p>{{ paragraph }}</p>
     % end
     % end
index 106c35f7f626b8499912bf70c11239ccf59bd9e1..9e1e68763b407efe64d6a8d0e517ebe72c95c142 100644 (file)
@@ -1,10 +1,11 @@
 <!DOCTYPE HTML>
 <html>
 <body>
+<h1>Edit {{ card["type"] }} card</h1>
 <form action="{{ web_path }}/decks/{{deck_id}}/cards/{{ card_id }}" method="POST">
-<input type="hidden" name="type" value="{{ card_type }}" /><br />
-% if card_type == 'guilt':
-% for answer in answers:
+<input type="hidden" name="type" value="{{ card["type"] }}" /><br />
+% if card["type"] == 'guilt':
+% for answer in card["answers"]:
 answer: <input type="text" name="answer" value="{{ answer }}" /><br />
 % end
 answer: <input type="text" name="answer" value="" /><br />
@@ -12,9 +13,9 @@ answer: <input type="text" name="answer" value="" /><br />
 answer: <input type="text" name="answer" value="" /><br />
 answer: <input type="text" name="answer" value="" /><br />
 % end
-% if card_type == 'action':
-title: <input type="text" name="title" value="{{ title }}" /><br />
-% for paragraph in paragraphs:
+% if card["type"] == 'action':
+title: <input type="text" name="title" value="{{ card["title"] }}" /><br />
+% for paragraph in card["paragraphs"]:
 paragraph: <input type="text" name="paragraph" value="{{ paragraph }}" /><br />
 % end
 paragraph: <input type="text" name="paragraph" value="" /><br />