Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
admin.user_edit.UserEdit Class Reference

List of all members.

Public Member Functions

def __init__
def close
def ok

Public Attributes

 cur
 con
 user_id
 class_id
 list_user
 new_user
 old_login
 entry_login
 entry_firstname
 entry_lastname
 entry_birthdate

Detailed Description

Definition at line 32 of file user_edit.py.


Constructor & Destructor Documentation

def admin.user_edit.UserEdit.__init__ (   self,
  db_connect,
  db_cursor,
  user_id,
  login,
  firstname,
  lastname,
  birthdate,
  class_id,
  list_user 
)

Definition at line 36 of file user_edit.py.

00036 
00037                  list_user):
00038         # Create the toplevel window
00039         gtk.Window.__init__(self)
00040 
00041         self.cur = db_cursor
00042         self.con = db_connect
00043 
00044         self.user_id  = user_id
00045         self.class_id = class_id
00046         
00047         # A pointer to the user_list class
00048         # Will be called to refresh the list when edit is done
00049         self.list_user = list_user
00050         
00051         self.set_title(_("Editing a User"))
00052         self.set_border_width(8)
00053         self.set_default_size(320, 250)
00054 
00055         if(firstname and lastname):
00056             frame = gtk.Frame(_("Editing a User ") +
00057                               lastname + " " +
00058                               firstname)
00059             self.new_user = False
00060             self.old_login = login
00061         else:
00062             frame = gtk.Frame(_("Editing a new user"))
00063             self.new_user = True
00064 
00065         self.add(frame)
00066 
00067         # Main VBOX
00068         vbox = gtk.VBox(False, 8)
00069         vbox.set_border_width(8)
00070         frame.add(vbox)
00071 
00072         # Label and Entry for the user name
00073         table = gtk.Table(2, 5, homogeneous=False)
00074         table.set_border_width(0)
00075         table.set_row_spacings(0)
00076         table.set_col_spacings(20)
00077         vbox.pack_start(table, True, True, 0)
00078         
00079         label = gtk.Label(_('Login:'))
00080         label.set_alignment(0, 0)
00081         table.attach(label, 0, 1, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00082         self.entry_login = gtk.Entry()
00083         self.entry_login.set_max_length(20)
00084         self.entry_login.insert_text(login, position=0)
00085         table.attach(self.entry_login, 1, 2, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00086 
00087         # FIXME: How to remove the selection
00088         
00089         # Label and Entry for the first name
00090         label = gtk.Label(_('First name:'))
00091         label.set_alignment(0, 0)
00092         table.attach(label, 0, 1, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00093         self.entry_firstname = gtk.Entry()
00094         self.entry_firstname.set_max_length(30)
00095         self.entry_firstname.insert_text(firstname, position=0)
00096         table.attach(self.entry_firstname, 1, 2, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00097 
00098         # Label and Entry for the last name
00099         label = gtk.Label(_('Last name:'))
00100         label.set_alignment(0, 0)
00101         table.attach(label, 0, 1, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00102         self.entry_lastname = gtk.Entry()
00103         self.entry_lastname.set_max_length(30)
00104         self.entry_lastname.insert_text(lastname, position=0)
00105         table.attach(self.entry_lastname, 1, 2, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00106 
00107         # Label and Entry for the birth date
00108         label = gtk.Label(_('Birth date:'))
00109         label.set_alignment(0, 0)
00110         table.attach(label, 0, 1, 3, 4, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00111         self.entry_birthdate = gtk.Entry()
00112         self.entry_birthdate.set_max_length(30)
00113         self.entry_birthdate.insert_text(birthdate, position=0)
00114         table.attach(self.entry_birthdate, 1, 2, 3, 4, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00115 
00116         # Confirmation Buttons
00117         # --------------------
00118         vbox.pack_start(gtk.HSeparator(), False, False, 0)
00119 
00120         bbox = gtk.HBox(homogeneous=False, spacing=8)
00121         
00122         button = gtk.Button(stock='gtk-help')
00123         bbox.pack_start(button, expand=False, fill=False, padding=0)
00124 
00125         button = gtk.Button(stock='gtk-ok')
00126         bbox.pack_end(button, expand=False, fill=False, padding=0)
00127         button.connect("clicked", self.ok)
00128 
00129         button = gtk.Button(stock='gtk-close')
00130         bbox.pack_end(button, expand=False, fill=False, padding=0)
00131         button.connect("clicked", self.close)
00132 
00133         vbox.pack_start(bbox, False, False, 0)
00134         
00135         # Ready GO
00136         self.show_all()
00137 


Member Function Documentation

def admin.user_edit.UserEdit.close (   self,
  button 
)

Definition at line 145 of file user_edit.py.

00145 
00146     def close(self, button):
00147         self.destroy()
        

Here is the call graph for this function:

def admin.user_edit.UserEdit.ok (   self,
  button 
)

Definition at line 150 of file user_edit.py.

00150 
00151     def ok(self, button):
00152 
00153         # Tell the user he must provide enough information
00154         if(self.entry_login.get_text() == "" or
00155            self.entry_firstname.get_text() == "" or
00156            self.entry_lastname.get_text() == ""):
00157             dialog = gtk.MessageDialog(None,
00158                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00159                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00160                                        _("You need to provide at least a login, first name and last name for your users"))
00161             dialog.run()
00162             dialog.destroy()
00163             return
00164 
00165         if(self.new_user):
00166             # Check the login do not exist already
00167             self.cur.execute('SELECT login FROM users')
00168         else:
00169             self.cur.execute('SELECT login FROM users WHERE login != \'%s\'' % self.old_login)
00170         logins = [x[0].upper() for x in self.cur.fetchall()]
00171         login = self.entry_login.get_text().decode('utf-8').upper()
00172 
00173         if login in logins:
00174             dialog = gtk.MessageDialog(None,
00175                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00176                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00177                                        _("There is already a user with this login"))
00178             dialog.run()
00179             dialog.destroy()
00180             return
00181 
00182         #
00183         # Now everything is correct, create the user
00184         #
00185         user_data = (self.user_id,
00186                      self.entry_login.get_text(),
00187                      self.entry_firstname.get_text(),
00188                      self.entry_lastname.get_text(),
00189                      self.entry_birthdate.get_text(),
00190                      self.class_id
00191                      )
00192         # Save the changes in the base
00193         self.cur.execute('insert or replace into users (user_id, login, firstname, lastname, birthdate, class_id) values (?, ?, ?, ?, ?, ?)', user_data)
00194         self.con.commit()
00195 
00196         # Close the dialog window now
00197         print "user_edit calling reload"
00198         self.list_user.reload(self.class_id)
00199 
00200         self.destroy()
00201         

Here is the call graph for this function:


Member Data Documentation

Definition at line 44 of file user_edit.py.

Definition at line 41 of file user_edit.py.

Definition at line 40 of file user_edit.py.

Definition at line 110 of file user_edit.py.

Definition at line 92 of file user_edit.py.

Definition at line 101 of file user_edit.py.

Definition at line 81 of file user_edit.py.

Definition at line 48 of file user_edit.py.

Definition at line 58 of file user_edit.py.

Definition at line 59 of file user_edit.py.

Definition at line 43 of file user_edit.py.


The documentation for this class was generated from the following file: