Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.user_list.User_list Class Reference

List of all members.

Public Member Functions

def __init__
def reload
def add_user_in_model
def get_next_user_id
def on_edit_clicked
def on_add_item_clicked
def on_remove_item_clicked
def on_import_cvs_clicked
def user_changed_cb

Public Attributes

 cur
 con
 class_id
 user_data
 model
 button_edit
 button_remove

Private Member Functions

def __create_model
def __add_columns

Detailed Description

GCompris Users List Table

Definition at line 43 of file user_list.py.


Constructor & Destructor Documentation

def admin.user_list.User_list.__init__ (   self,
  container,
  db_connect,
  db_cursor 
)

Definition at line 51 of file user_list.py.

00051 
00052   def __init__(self, container, db_connect, db_cursor):
00053 
00054       self.cur = db_cursor
00055       self.con = db_connect
00056 
00057       # ---------------
00058       # User Management
00059       # ---------------
00060 
00061       # The class to work on
00062       self.class_id = 1
00063 
00064       self.user_data = []
00065 
00066       # create tree model
00067       self.model = self.__create_model()
00068 
00069       # First line
00070       group_hbox = gtk.HBox(False, 8)
00071       group_hbox.show()
00072       container.add(group_hbox)
00073 
00074       left_box = gtk.VBox(False, 8)
00075       left_box.show()
00076       group_hbox.add(left_box)
00077 
00078       right_box = gtk.VBox(False, 8)
00079       right_box.show()
00080       group_hbox.add(right_box)
00081 
00082       # Create the table
00083       sw = gtk.ScrolledWindow()
00084       sw.show()
00085       sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00086       sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00087 
00088 
00089       # create tree view
00090       treeview = gtk.TreeView(self.model)
00091       treeview.show()
00092       treeview.set_rules_hint(True)
00093       treeview.set_search_column(COLUMN_FIRSTNAME)
00094       treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
00095 
00096       sw.add(treeview)
00097 
00098       left_box.pack_start(sw, True, True, 0)
00099 
00100       # add columns to the tree view
00101       self.__add_columns(treeview)
00102 
00103       # Add buttons
00104       button = gtk.Button(stock='gtk-add')
00105       button.connect("clicked", self.on_add_item_clicked, self.model)
00106       right_box.pack_start(button, False, False, 0)
00107       button.show()
00108 
00109       self.button_edit = gtk.Button(stock='gtk-edit')
00110       self.button_edit.connect("clicked", self.on_edit_clicked, treeview)
00111       right_box.pack_start(self.button_edit, False, False, 0)
00112       self.button_edit.show()
00113       # Not editable until one class is selected
00114       self.button_edit.set_sensitive(False)
00115 
00116       button = gtk.Button(stock='gtk-open')
00117       button.connect("clicked", self.on_import_cvs_clicked, treeview)
00118       right_box.pack_start(button, False, False, 0)
00119       button.show()
00120 
00121       self.button_remove = gtk.Button(stock='gtk-remove')
00122       self.button_remove.connect("clicked", self.on_remove_item_clicked, treeview)
00123       right_box.pack_start(self.button_remove, False, False, 0)
00124       self.button_remove.show()
00125 
00126       # Missing callbacks
00127       selection = treeview.get_selection()
00128       selection.connect('changed', self.user_changed_cb, treeview)


Member Function Documentation

def admin.user_list.User_list.__add_columns (   self,
  treeview 
) [private]

Definition at line 177 of file user_list.py.

00177 
00178   def __add_columns(self, treeview):
00179 
00180     # Total column length must be 400
00181 
00182     model = treeview.get_model()
00183 
00184     # columns for login
00185     renderer = gtk.CellRendererText()
00186     renderer.set_data("column", COLUMN_LOGIN)
00187     column = gtk.TreeViewColumn(_('Login'), renderer,
00188                                 text=COLUMN_LOGIN)
00189     column.set_sort_column_id(COLUMN_LOGIN)
00190     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00191     column.set_fixed_width(constants.COLUMN_WIDTH_LOGIN)
00192     treeview.append_column(column)
00193 
00194     # columns for first name
00195     renderer = gtk.CellRendererText()
00196     renderer.set_data("column", COLUMN_FIRSTNAME)
00197     column = gtk.TreeViewColumn(_('First Name'), renderer,
00198                                 text=COLUMN_FIRSTNAME)
00199     column.set_sort_column_id(COLUMN_FIRSTNAME)
00200     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00201     column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
00202     treeview.append_column(column)
00203 
00204     # column for last name
00205     renderer = gtk.CellRendererText()
00206     renderer.set_data("column", COLUMN_LASTNAME)
00207     column = gtk.TreeViewColumn(_('Last Name'), renderer,
00208                                 text=COLUMN_LASTNAME)
00209     column.set_sort_column_id(COLUMN_LASTNAME)
00210     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00211     column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
00212     treeview.append_column(column)
00213 
00214     # column for birth date
00215     renderer = gtk.CellRendererText()
00216     renderer.set_data("column", COLUMN_BIRTHDATE)
00217     column = gtk.TreeViewColumn(_('Birth Date'), renderer,
00218                                 text=COLUMN_BIRTHDATE)
00219     column.set_sort_column_id(COLUMN_BIRTHDATE)
00220     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00221     column.set_fixed_width(constants.COLUMN_WIDTH_BIRTHDATE)
00222     treeview.append_column(column)
00223 

def admin.user_list.User_list.__create_model (   self) [private]

Definition at line 165 of file user_list.py.

00165 
00166   def __create_model(self):
00167     model = gtk.ListStore(
00168       gobject.TYPE_INT,
00169       gobject.TYPE_STRING,
00170       gobject.TYPE_STRING,
00171       gobject.TYPE_STRING,
00172       gobject.TYPE_STRING,
00173       gobject.TYPE_BOOLEAN)
00174 
00175     return model
00176 

def admin.user_list.User_list.add_user_in_model (   self,
  model,
  user 
)

Definition at line 153 of file user_list.py.

00153 
00154   def add_user_in_model(self, model, user):
00155     iter = model.append()
00156     model.set (iter,
00157                COLUMN_USERID,    user[COLUMN_USERID],
00158                COLUMN_LOGIN,     user[COLUMN_LOGIN],
00159                COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
00160                COLUMN_LASTNAME,  user[COLUMN_LASTNAME],
00161                COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE]
00162                )
00163 
00164 

Here is the caller graph for this function:

Definition at line 225 of file user_list.py.

00225 
00226   def get_next_user_id(self):
00227     self.cur.execute('select max(user_id) from users')
00228     user_id = self.cur.fetchone()[0]
00229     if(user_id == None):
00230       user_id=0
00231     else:
00232       user_id += 1
00233 
00234     return user_id
00235 

Here is the caller graph for this function:

def admin.user_list.User_list.on_add_item_clicked (   self,
  button,
  model 
)

Definition at line 259 of file user_list.py.

00259 
00260   def on_add_item_clicked(self, button, model):
00261     user_id = self.get_next_user_id()
00262 
00263     user_edit.UserEdit(self.con, self.cur,
00264                        user_id, "", "", "", "", self.class_id,
00265                        self)
00266 
00267 

Here is the call graph for this function:

def admin.user_list.User_list.on_edit_clicked (   self,
  button,
  treeview 
)

Definition at line 239 of file user_list.py.

00239 
00240   def on_edit_clicked(self, button, treeview):
00241     model = treeview.get_model()
00242     treestore, paths = treeview.get_selection().get_selected_rows()
00243     paths.reverse()
00244 
00245     for path in paths:
00246       iter = treestore.get_iter(path)
00247       path = model.get_path(iter)[0]
00248 
00249       user_id       = model.get_value(iter, COLUMN_USERID)
00250       login         = model.get_value(iter, COLUMN_LOGIN)
00251       firstname     = model.get_value(iter, COLUMN_FIRSTNAME)
00252       lastname      = model.get_value(iter, COLUMN_LASTNAME)
00253       birthdate     = model.get_value(iter, COLUMN_BIRTHDATE)
00254       user_edit.UserEdit(self.con, self.cur,
00255                          user_id, login, firstname, lastname, birthdate, self.class_id,
00256                          self)
00257 

def admin.user_list.User_list.on_import_cvs_clicked (   self,
  button,
  treeview 
)

Definition at line 285 of file user_list.py.

00285 
00286   def on_import_cvs_clicked(self, button, treeview):
00287 
00288     # Tell the user to select a class first
00289     dialog = gtk.MessageDialog(None,
00290                                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00291                                gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00292                                _("To import a user list from a file, first select a class.\nFILE FORMAT: Your file must be formatted like this:\nlogin;First name;Last name;Date of birth\nThe separator is autodetected and can be one of ',', ';' or ':'"))
00293     dialog.run()
00294     dialog.destroy()
00295 
00296     model = treeview.get_model()
00297 
00298     dialog = gtk.FileChooserDialog("Open..",
00299                                    None,
00300                                    gtk.FILE_CHOOSER_ACTION_OPEN,
00301                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
00302                                     gtk.STOCK_OPEN, gtk.RESPONSE_OK))
00303     dialog.set_default_response(gtk.RESPONSE_OK)
00304 
00305     filter = gtk.FileFilter()
00306     filter.set_name("All files")
00307     filter.add_pattern("*")
00308     dialog.add_filter(filter)
00309 
00310     response = dialog.run()
00311     if response == gtk.RESPONSE_OK:
00312       filename = dialog.get_filename()
00313     elif response == gtk.RESPONSE_CANCEL:
00314       dialog.destroy()
00315       return
00316 
00317     dialog.destroy()
00318 
00319     # Parse the file and include each line in the user table
00320     file = open(filename, 'r')
00321 
00322     # Determine the separator (the most used in the set ,;:)
00323     # Warning, the input file must use the same separator on each line and
00324     # between each fields
00325     line = file.readline()
00326     file.seek(0)
00327     sep=''
00328     count=0
00329     for asep in [',', ';', ':']:
00330       c = line.count(asep)
00331       if(c>count):
00332         count=c
00333         sep=asep
00334 
00335     self.cur.execute('SELECT login FROM users')
00336 
00337     passed_upper_login = [x[0].upper() for x in self.cur.fetchall()]
00338 
00339     rejected = []
00340 
00341     for line in file.readlines():
00342       print line
00343       line = line.rstrip("\n\r")
00344       user_id = self.get_next_user_id()
00345       login, firstname, lastname, birthdate = line.split(sep)
00346 
00347       #check uppercase are unique.
00348       up_login = login.decode('utf-8').upper()
00349       if up_login in passed_upper_login:
00350         rejected.append(login.encode('utf-8'))
00351         import time
00352         login = login + str(time.time())
00353       else:
00354         passed_upper_login.append(up_login)
00355 
00356       # Save the changes in the base
00357       new_user = [user_id, login, firstname, lastname, birthdate, self.class_id]
00358       self.add_user_in_model(model, new_user)
00359       self.cur.execute('INSERT OR REPLACE INTO users (user_id, login, firstname, lastname, birthdate, class_id) VALUES (?, ?, ?, ?, ?, ?)', new_user)
00360       self.con.commit()
00361 
00362     if len(rejected) != 0:
00363       p = ''
00364       for rej in rejected:
00365         p = p + ' ' + rej
00366 
00367       p.strip()
00368       dialog = gtk.MessageDialog(None,
00369                                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00370                                gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00371                                _("One or more logins are not unique !\nYou need to change them: %s !") % p)
00372       dialog.run()
00373       dialog.destroy()
00374 
00375     file.close()
00376 

Here is the call graph for this function:

def admin.user_list.User_list.on_remove_item_clicked (   self,
  button,
  treeview 
)

Definition at line 268 of file user_list.py.

00268 
00269   def on_remove_item_clicked(self, button, treeview):
00270     model = treeview.get_model()
00271     treestore, paths = treeview.get_selection().get_selected_rows()
00272     paths.reverse()
00273 
00274     for path in paths:
00275       iter = treestore.get_iter(path)
00276       path = model.get_path(iter)[0]
00277 
00278       user_id = model.get_value(iter, COLUMN_USERID)
00279       model.remove(iter)
00280       # Remove it from the base
00281       print "Deleting user_id=" + str(user_id)
00282       self.cur.execute('delete from users where user_id=?', (user_id,))
00283       self.con.commit()
00284 

def admin.user_list.User_list.reload (   self,
  class_id 
)

Definition at line 134 of file user_list.py.

00134 
00135   def reload(self, class_id):
00136     print "user_list reload %d" %class_id
00137     self.class_id = class_id
00138 
00139     # Remove all entries in the list
00140     self.model.clear()
00141 
00142     self.button_edit.set_sensitive(False)
00143     self.button_remove.set_sensitive(False)
00144 
00145     # Grab the user data
00146     self.cur.execute('select user_id,login,firstname,lastname,birthdate from users where class_id=? order by login',
00147                      (class_id,))
00148     self.user_data = self.cur.fetchall()
00149 
00150     for user in self.user_data:
00151       self.add_user_in_model(self.model, user)

Here is the call graph for this function:

def admin.user_list.User_list.user_changed_cb (   self,
  selection,
  treeview 
)

Definition at line 378 of file user_list.py.

00378 
00379   def user_changed_cb(self, selection, treeview):
00380     self.button_edit.set_sensitive(True)
00381     self.button_remove.set_sensitive(True)
00382 

Member Data Documentation

Definition at line 108 of file user_list.py.

Definition at line 120 of file user_list.py.

Definition at line 61 of file user_list.py.

Definition at line 54 of file user_list.py.

Definition at line 53 of file user_list.py.

Definition at line 66 of file user_list.py.

Definition at line 63 of file user_list.py.


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