From: Christian Heller Date: Sun, 15 Nov 2020 17:56:19 +0000 (+0100) Subject: Differentiate card data processing between action and guilt cards. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/pick_tasks?a=commitdiff_plain;h=f77e6362f9b1e8d0e7bc93e4f6a0d6e1397e1b23;p=guiltcards Differentiate card data processing between action and guilt cards. --- diff --git a/guiltcards.py b/guiltcards.py index cad1cb3..0487843 100755 --- a/guiltcards.py +++ b/guiltcards.py @@ -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//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//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//cards//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//cards/') @@ -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//cards//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) diff --git a/views/card.tpl b/views/card.tpl index cb121e6..eeae380 100644 --- a/views/card.tpl +++ b/views/card.tpl @@ -1,21 +1,29 @@ -
-

{{ title }}

-

{{ prompt }}

+
+ % if card_type == 'guilt': +

GUILT CARD

+

Choose at least one of these guilts as your own:

    % for answer in answers:
  • {{ answer }}
  • % end
      + % end + % if card_type == 'action': +

      ACTION CARD
      {{ title }}

      + % for paragraph in paragraphs: +

      {{ paragraph }}

      + % end + % end
back to overview diff --git a/views/card_form.tpl b/views/card_form.tpl index c4c6488..106c35f 100644 --- a/views/card_form.tpl +++ b/views/card_form.tpl @@ -2,18 +2,30 @@
-title:
-prompt:
+
+% if card_type == 'guilt': % for answer in answers: answer:
% end -answer:
-answer:
-answer:
+answer:
+answer:
+answer:
+answer:
+% end +% if card_type == 'action': +title:
+% for paragraph in paragraphs: +paragraph:
+% end +paragraph:
+paragraph:
+paragraph:
+paragraph:
+% end

-(leave specific answer fields empty to remove them as answer options) +(leave specific fields empty to have them not appear on the card)

% if deletable:

diff --git a/views/cards.tpl b/views/cards.tpl index 2c20cb0..d63aab1 100644 --- a/views/cards.tpl +++ b/views/cards.tpl @@ -8,9 +8,12 @@ % end

-add another card? name: +add another guilt card? name: type:

+deck print view +

+

back to decks overview

diff --git a/views/cards_print.tpl b/views/cards_print.tpl index a649ac6..99f88b0 100644 --- a/views/cards_print.tpl +++ b/views/cards_print.tpl @@ -11,13 +11,21 @@ % for card in cards:
-

{{ card["title"] }}

-

{{ card["prompt"] }}

-
    + % if card["type"] == 'guilt': +

    GUILT CARD

    +

    Choose at least one of these guilts as your own:

    +
      % for answer in card["answers"]:
    • {{ answer }}
    • % end
        + % end + % if card["type"] == 'action': +

        ACTION CARD
        {{ card["title"] }}

        + % for paragraph in card["paragraphs"]: +

        {{ paragraph }}

        + % end + % end
% end