implement GetGroupView

pull/20/head
Max Erenberg 1 year ago
parent 6b3ad28e89
commit beb16b1740
  1. 3
      ceo/tui/Model.py
  2. 5
      ceo/tui/ResultView.py
  3. 18
      ceo/tui/groups/GetGroupResultView.py
  4. 31
      ceo/tui/groups/GetGroupView.py
  5. 4
      ceo/tui/start.py

@ -48,6 +48,9 @@ class Model:
'cn': '',
'description': '',
},
'GetGroup': {
'cn': '',
},
}
self.viewdata = deepcopy(self._initial_viewdata)
# data which is shared between multiple views

@ -30,7 +30,10 @@ class ResultView(CeoFrame):
def _add_pair(self, key: str, val: str):
layout = Layout([10, 1, 10])
self.add_layout(layout)
layout.add_widget(Label(key + ':', align='>'), 0)
if key:
layout.add_widget(Label(key + ':', align='>'), 0)
else:
layout.add_widget(Label(''), 0)
layout.add_widget(Label(val, align='<'), 2)
# override this method in child classes if desired

@ -0,0 +1,18 @@
import requests
from ..ResultView import ResultView
class GetGroupResultView(ResultView):
def show_result(self, resp: requests.Response):
d = resp.json()
if 'description' in d:
desc = d['description'] + ' (' + d['cn'] + ')'
else:
desc = d['cn']
self._add_text('Members of ' + desc, center=True)
self._add_text()
for member in d['members']:
self._add_text(
member['cn'] + ' (' + member['uid'] + ')',
center=True)

@ -0,0 +1,31 @@
from asciimatics.widgets import Layout, Text
from ...utils import http_get
from ..CeoFrame import CeoFrame
class GetGroupView(CeoFrame):
def __init__(self, screen, width, height, model):
super().__init__(
screen, height, width, model, 'GetGroup',
save_data=True,
)
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
self._cn = Text("Group name", "cn")
layout.add_widget(self._cn)
self.add_flash_message_layout()
self.add_buttons(
back_btn=True,
next_scene='GetGroupResult', on_next=self._next)
self.fix()
def _next(self):
cn = self._cn.value
self._model.viewdata['GetGroup']['cn'] = cn
self.flash_message('Looking up group...', force_update=True)
try:
self._model.resp = http_get(f'/api/groups/{cn}')
finally:
self.clear_flash_message()

@ -12,6 +12,8 @@ from .ResultView import ResultView
from .TransactionView import TransactionView
from .WelcomeView import WelcomeView
from .groups.AddGroupView import AddGroupView
from .groups.GetGroupView import GetGroupView
from .groups.GetGroupResultView import GetGroupResultView
from .members.AddUserView import AddUserView
from .members.ChangeLoginShellView import ChangeLoginShellView
from .members.GetUserView import GetUserView
@ -57,6 +59,8 @@ def screen_wrapper(screen, last_scene, model):
('ChangeLoginShell', ChangeLoginShellView(screen, width, height, model)),
('SetForwardingAddresses', SetForwardingAddressesView(screen, width, height, model)),
('AddGroup', AddGroupView(screen, width, height, model)),
('GetGroup', GetGroupView(screen, width, height, model)),
('GetGroupResult', GetGroupResultView(screen, width, height, model)),
]
scenes = [
Scene([view], -1, name=name) for name, view in views

Loading…
Cancel
Save