home · contact · privacy
Use b64 for card IDs.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 9 Nov 2020 20:59:48 +0000 (21:59 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 9 Nov 2020 20:59:48 +0000 (21:59 +0100)
guiltcards.py
views/cards.tpl
views/delete_card.tpl

index 92cd49b23c9b03f387654a1119404028c455b792..aa77ce3f789add3e2cf05a8d65b35db27aaee6e8 100755 (executable)
@@ -2,6 +2,7 @@
 from bottle import debug, run, default_app, get, view, request, post, redirect
 import os
 import json
+import base64
 
 web_path = '/guiltcards'
 cards_dir = 'cards/'
@@ -12,7 +13,7 @@ def get_card_data(card_id):
     path_card = cards_dir + card_id
     if os.path.exists(path_card):
         with open(path_card, 'r') as f:
-            data = json.loads(f.read())#f.read()
+            data = json.loads(f.read())
     else:
         data = {'title': '?',
                 'prompt':'?',
@@ -30,12 +31,16 @@ def list_cards():
     if not os.path.exists(cards_dir):
         os.makedirs(cards_dir)
     card_ids = os.listdir(cards_dir)
+    cards = {}
+    for card_id in card_ids:
+        cards[card_id] = base64.b64decode(card_id).decode()
     return dict(web_path=web_path,
-                card_ids=card_ids)
+                cards=cards)
 
 @get(web_path + '/cards/')
 def new_card():
-    card_id = request.query.get('card_id')
+    card_name = request.query.get('card_name')
+    card_id = base64.b64encode(card_name.encode()).decode()
     redirect(web_path + '/cards/' + card_id + '/form')
 
 @get(web_path + '/cards/<card_id>/view')
@@ -81,7 +86,9 @@ def card_form(card_id):
 @get(web_path + '/cards/<card_id>/delete')
 @view('delete_card')
 def delete_card_ask(card_id):
+    card_name = base64.b64decode(card_id.encode()).decode()
     return dict(web_path=web_path,
+                card_name=card_name,
                 card_id=card_id)
 
 @post(web_path + '/cards/<card_id>/delete')
index dbf5ea63c06ea1caf1be7f93a2341de110d3ccba..758fe22b70e9ade34a39f5f4c700a9aa800d557d 100644 (file)
@@ -2,12 +2,12 @@
 <html>
 <body>
 <ul>
-% for card_id in card_ids:
-<li><a href="{{ web_path }}/cards/{{card_id}}/view">{{card_id}}</a> (<a href="{{ web_path }}/cards/{{card_id}}/form">edit</a>)</li>
+% for card_id in cards:
+<li><a href="{{ web_path }}/cards/{{card_id}}/view">{{cards[card_id]}}</a> (<a href="{{ web_path }}/cards/{{card_id}}/form">edit</a>)</li>
 % end
 </ul>
 <form action="{{ web_path }}/cards/" method="GET">
-add another? name: <input type="text" name="card_id" />
+add another? name: <input type="text" name="card_name" />
 </form>
 </body>
 </html>
index 45b644998dcc2400109d4dea5532e5c8a0ce354a..cd1ec0fde4c6a72df92031498a5d277352fd1825 100644 (file)
@@ -2,7 +2,7 @@
 <html>
 <body>
 <form action="{{ web_path }}/cards/{{ card_id }}/delete" method="POST">
-<input type="submit" value="delete {{card_id}}?" />
+<input type="submit" value="delete {{card_name}}?" />
 </form>
 <a href="{{ web_path }}/cards">Nah, better not …</a>
 </body>