From: Christian Heller Date: Sun, 15 Nov 2020 18:05:22 +0000 (+0100) Subject: Refactor. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_free?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//cards/') 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//cards//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 @@
- % if card_type == 'guilt': + % if card["type"] == 'guilt':

GUILT CARD

Choose at least one of these guilts as your own:

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

      ACTION CARD
      {{ title }}

      - % for paragraph in paragraphs: + % if card["type"] == 'action': +

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

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

      {{ paragraph }}

      % 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 @@ +

      Edit {{ card["type"] }} card

      -
      -% if card_type == 'guilt': -% for answer in answers: +
      +% if card["type"] == 'guilt': +% for answer in card["answers"]: answer:
      % end answer:
      @@ -12,9 +13,9 @@ answer:
      answer:
      answer:
      % end -% if card_type == 'action': -title:
      -% for paragraph in paragraphs: +% if card["type"] == 'action': +title:
      +% for paragraph in card["paragraphs"]: paragraph:
      % end paragraph: