Commit 78f19b1b authored by Yves Combe's avatar Yves Combe
Browse files

fix GcomprisUser binding (user->login was missing).

add missing python bindings in admin: get_users_from_group, set_current_user, get_current_user.
login.py now uses that.
pythontest check get_current_user
parent f05b1c9a
2005-08-20 Yves Combe,,, <yves@ycombe.net>
fix GcomprisUser binding (user->login was missing).
add missing python bindings in admin: get_users_from_group, set_current_user, get_current_user.
login.py now uses that.
pythontest check get_current_user
* src/boards/py-gcompris-user.c: (pyGcomprisUserType_getattr):
* src/boards/py-mod-admin.c: (py_gcompris_get_users_from_group),
(py_gcompris_set_current_user), (py_gcompris_get_current_user):
* src/boards/python/login.py:
* src/boards/python/pythontest.py:
* src/gcompris/gcompris_db.h:
2005-08-20 Bruno coudoin <bruno.coudoin@free.fr>
Now the square number that cause the number entering refusal is
......
......@@ -46,6 +46,8 @@ pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
/* int */
if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
/* str */
if(strcmp(name,"login")==0) return Py_BuildValue("s", self->cdata->login);
/* str */
if(strcmp(name,"lastname")==0) return Py_BuildValue("s", self->cdata->lastname);
/* str */
if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
......
......@@ -271,6 +271,70 @@ py_gcompris_get_classes_list (PyObject* self, PyObject* args)
return pylist;
}
static PyObject*
py_gcompris_get_users_from_group (PyObject* self, PyObject* args)
{
GList *users_list;
GList *list;
PyObject *pylist;
int group_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris_get_users_from_group", &group_id))
return NULL;
/* Call the corresponding C function */
users_list = gcompris_get_users_from_group(group_id);
pylist = PyList_New(0);
for (list = users_list; list != NULL; list = list->next){
PyList_Append(pylist, gcompris_new_pyGcomprisUserObject((GcomprisUser*) list->data));
}
/* Create and return the result */
return pylist;
}
/* void *gcompris_set_current_user(GcomprisUser *user); */
static PyObject*
py_gcompris_set_current_user (PyObject* self, PyObject* args)
{
PyObject *pyObject_user;
pyGcomprisUserObject *pyUser;
GcomprisUser *user;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris.get_current_user", &pyObject_user))
return NULL;
pyUser = (pyGcomprisUserObject *) pyObject_user;
user = (GcomprisUser *) pyUser->cdata;
/* Call the corresponding C function */
gcompris_set_current_user(user);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
/* GcomprisUser *gcompris_get_current_user(); */
static PyObject*
py_gcompris_get_current_user (PyObject* self, PyObject* args)
{
GcomprisUser *user;
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_current_user"))
return NULL;
/* Call the corresponding C function */
user = gcompris_get_current_user ();
/* Create and return the result */
return gcompris_new_pyGcomprisUserObject((GcomprisUser*) user);
}
static PyMethodDef PythonGcomprisAdminModule[] = {
{ "board_run_next", py_board_run_next, METH_VARARGS, "board_run_next" },
......@@ -286,6 +350,10 @@ static PyMethodDef PythonGcomprisAdminModule[] = {
{ "get_classes_list", py_gcompris_get_classes_list, METH_VARARGS, "gcompris_get_classes_list" },
{ "get_board_from_id", py_gcompris_get_board_from_id, METH_VARARGS, "gcompris_get_board_from_id" },
{ "get_boards_list", py_gcompris_get_boards_list, METH_VARARGS, "gcompris_get_boards_list" },
{ "get_users_from_group", py_gcompris_get_users_from_group, METH_VARARGS, "gcompris_get_users_from_group" },
{ "get_users_from_group", py_gcompris_get_users_from_group, METH_VARARGS, "gcompris_get_users_from_group" },
{ "get_current_user", py_gcompris_get_current_user, METH_VARARGS, "gcompris_get_current_user" },
{ "set_current_user", py_gcompris_set_current_user, METH_VARARGS, "gcompris_set_current_user" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -107,14 +107,32 @@ class Gcompris_login:
)
# Get the user list
users = self.get_users(self.con, self.cur,
Prop.profile.profile_id)
#users = self.get_users(self.con, self.cur,
# Prop.profile.profile_id)
users = []
for group_id in Prop.profile.group_ids:
users.extend( gcompris.admin.get_users_from_group(group_id))
users = self.check_unique_id(users)
self.display_user_by_letter(users, "")
print("Gcompris_login start.")
def check_unique_id(self, users):
passed = {}
for user in users:
passed[user.login] = user
result = []
keys = passed.keys()
keys.sort()
for login in keys:
result.append(passed[login])
return result
def end(self):
# Remove the root item removes all the others inside it
......@@ -155,45 +173,6 @@ class Gcompris_login:
# ---- End of Initialisation ----
# -------------------------------
# Based on the given profile_id, return the list of users
def get_users(self, con, cur, profile_id):
print "profile_id=%s" % profile_id
self.cur.execute('select group_id from list_groups_in_profiles where profile_id=?', (profile_id,))
group_ids = self.cur.fetchall()
print "group_ids"
print group_ids
if not group_ids:
return []
# Hold the results
users = []
# We have the list of groups, now get their users
where_clause = ""
for group_id in group_ids:
group_id = group_id[0]
if(where_clause == ""):
where_clause += "where "
else:
where_clause += "or "
where_clause += "group_id=" + str(group_id) + " "
# Run the query in one shot to have a Distinct user list
self.cur.execute('select distinct user_id from list_users_in_groups ' + where_clause)
user_ids = self.cur.fetchall()
for user_id in user_ids:
# Extract the login, first and last name
self.cur.execute('select login from users where user_id=?', (user_id[0],))
users.append(self.cur.fetchall()[0][0])
# Sort the users
users.sort()
return users
# Display user by letter
# The first letter of the users is displayed
# If the remaining list of users with this letter is
......@@ -206,27 +185,19 @@ class Gcompris_login:
#
def display_user_by_letter(self, users, start_filter):
if not users:
# Get the default profile
Prop = gcompris.get_properties()
gcompris.admin.board_run_next(Prop.menu_board)
return
print "display_user_by_letter start_filter=" + start_filter
# First, create the list of first letter
print "users="
print users
first_letters = []
current_letter = None
remaining_users=0
for user in users:
if user.startswith(start_filter):
if user.login.startswith(start_filter):
remaining_users += 1
if(len(start_filter)<len(user)):
if(len(start_filter)<len(user.login)):
if(not current_letter or
current_letter != user[len(start_filter)]):
current_letter = user[len(start_filter)]
current_letter != user.login[len(start_filter)]):
current_letter = user.login[len(start_filter)]
first_letters.append(current_letter)
# Fine we have the list of first letters
......@@ -365,7 +336,7 @@ class Gcompris_login:
for user in users:
if not user.startswith(start_filter):
if not user.login.startswith(start_filter):
continue
item = self.rootitem.add(
......@@ -384,7 +355,7 @@ class Gcompris_login:
gnome.canvas.CanvasText,
x= x + 1.5,
y= y + 1.5,
text= user,
text= user.login,
fill_color="black",
font=gcompris.skin.get_font("gcompris/board/huge"),
)
......@@ -395,7 +366,7 @@ class Gcompris_login:
gnome.canvas.CanvasText,
x= x,
y= y,
text= user,
text= user.login,
fill_color="white",
font=gcompris.skin.get_font("gcompris/board/huge"),
)
......@@ -427,7 +398,8 @@ class Gcompris_login:
#
def name_click_event(self, widget, event, user):
if event.type == gtk.gdk.BUTTON_PRESS:
print "selected user = " + user
print "selected user = " + user.login
gcompris.admin.set_current_user(user)
# Get the default profile
Prop = gcompris.get_properties()
......
......@@ -4,6 +4,7 @@ import gnome.canvas
import gcompris
import gcompris.utils
import gcompris.skin
import gcompris.admin
import gtk
import gtk.gdk
from gcompris import gcompris_gettext as _
......@@ -37,6 +38,11 @@ class Gcompris_pythontest:
#the configured values.
def start(self):
logged = gcompris.admin.get_current_user()
print "User Logged in:"
print " ", logged.login, logged.firstname, logged.lastname
self.gcomprisBoard.level=1
self.gcomprisBoard.maxlevel=1
self.gcomprisBoard.sublevel=1
......
/* gcompris - gcompris_db.h
*
* Time-stamp: <2005/07/24 23:59:17 bruno>
* Time-stamp: <2005/08/20 23:44:47 yves>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -111,6 +111,8 @@ GHashTable *gcompris_get_board_conf();
/* get conf for specific profile and board */
GHashTable *gcompris_get_conf(GcomprisProfile *profile, GcomprisBoard *board);
GcomprisBoard *gcompris_get_board_from_id(int board_id);
#endif
/* Local Variables: */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment