Back to index

gcompris  8.2.2
constants.py
Go to the documentation of this file.
00001 #  gcompris - constants.py
00002 # 
00003 # Copyright (C) 2005 Bruno Coudoin and Yves Combe
00004 # 
00005 #   This program is free software; you can redistribute it and/or modify
00006 #   it under the terms of the GNU General Public License as published by
00007 #   the Free Software Foundation; either version 2 of the License, or
00008 #   (at your option) any later version.
00009 # 
00010 #   This program is distributed in the hope that it will be useful,
00011 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #   GNU General Public License for more details.
00014 # 
00015 #   You should have received a copy of the GNU General Public License
00016 #   along with this program; if not, write to the Free Software
00017 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 # 
00019 
00020 
00021 # Some common constants for the administration
00022 
00023 COLUMN_WIDTH_LOGIN                   = 80
00024 COLUMN_WIDTH_FIRSTNAME               = 100
00025 COLUMN_WIDTH_LASTNAME                = 180
00026 COLUMN_WIDTH_BIRTHDATE               = 40
00027 
00028 COLUMN_WIDTH_CLASSNAME               = 100
00029 COLUMN_WIDTH_TEACHER                 = 300
00030 
00031 COLUMN_WIDTH_GROUPNAME               = 100
00032 COLUMN_WIDTH_GROUPDESCRIPTION        = 200
00033 COLUMN_WIDTH_GROUPDESCRIPTION_EDIT   = 150
00034 
00035 COLUMN_WIDTH_PROFILENAME             = 100
00036 COLUMN_WIDTH_PROFILEDESCRIPTION      = 300
00037 
00038 #
00039 # Some utility method
00040 # -------------------
00041 
00042 # Return the next class id in the base
00043 # Params are db_connect, db_cursor
00044 def get_next_class_id(con, cur):
00045     cur.execute('select max(class_id) from class')
00046     class_id = cur.fetchone()[0]
00047     
00048     if(class_id == None):
00049         class_id=0
00050     else:
00051         class_id += 1
00052       
00053     return class_id
00054 
00055 
00056 
00057 # Return the next group id in the base
00058 # Params are db_connect, db_cursor
00059 def get_next_group_id(con, cur):
00060     cur.execute('select max(group_id) from groups')
00061     group_id = cur.fetchone()[0]
00062     
00063     if(group_id == None):
00064         group_id=0
00065     else:
00066         group_id += 1
00067       
00068     return group_id
00069 
00070 
00071 # Return the next profile id in the base
00072 # Params are db_connect, db_cursor
00073 def get_next_profile_id(con, cur):
00074     cur.execute('select max(profile_id) from profiles')
00075     profile_id = cur.fetchone()[0]
00076     
00077     if(profile_id == None):
00078         profile_id=0
00079     else:
00080         profile_id += 1
00081         
00082     return profile_id
00083 
00084 
00085 # get_wholegroup_id
00086 # From the given class_id, return it's wholegroup_id
00087 # Params are db_connect, db_cursor, class_id
00088 def get_wholegroup_id(con, cur, class_id):
00089     cur.execute('SELECT wholegroup_id FROM class WHERE class_id=?',
00090                 (class_id,))
00091     return(cur.fetchone()[0])
00092 
00093 
00094 # get_class_name_for_group_id
00095 # From the given group_id, return it's class name
00096 # Or "" if not found
00097 def get_class_name_for_group_id(con, cur, group_id):
00098 
00099     class_name = ""
00100     
00101     # Extract the class name of this group
00102     cur.execute('SELECT class_id FROM groups WHERE group_id=?',
00103                      (group_id,))
00104     result = cur.fetchall()
00105     if(result):
00106         class_id = result[0][0]
00107 
00108         cur.execute('SELECT name FROM class WHERE class_id=?',
00109                     (class_id,))
00110         result = cur.fetchall()
00111         if(result):
00112             class_name = result[0][0]
00113 
00114     return class_name