Autofill set positions (#41)
continuous-integration/drone/push Build is passing Details

Implements #40

Co-authored-by: Raymond Li <hi@raymond.li>
Reviewed-on: #41
Co-authored-by: Raymond Li <raymo@csclub.uwaterloo.ca>
Co-committed-by: Raymond Li <raymo@csclub.uwaterloo.ca>
This commit is contained in:
Raymond Li 2022-01-02 02:41:28 -05:00
parent d7b6ac2307
commit f45efefaca
1 changed files with 25 additions and 5 deletions

View File

@ -1,7 +1,9 @@
from threading import Thread
from asciimatics.widgets import Layout, Label, Text
from zope import component
from ...utils import defer, http_post
from ...utils import defer, http_post, http_get
from ..CeoFrame import CeoFrame
from .GetPositionsView import position_names
from ceo_common.interfaces import IConfig
@ -9,6 +11,24 @@ from ceod.transactions.members.UpdateMemberPositionsTransaction import UpdateMem
class SetPositionsView(CeoFrame):
"""
Reset the positions to the currently set positions
"""
def reset_positions(self):
def target():
self.flash_message('Looking up positions...')
try:
resp = http_get('/api/positions')
if not resp.ok:
return
positions = resp.json()
for pos, username in positions.items():
self._widgets[pos].value = username
finally:
self.clear_flash_message(force_update=True)
Thread(target=target).start()
def __init__(self, screen, width, height, model):
super().__init__(
screen, height, width, model, 'SetPositions',
@ -19,11 +39,11 @@ class SetPositionsView(CeoFrame):
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
self._widgets = []
self._widgets = {}
for pos in avail:
suffix = ' (*)' if pos in required else ''
widget = Text(position_names[pos] + suffix, pos)
self._widgets.append(widget)
self._widgets[pos] = widget
layout.add_widget(widget)
layout = Layout([100])
@ -34,12 +54,12 @@ class SetPositionsView(CeoFrame):
self.add_buttons(
back_btn=True,
next_scene='Confirm', on_next=self._next)
self.reset_positions()
self.fix()
def _ceoframe_on_reset(self):
super()._ceoframe_on_reset()
for widget in self._widgets:
widget.value = None
self.reset_positions()
def _next(self):
self.save()