From: Christian Heller <c.heller@plomlompom.de> Date: Sun, 15 Nov 2020 18:05:22 +0000 (+0100) Subject: Refactor. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/day?a=commitdiff_plain;h=f192f42b97251a378116ac5be16c8e5266dbc817;p=guiltcards Refactor. --- diff --git a/guiltcards.py b/guiltcards.py index 0487843..7d900df 100755 --- a/guiltcards.py +++ b/guiltcards.py @@ -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') diff --git a/views/card.tpl b/views/card.tpl index eeae380..31749f4 100644 --- a/views/card.tpl +++ b/views/card.tpl @@ -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 diff --git a/views/card_form.tpl b/views/card_form.tpl index 106c35f..9e1e687 100644 --- a/views/card_form.tpl +++ b/views/card_form.tpl @@ -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 />