home · contact · privacy
Differentiate card data processing between action and guilt cards.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 15 Nov 2020 17:56:19 +0000 (18:56 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 15 Nov 2020 17:56:19 +0000 (18:56 +0100)
guiltcards.py
views/card.tpl
views/card_form.tpl
views/cards.tpl
views/cards_print.tpl

index cad1cb36da57bb3f49a3857b9b0c250649293f11..0487843cbdb53b4c6d304937da71e7da23ab8b5a 100755 (executable)
@@ -7,7 +7,7 @@ import base64
 web_path = '/guiltcards'
 decks_dir = 'decks/'
 
-def get_card_data(deck_id, card_id):
+def get_card_data(deck_id, card_id, card_type_hint):
     cards_dir = decks_dir + deck_id
     if not os.path.exists(cards_dir):
         os.makedirs(cards_dir)
@@ -16,9 +16,10 @@ def get_card_data(deck_id, card_id):
         with open(path_card, 'r') as f:
             data = json.loads(f.read())
     else:
-        data = {'title': '?',
-                'prompt':'?',
-                'answers': ['?', '?']}
+        data = {'type': card_type_hint,
+                'title': 'title',
+                'paragraphs': ['first paragraph', 'second paragraph'],
+                'answers': ['first option', 'second option']}
     return data
 
 @get(web_path + '/')
@@ -29,7 +30,6 @@ def list_decks():
         os.makedirs(decks_dir)
     deck_ids = os.listdir(decks_dir)
     decks = {}
-    print('DEBUG', deck_ids)
     for deck_id in deck_ids:
         decks[deck_id] = base64.b64decode(deck_id).decode()
     return dict(web_path=web_path, decks=decks)
@@ -58,20 +58,35 @@ def list_cards(deck_id):
                 deck_name=deck_name,
                 cards=cards)
 
+@get(web_path + '/decks/<deck_id>/printable')
+@view('cards_print')
+def print_view(deck_id):
+    cards_dir = decks_dir + deck_id
+    cards = []
+    if os.path.exists(cards_dir):
+        card_ids = os.listdir(cards_dir)
+        for card_id in card_ids:
+            cards += [get_card_data(deck_id, card_id, None)]
+    deck_name = base64.b64decode(deck_id).decode()
+    return dict(cards=cards)
+
 @get(web_path + '/decks/<deck_id>/cards/')
 def new_card(deck_id):
     card_name = request.query.get('card_name')
+    card_type = request.query.get('card_type')
     card_id = base64.b64encode(card_name.encode()).decode()
-    redirect(web_path + '/decks/' + deck_id + '/cards/' + card_id + '/form')
+    redirect(web_path + '/decks/' + deck_id + '/cards/' + card_id
+             + '/form?type=' + card_type)
 
 @get(web_path + '/decks/<deck_id>/cards/<card_id>/view')
 @view('card')
 def show_card(deck_id, card_id):
-    data = get_card_data(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'],
-                prompt=data['prompt'],
+                paragraphs=data['paragraphs'],
                 answers=data['answers'])
 
 @post(web_path + '/decks/<deck_id>/cards/<card_id>')
@@ -80,13 +95,20 @@ def update_card(deck_id, card_id):
     if not os.path.exists(cards_dir):
         os.makedirs(cards_dir)
     path_card = cards_dir + '/' + card_id
-    json_dict = {
-        'title': request.forms.get('title'),
-        'prompt': request.forms.get('prompt'),
-        'answers': request.forms.getall('answer')
-    }
-    json_dict['answers'] = [answer for answer in json_dict['answers']
-                            if answer.strip() != '']
+    card_type = request.forms.get('type')
+    json_dict = {'type': request.forms.get('type'),
+                 'title': '',
+                 'answers': [],
+                 'paragraphs': []}
+    if card_type == 'action':
+        json_dict['title'] = request.forms.get('title')
+        json_dict['paragraphs'] = request.forms.getall('paragraph')
+        json_dict['paragraphs'] = [paragraph for paragraph in json_dict['paragraphs']
+                                if paragraph.strip() != '']
+    else:
+        json_dict['answers'] = request.forms.getall('answer')
+        json_dict['answers'] = [answer for answer in json_dict['answers']
+                                if answer.strip() != '']
     with open(path_card, 'w') as f:
         f.write(json.dumps(json_dict, indent=4))
     redirect(web_path + '/decks/' + deck_id + '/cards/' + card_id + '/view')
@@ -94,7 +116,8 @@ def update_card(deck_id, card_id):
 @get(web_path + '/decks/<deck_id>/cards/<card_id>/form')
 @view('card_form')
 def card_form(deck_id, card_id):
-    data = get_card_data(deck_id, card_id)
+    card_type = request.query.get('type')
+    data = get_card_data(deck_id, card_id, card_type)
     card_path = decks_dir + deck_id + '/' + card_id
     deletable = False
     if os.path.exists(card_path):
@@ -102,8 +125,9 @@ 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'],
-                prompt=data['prompt'],
+                paragraphs=data['paragraphs'],
                 answers=data['answers'],
                 deletable=deletable)
 
index cb121e64444ddeb714f09b1ac5a5d3bfc433beb7..eeae380755efa41a3c539d9bfb8404209795712f 100644 (file)
@@ -1,21 +1,29 @@
 <!DOCTYPE HTML>
 <html>
 <style>
-  #card {
+  .card {
       box-sizing: border-box;
       border: 30px solid #aaaaaa;
       width: 200px;
       height: 400px; }
 </style>
 <body>
-  <div id="card">
-    <h1 id="title">{{ title }}</h1>
-    <p id="prompt">{{ prompt }}</p>
+  <div class="card">
+    % 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:
       <li>{{ answer }}</li>
     % end
     <ul/>
+    % end
+    % if card_type == 'action':
+    <h1 id="title">ACTION CARD<br />{{ title }}</h1>
+    % for paragraph in paragraphs:
+    <p>{{ paragraph }}</p>
+    % end
+    % end
   </div>
 <a href="{{ web_path }}/decks/{{deck_id}}/cards">back to overview</a>
 </body>
index c4c64885436ca61db6be939ea5064f53dfc8989e..106c35f7f626b8499912bf70c11239ccf59bd9e1 100644 (file)
@@ -2,18 +2,30 @@
 <html>
 <body>
 <form action="{{ web_path }}/decks/{{deck_id}}/cards/{{ card_id }}" method="POST">
-title: <input type="text" name="title" value="{{ title }}" /><br />
-prompt: <input type="text" name="prompt" value="{{ prompt }}" /><br />
+<input type="hidden" name="type" value="{{ card_type }}" /><br />
+% if card_type == 'guilt':
 % for answer in answers:
 answer: <input type="text" name="answer" value="{{ answer }}" /><br />
 % end
-answer: <input type="text" name="answer" /><br />
-answer: <input type="text" name="answer" /><br />
-answer: <input type="text" name="answer" /><br />
+answer: <input type="text" name="answer" value="" /><br />
+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:
+paragraph: <input type="text" name="paragraph" value="{{ paragraph }}" /><br />
+% end
+paragraph: <input type="text" name="paragraph" value="" /><br />
+paragraph: <input type="text" name="paragraph" value="" /><br />
+paragraph: <input type="text" name="paragraph" value="" /><br />
+paragraph: <input type="text" name="paragraph" value="" /><br />
+% end
 <input type="submit" value="OK" />
 </form>
 <p>
-(leave specific answer fields empty to remove them as answer options)
+(leave specific fields empty to have them not appear on the card)
 </p>
 % if deletable:
 <p>
index 2c20cb05a96ea912bb3738a677aa7a9f0bbf8989..d63aab12f533ab6bda138108024443d4abd92487 100644 (file)
@@ -8,9 +8,12 @@
 % end
 </ul>
 <form action="{{ web_path }}/decks/{{deck_id}}/cards/" method="GET">
-add another card? name: <input type="text" name="card_name" />
+add another guilt card? name: <input type="text" name="card_name" /> type: <select name="card_type"><option value="guilt">guilt card</option><option value="action">action card</option></select>
 </form>
 <p>
+<a href="{{ web_path }}/decks/{{deck_id}}/printable">deck print view</a>
+</p>
+<p>
 <a href="{{ web_path }}/decks">back to decks overview</a>
 </p>
 </body>
index a649ac6c4d03388659d4e1ca18ac7f07d0f92e34..99f88b0fe3fc4484743ae06a3441d2639646ece1 100644 (file)
 <body>
 % for card in cards:
   <div class="card">
-    <h1 class="title">{{ card["title"] }}</h1>
-    <p class="prompt">{{ card["prompt"] }}</p>
-    <ul class="answers">
+    % 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 card["answers"]:
       <li>{{ answer }}</li>
     % end
     <ul/>
+    % end
+    % if card["type"] == 'action':
+    <h1 id="title">ACTION CARD<br />{{ card["title"] }}</h1>
+    % for paragraph in card["paragraphs"]:
+    <p>{{ paragraph }}</p>
+    % end
+    % end
   </div>
 % end
 </body>