Add preliminary group management functions
authorDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Wed, 14 Nov 2007 00:30:01 +0000 (19:30 -0500)
committerDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Wed, 14 Nov 2007 00:30:01 +0000 (19:30 -0500)
pylib/csc/adm/members.py
pylib/csc/apps/urwid/main.py
pylib/csc/apps/urwid/widgets.py

index 2dda57f..83152ca 100644 (file)
@@ -299,6 +299,17 @@ def member_terms(userid):
     else:
         return member['term']
 
+def group_members(group):
+
+    """
+    Returns a list of group members
+    """
+
+    group = ldap_connection.group_lookup(group)
+    if not 'uniqueMember' in group:
+        return []
+    else:
+        return group['uniqueMember']
 
 
 ### Tests ###
index fef149c..dccfdd4 100644 (file)
@@ -1,4 +1,4 @@
-import random, time
+import random, time, re
 import urwid, urwid.curses_display
 
 from csc.apps.urwid.widgets import *
@@ -47,17 +47,29 @@ def program_name():
 
     return "%s %s %s" % (cword, eword, oword)
 
+office_data = {
+    "name" : "Office Staff",
+    "group" : "office"
+}
+
+syscom_data = {
+    "name" : "Systems Committee",
+    "group" : "syscom"
+}
+
 def menu_items(items):
-    return [ urwid.AttrWrap( ButtonText( cb, txt ), 'menu', 'selected') for (txt, cb) in items ]
+    return [ urwid.AttrWrap( ButtonText( cb, data, txt ), 'menu', 'selected') for (txt, cb, data) in items ]
 
 def main_menu():
     menu = [
-        ("New Member", new_member),
-        ("Renew Membership", renew_member),
-        ("Create Club Account", new_club),
-        ("Display Member", display_member),
-        ("Search", search_members),
-        ("Exit", raise_abort),
+        ("New Member", new_member, None),
+        ("Renew Membership", renew_member, None),
+        ("Create Club Account", new_club, None),
+        ("Display Member", display_member, None),
+        ("Search", search_members, None),
+        ("Manage Office Staff", group_members, office_data),
+        ("Manage Systems Committee", group_members, syscom_data),
+        ("Exit", raise_abort, None),
     ]
 
     listbox = urwid.ListBox( menu_items( menu ) )
@@ -73,7 +85,7 @@ def push_wizard(name, pages, dimensions=(50, 10)):
     push_window( urwid.Filler( urwid.Padding(
         urwid.LineBox(wiz), 'center', dimensions[0]),
         'middle', dimensions[1] ), name )
-    
+
 def new_member(*args, **kwargs):
     push_wizard("New Member", [
         newmember.IntroPage,
@@ -99,28 +111,58 @@ def renew_member(*args, **kwargs):
         renew.EndPage,
     ])
 
-def display_member(a):
+def display_member(data):
     push_wizard("Display Member", [
         renew.UserPage,
         info.InfoPage,
     ], (60, 15))
 
-def search_members(a):
+def search_members(data):
     menu = [
-        ("Members by term", search_term),
-        ("Members by name", search_name),
-        ("Back", raise_back),
+        ("Members by term", search_term, None),
+        ("Members by name", search_name, None),
+        ("Back", raise_back, None),
     ]
 
     listbox = urwid.ListBox( menu_items( menu ) )
     push_window(listbox, "Search")
 
-def search_name(a):
+def search_name(data):
     push_wizard("By Name", [ search.NamePage ])
 
-def search_term(a):
+def search_term(data):
     push_wizard("By Term", [ search.TermPage ])
 
+def group_members(data):
+    menu = [
+        ("Add %s member" % data["name"].lower(), add_group_member, data),
+        ("Remove %s member" % data["name"].lower(), remove_group_member, 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"])
+
+def add_group_member(data):
+    pass
+
+def remove_group_member(data):
+    pass
+
+def list_group_members(data):
+
+    if not members.connected(): members.connect()
+    group_members = members.group_members(data["group"])
+    r = re.compile('^uid=([^,]*)')
+    menu = []
+    for group in group_members:
+        menu.append( (r.match(group).group(1), None, None) )
+    menu.append( ("Back", raise_back, None) )
+
+    listbox = urwid.ListBox( menu_items( menu ) )
+    push_window(listbox, "Members")
+
 def run():
     push_window( main_menu(), program_name() )
     event_loop( ui )
index 5fe8214..a0f440b 100644 (file)
@@ -2,14 +2,15 @@ import urwid
 from csc.apps.urwid.ldapfilter import *
 
 class ButtonText(urwid.Text):
-    def __init__(self, callback, *args, **kwargs):
+    def __init__(self, callback, data, *args, **kwargs):
         self.callback = callback
+        self.data = data
         urwid.Text.__init__(self, *args, **kwargs)
     def selectable(self):
         return True
     def keypress(self, size, key):
-        if key == 'enter':
-            self.callback(self.get_text())
+        if key == 'enter' and self.callback:
+            self.callback(self.data)
         else:
             return key
 
@@ -58,7 +59,7 @@ class Wizard(urwid.WidgetWrap):
         self.panels.append( panel )
         if len(self.panels) == 1:
             self.select(0)
-    
+
     def select(self, panelno, set_focus=True):
         if 0 <= panelno < len(self.panels):
             self.selected = panelno
@@ -70,13 +71,13 @@ class Wizard(urwid.WidgetWrap):
                     self.pile.set_focus( 0 )
                 else:
                     self.pile.set_focus( 1 )
-    
+
     def next(self, *args, **kwargs):
         if self.panels[self.selected].check():
             self.select( self.selected )
             return
         self.select(self.selected + 1)
-    
+
     def back(self, *args, **kwargs):
         self.select(self.selected - 1, False)