Silence pychecker and pylint warnings
[public/pyceo-broken.git] / pylib / csc / apps / urwid / main.py
index fef149c..43f7ca7 100644 (file)
@@ -1,5 +1,5 @@
-import random, time
-import urwid, urwid.curses_display
+import random
+import urwid.curses_display
 
 from csc.apps.urwid.widgets import *
 from csc.apps.urwid.window import *
@@ -7,6 +7,8 @@ import csc.apps.urwid.newmember as newmember
 import csc.apps.urwid.renew as renew
 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.adm import accounts, members, terms
 from csc.common.excep import InvalidArgument
@@ -31,10 +33,10 @@ def program_name():
         "Embryonic", "Emigrant", "Emissary's", "Emoting", "Employment", "Emulated",
         "Enabling", "Enamoring", "Encapsulated", "Enchanted", "Encoded", "Encrypted",
         "Encumbered", "Endemic", "Enhanced", "Enigmatic", "Enlightened", "Enormous",
-        "Enrollment", "Enshrouded", "Ephermal", "Epidemic", "Episodic", "Epsilon",
+        "Enrollment", "Enshrouded", "Ephemeral", "Epidemic", "Episodic", "Epsilon",
         "Equitable", "Equestrian", "Equilateral", "Erroneous", "Erratic",
         "Espresso", "Essential", "Estate", "Esteemed", "Eternal", "Ethical", "Eucalyptus",
-        "Euphemistic", "Envangelist", "Evasive", "Everyday", "Evidence", "Eviction", "Evildoer's",
+        "Euphemistic", "Evangelist", "Evasive", "Everyday", "Evidence", "Eviction", "Evildoer's",
         "Evolution", "Exacerbation", "Exalted", "Examiner's", "Excise", "Exciting", "Exclusion",
         "Exec", "Executioner's", "Exile", "Existential", "Expedient", "Expert", "Expletive",
         "Exploiter's", "Explosive", "Exponential", "Exposing", "Extortion", "Extraction",
@@ -47,33 +49,40 @@ def program_name():
 
     return "%s %s %s" % (cword, eword, oword)
 
+office_data = {
+    "name" : "Office Staff",
+    "group" : "office",
+    "groups" : [ "office", "cdrom", "audio", "video", "www" ],
+}
+
+syscom_data = {
+    "name" : "Systems Committee",
+    "group" : "syscom",
+    "groups" : [ "office", "staff", "adm", "src" ],
+}
+
 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 Club or Group Members", manage_group, None),
+        ("Manage Positions", manage_positions, None),
+        ("Manage Office Staff", groups.group_members,
+            (office_data, ui.uid)),
+        ("Manage Systems Committee", groups.group_members,
+            (syscom_data, ui.uid)),
+        ("Exit", raise_abort, None),
     ]
 
     listbox = urwid.ListBox( menu_items( menu ) )
     return listbox
 
-def push_wizard(name, pages, dimensions=(50, 10)):
-    state = {}
-    wiz = Wizard()
-    for page in pages:
-        if type(page) != tuple:
-            page = (page, )
-        wiz.add_panel( page[0](state, *page[1:]) )
-    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,
@@ -88,7 +97,13 @@ def new_club(*args, **kwargs):
         newmember.ClubIntroPage,
         newmember.ClubInfoPage,
         (newmember.EndPage, "club"),
-    ], (60,15))
+    ], (60, 15))
+
+def manage_group(*args, **kwargs):
+    push_wizard("Manage Club or Group Members", [
+        groups.IntroPage,
+        (groups.InfoPage, ui.uid),
+    ], (60, 15))
 
 def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
@@ -99,34 +114,51 @@ 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),
+        ("Members by group", search_group, 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 search_group(data):
+    push_wizard("By Group", [ search.GroupPage ])
+
+def manage_positions(data):
+    push_wizard("Manage Positions", [
+        positions.IntroPage,
+        positions.InfoPage,
+        positions.EndPage,
+    ], (50, 15))
+
 def run():
+    members.connect()
+    accounts.connect()
+
     push_window( main_menu(), program_name() )
     event_loop( ui )
 
-def start():
+def start(uid, gid):
+    ui.uid = uid
+    ui.gid = gid
     ui.run_wrapper( run )
 
 if __name__ == '__main__':
-    start()
+    import os
+    start(os.getuid(), os.getgid())