Add group/club management
authorDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Wed, 28 Nov 2007 00:27:03 +0000 (19:27 -0500)
committerDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Wed, 28 Nov 2007 00:29:06 +0000 (19:29 -0500)
pylib/csc/apps/urwid/groups.py
pylib/csc/apps/urwid/main.py

index 80ee9df..4641083 100644 (file)
@@ -1,10 +1,77 @@
 import urwid
 from csc.apps.urwid.widgets import *
 from csc.apps.urwid.window import *
+import csc.apps.urwid.search as search
 
 from csc.adm import accounts, members
 from csc.common.excep import InvalidArgument
 
+def menu_items(items):
+    return [ urwid.AttrWrap( ButtonText( cb, data, txt ), 'menu', 'selected') for (txt, cb, data) in items ]
+
+def change_group_member(data):
+    push_wizard("%s %s Member" % (data["type"], data["name"]), [
+        (groups.ChangeMember, data),
+        groups.EndPage,
+    ])
+
+def list_group_members(data):
+    mlist = members.list_group( data["group"] ).values()
+    search.member_list( mlist )
+
+def group_members(data):
+    add_data = data.copy()
+    add_data['type'] = 'Add'
+    remove_data = data.copy()
+    remove_data['type'] = 'Remove'
+    menu = [
+        ("Add %s member" % data["name"].lower(),
+            change_group_member, add_data),
+        ("Remove %s member" % data["name"].lower(),
+            change_group_member, remove_data),
+        ("List %s members" % data["name"].lower(), list_group_members, data),
+        ("Back", raise_back, None),
+    ]
+
+    listbox = urwid.ListBox( menu_items( menu ) )
+    push_window(listbox, "Manage %s" % data["name"])
+
+class IntroPage(WizardPanel):
+    def init_widgets(self):
+        self.widgets = [
+            urwid.Text( "Managing Club or Group" ),
+            urwid.Divider(),
+            urwid.Text( "Adding a member to a club will also grant them "
+                        "access to the club's files and allow them to "
+                        "become_club."
+                        "\n\n"
+                        "Do not manage office and syscom related groups using "
+                        "this interface. Instead use the \"Manage Office "
+                        "Staff\" and \"Manage Systems Committee\" entries "
+                        "from the main menu." )
+        ]
+    def focusable(self):
+        return False
+
+class InfoPage(WizardPanel):
+    def init_widgets(self):
+        self.group = WordEdit("Club or Group: ")
+        self.widgets = [
+            urwid.Text( "Club or Group Information"),
+            urwid.Divider(),
+            self.group,
+        ]
+    def check(self):
+        group = self.group.get_edit_text()
+        # TODO - check that group is valid
+        group_name = group # TODO
+        data = {
+            "name" : group,
+            "group" : group_name,
+            "groups" : [group],
+        }
+        group_members(data)
+
 class ChangeMember(WizardPanel):
     def __init__(self, state, data):
         state['data'] = data
index 8ea09aa..e061cc2 100644 (file)
@@ -9,6 +9,7 @@ import csc.apps.urwid.info as info
 import csc.apps.urwid.search as search
 import csc.apps.urwid.positions as positions
 import csc.apps.urwid.groups as groups
+from csc.apps.urwid.error import *
 
 from csc.adm import accounts, members, terms
 from csc.common.excep import InvalidArgument
@@ -71,6 +72,7 @@ def main_menu():
         ("Create Club Account", new_club, None),
         ("Display Member", display_member, None),
         ("Search", search_members, None),
+        ("Manage Club or Group Members", manage_group, None),
         ("Manage Positions", manage_positions, None),
         ("Manage Office Staff", group_members, office_data),
         ("Manage Systems Committee", group_members, syscom_data),
@@ -107,6 +109,12 @@ def new_club(*args, **kwargs):
         (newmember.EndPage, "club"),
     ], (60, 15))
 
+def manage_group(*args, **kwargs):
+    push_wizard("Manage Club or Group Members", [
+        groups.IntroPage,
+        groups.InfoPage,
+    ], (60, 15))
+
 def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
         renew.IntroPage,
@@ -156,27 +164,17 @@ def group_members(data):
     remove_data['type'] = 'Remove'
     menu = [
         ("Add %s member" % data["name"].lower(),
-            change_group_member, add_data),
+            groups.change_group_member, add_data),
         ("Remove %s member" % data["name"].lower(),
-            change_group_member, remove_data),
-        ("List %s members" % data["name"].lower(), list_group_members, data),
+            groups.change_group_member, remove_data),
+        ("List %s members" % data["name"].lower(),
+            groups.list_group_members, data),
         ("Back", raise_back, None),
     ]
 
     listbox = urwid.ListBox( menu_items( menu ) )
     push_window(listbox, "Manage %s" % data["name"])
 
-def change_group_member(data):
-    push_wizard("%s %s Member" % (data["type"], data["name"]), [
-        (groups.ChangeMember, data),
-        groups.EndPage,
-    ])
-
-def list_group_members(data):
-    if not members.connected(): members.connect()
-    mlist = members.list_group( data["group"] ).values()
-    search.member_list( mlist )
-
 def run():
     push_window( main_menu(), program_name() )
     event_loop( ui )