from bottle import debug, run, default_app, get, view, request, post, redirect
import os
import json
+import base64
web_path = '/guiltcards'
cards_dir = 'cards/'
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':'?',
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')
@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')
<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>
<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>