From a9944c178f13ed6fd876a8757a147ca5949d6423 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 31 May 2019 20:51:05 +0200 Subject: Board preview feature --- http/api/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'http/api') diff --git a/http/api/api.py b/http/api/api.py index 1c1cb0f..be2635f 100644 --- a/http/api/api.py +++ b/http/api/api.py @@ -63,6 +63,22 @@ def handle_upload(response, request): input_file.close() if not len(dealset): raise RuntimeError('Dealset is empty') + if params['display_deals']: + preview_obj = [] + for board in dealset: + deal_preview = { + 'number': board.number, + 'conditions': 'nesw'[board.dealer], + 'hands': [] + } + for pair in ['ns', 'ew']: + if board.vulnerable[pair.upper()]: + deal_preview['conditions'] += '-' + pair + deal_preview['hands'] = board.hands + preview_obj.append(deal_preview) + return_obj['preview'] = preview_obj + else: + return_obj['preview'] = None except RuntimeError as e: return_obj['error'] = unicode(e) return _print_response(response, return_obj) -- cgit v1.2.3