~ml-launchpad/ubuntu/natty/gcompris/fix-for-777349

« back to all changes in this revision

Viewing changes to src/boards/python/admin/group_user_list.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#  gcompris - group_user_list.py
2
 
#
3
 
# Copyright (C) 2005 Bruno Coudoin and Yves Combe
4
 
#
5
 
#   This program is free software; you can redistribute it and/or modify
6
 
#   it under the terms of the GNU General Public License as published by
7
 
#   the Free Software Foundation; either version 3 of the License, or
8
 
#   (at your option) any later version.
9
 
#
10
 
#   This program is distributed in the hope that it will be useful,
11
 
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
#   GNU General Public License for more details.
14
 
#
15
 
#   You should have received a copy of the GNU General Public License
16
 
#   along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 
#
18
 
 
19
 
import gnomecanvas
20
 
import gcompris
21
 
import gcompris.utils
22
 
import gcompris.skin
23
 
import gtk
24
 
import gtk.gdk
25
 
import gobject
26
 
from gcompris import gcompris_gettext as _
27
 
 
28
 
import constants
29
 
 
30
 
# Database
31
 
try:
32
 
  import sqlite3 as sqlite
33
 
except ImportError:
34
 
  try:
35
 
    from pysqlite2 import dbapi2 as sqlite
36
 
  except ImportError:
37
 
    raise ImportError, "no module named sqlite3 or pysqlite2.dbapi2"
38
 
 
39
 
#import group_edit
40
 
 
41
 
# User Management
42
 
(
43
 
  COLUMN_USERID,
44
 
  COLUMN_LOGIN,
45
 
  COLUMN_FIRSTNAME,
46
 
  COLUMN_LASTNAME,
47
 
  COLUMN_BIRTHDATE,
48
 
) = range(5)
49
 
 
50
 
 
51
 
class Group_user_list:
52
 
  """GCompris Group User List Table"""
53
 
 
54
 
 
55
 
  # The created list will be packed in the given container
56
 
  #
57
 
  def __init__(self, container, db_connect, db_cursor, group_id):
58
 
 
59
 
      self.cur = db_cursor
60
 
      self.con = db_connect
61
 
 
62
 
      # The group_id to work on
63
 
      self.group_id = group_id
64
 
 
65
 
      # ---------------
66
 
      # User Group Management
67
 
      # ---------------
68
 
 
69
 
      # create tree model
70
 
      self.model = self.__create_model()
71
 
 
72
 
      self.reload(self.group_id)
73
 
 
74
 
      # Create the table
75
 
      sw = gtk.ScrolledWindow()
76
 
      sw.show()
77
 
      sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
78
 
      sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
79
 
 
80
 
      # create tree view
81
 
      treeview_group = gtk.TreeView(self.model)
82
 
      treeview_group.show()
83
 
      treeview_group.set_rules_hint(True)
84
 
      treeview_group.set_search_column(COLUMN_FIRSTNAME)
85
 
      treeview_group.get_selection().set_mode(gtk.SELECTION_NONE)
86
 
 
87
 
      sw.add(treeview_group)
88
 
 
89
 
      # add columns to the tree view
90
 
      self.__add_columns(treeview_group)
91
 
 
92
 
      container.pack_start(sw)
93
 
 
94
 
 
95
 
  # -------------------
96
 
  # User Management
97
 
  # -------------------
98
 
 
99
 
  # clear all data in the list
100
 
  def clear(self):
101
 
      self.model.clear()
102
 
 
103
 
  # Retrieve data from the database for the given group_id
104
 
  def reload(self, group_id):
105
 
      self.group_id = group_id
106
 
 
107
 
      # Remove all entries in the list
108
 
      self.model.clear()
109
 
 
110
 
      self.cur.execute('SELECT DISTINCT users.user_id,login,firstname,lastname,birthdate FROM users,list_users_in_groups WHERE list_users_in_groups.group_id=? AND list_users_in_groups.user_id=users.user_id ORDER BY login', (self.group_id,));
111
 
      users = self.cur.fetchall()
112
 
      for user in users:
113
 
        self.add_user_in_model(self.model, user)
114
 
 
115
 
 
116
 
  # Add user in the model
117
 
  def add_user_in_model(self, model, user):
118
 
    iter = model.append()
119
 
    model.set (iter,
120
 
               COLUMN_USERID,    user[COLUMN_USERID],
121
 
               COLUMN_LOGIN,     user[COLUMN_LOGIN],
122
 
               COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
123
 
               COLUMN_LASTNAME,  user[COLUMN_LASTNAME],
124
 
               COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE]
125
 
               )
126
 
 
127
 
 
128
 
 
129
 
  def __create_model(self):
130
 
    model = gtk.ListStore(
131
 
      gobject.TYPE_INT,
132
 
      gobject.TYPE_STRING,
133
 
      gobject.TYPE_STRING,
134
 
      gobject.TYPE_STRING,
135
 
      gobject.TYPE_STRING)
136
 
 
137
 
    return model
138
 
 
139
 
 
140
 
  def __add_columns(self, treeview):
141
 
 
142
 
    model = treeview.get_model()
143
 
 
144
 
    # Total column lengh must be 400
145
 
 
146
 
    # columns for login
147
 
    renderer = gtk.CellRendererText()
148
 
    renderer.set_data("column", COLUMN_LOGIN)
149
 
    column = gtk.TreeViewColumn(_('Login'), renderer,
150
 
                                text=COLUMN_LOGIN)
151
 
    column.set_sort_column_id(COLUMN_LOGIN)
152
 
    column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
153
 
    column.set_fixed_width(constants.COLUMN_WIDTH_LOGIN)
154
 
    treeview.append_column(column)
155
 
 
156
 
    # columns for first name
157
 
    renderer = gtk.CellRendererText()
158
 
    renderer.set_data("column", COLUMN_FIRSTNAME)
159
 
    column = gtk.TreeViewColumn(_('First Name'), renderer,
160
 
                                text=COLUMN_FIRSTNAME)
161
 
    column.set_sort_column_id(COLUMN_FIRSTNAME)
162
 
    column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
163
 
    column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
164
 
    treeview.append_column(column)
165
 
 
166
 
    # column for last name
167
 
    renderer = gtk.CellRendererText()
168
 
    renderer.set_data("column", COLUMN_LASTNAME)
169
 
    column = gtk.TreeViewColumn(_('Last Name'), renderer,
170
 
                                text=COLUMN_LASTNAME)
171
 
    column.set_sort_column_id(COLUMN_LASTNAME)
172
 
    column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
173
 
    column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
174
 
    treeview.append_column(column)
175
 
 
176
 
    # column for birth date
177
 
    renderer = gtk.CellRendererText()
178
 
    renderer.set_data("column", COLUMN_BIRTHDATE)
179
 
    column = gtk.TreeViewColumn(_('Birth Date'), renderer,
180
 
                                text=COLUMN_BIRTHDATE)
181
 
    column.set_sort_column_id(COLUMN_BIRTHDATE)
182
 
    column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
183
 
    column.set_fixed_width(constants.COLUMN_WIDTH_BIRTHDATE)
184
 
    treeview.append_column(column)
185
 
 
186
 
 
187
 
 
188