Remind users that club accounts are free.
[public/pyceo-broken.git] / ceo / urwid / main.py
index b923a9f..53d3ba2 100644 (file)
@@ -1,18 +1,8 @@
-import random, ldap, urwid.curses_display
-from ceo import members
+import os, grp, pwd, sys, random, urwid.curses_display
 from ceo.urwid.widgets import *
 from ceo.urwid.window import *
-from ceo.urwid import newmember, renew, info, search, positions, groups
-
-ui = urwid.curses_display.Screen()
-
-ui.register_palette([
-    # name, foreground, background, mono
-    ('banner', 'light gray', 'default', None),
-    ('menu', 'light gray', 'default', 'bold'),
-    ('selected', 'black', 'light gray', 'bold'),
-])
-
+from ceo.urwid import newmember, renew, info, search, positions, groups, \
+    shell, library, databases
 
 def program_name():
     cwords = [ "CSC" ] * 20 + [ "Club" ] * 10 + [ "Campus" ] * 5 + \
@@ -40,46 +30,15 @@ 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, data, txt ), 'menu', 'selected') for (txt, cb, data) in items ]
-
-def main_menu():
-    menu = [
-        ("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),
-        ("Manage Systems Committee", groups.group_members, syscom_data),
-        ("Exit", raise_abort, None),
-    ]
-
-    listbox = urwid.ListBox( menu_items( menu ) )
-    return listbox
-
 def new_member(*args, **kwargs):
     push_wizard("New Member", [
         newmember.IntroPage,
         newmember.InfoPage,
+        newmember.NumberOfTermsPage,
         newmember.SignPage,
         newmember.PassPage,
         newmember.EndPage,
-    ])
+    ], (60, 15))
 
 def new_club(*args, **kwargs):
     push_wizard("New Club Account", [
@@ -88,6 +47,17 @@ def new_club(*args, **kwargs):
         (newmember.EndPage, "club"),
     ], (60, 15))
 
+def new_club_user(*args, **kwargs):
+    push_wizard("New Club Rep Account", [
+        newmember.ClubUserIntroPage,
+        newmember.ClubNoPayPage,
+        newmember.InfoPage,
+        newmember.NumberOfTermsPage,
+        newmember.SignPage,
+        newmember.PassPage,
+        (newmember.EndPage, "clubuser"),
+    ], (60, 15))
+
 def manage_group(*args, **kwargs):
     push_wizard("Manage Club or Group Members", [
         groups.IntroPage,
@@ -98,10 +68,23 @@ def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
         renew.IntroPage,
         renew.UserPage,
+        renew.EmailPage,
+        renew.EmailDonePage,
         renew.TermPage,
         renew.PayPage,
         renew.EndPage,
-    ])
+    ], (60, 15))
+
+def renew_club_user(*args, **kwargs):
+    push_wizard("Renew Club Rep Account", [
+        renew.ClubUserIntroPage,
+        newmember.ClubNoPayPage,
+        renew.UserPage,
+        renew.EmailPage,
+        renew.EmailDonePage,
+        (renew.TermPage, "clubuser"),
+        (renew.EndPage, "clubuser"),
+    ], (60, 15))
 
 def display_member(data):
     push_wizard("Display Member", [
@@ -110,15 +93,13 @@ def display_member(data):
     ], (60, 15))
 
 def search_members(data):
-    menu = [
+    menu = make_menu([
         ("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")
+    ])
+    push_window(menu, "Search Members")
 
 def search_name(data):
     push_wizard("By Name", [ search.NamePage ])
@@ -136,18 +117,76 @@ def manage_positions(data):
         positions.EndPage,
     ], (50, 15))
 
-def run():
-    members.connect()
+def change_shell(data):
+    push_wizard("Change Shell", [
+        shell.IntroPage,
+        shell.YouPage,
+        shell.ShellPage,
+        shell.EndPage
+    ], (50, 20))
+
+def create_mysql_db(data):
+    push_wizard("Create MySQL database", [
+        databases.IntroPage,
+        databases.UserPage,
+        databases.EndPage,
+    ], (60, 15))
 
-    push_window( main_menu(), program_name() )
-    event_loop( ui )
+def check_group(group):
+    try:
+        me = pwd.getpwuid(os.getuid()).pw_name
+        return me in grp.getgrnam(group).gr_mem
+    except KeyError:
+        pass
+
+def top_menu():
+    office_only = [
+        ("New Member", new_member, None),
+        ("New Club Rep", new_club_user, None),
+        ("Renew Membership", renew_member, None),
+        ("Renew Club Rep", renew_club_user, None),
+        ("New Club", new_club, None),
+        ("Library", library.library, None),
+    ]
+    syscom_only = [
+        ("Manage Club or Group Members", manage_group, None),
+        ("Manage Positions", manage_positions, None),
+    ]
+    unrestricted = [
+        ("Display Member", display_member, None),
+        ("Search Members", search_members, None),
+        ("Change Shell", change_shell, None),
+        ("Create MySQL database", create_mysql_db, None),
+    ]
+    footer = [
+        ("Exit", raise_abort, None),
+    ]
+    menu = None
+
+    # reorder the menu for convenience
+    if not check_group('office') and not check_group('syscom'):
+        menu = labelled_menu([
+            ('Unrestricted', unrestricted),
+            ('Office Staff', office_only),
+            ('Systems Committee', syscom_only),
+            (None, footer)
+        ])
+    else:
+        menu = labelled_menu([
+            ('Office Staff', office_only),
+            ('Unrestricted', unrestricted),
+            ('Systems Committee', syscom_only),
+            (None, footer)
+        ])
+
+    return menu
+
+def run():
+    push_window(top_menu(), program_name())
+    event_loop(ui)
 
 def start():
-    try:
-        ui.run_wrapper( run )
-    except ldap.LOCAL_ERROR, e:
-        print e[0]['info']
-        print "Hint: You may need to run 'kinit'"
+    ui.run_wrapper( run )
 
 if __name__ == '__main__':
     start()