root/actividadextraescolar/actividadExtraescolar.py @ 494
466 | JuanAntoni | #!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|||
# generated by wxGlade 0.6.3 on Thu Apr 19 10:05:25 2012
|
|||
# Tiétar 20-12-2012
|
|||
import wx, ldap, listado
|
|||
from reportlab.pdfgen.canvas import Canvas
|
|||
from reportlab.lib.pagesizes import A4
|
|||
import subprocess, os
|
|||
import unicodedata
|
|||
# begin wxGlade: extracode
|
|||
# end wxGlade
|
|||
class excursiones(wx.Frame):
|
|||
tabla = []
|
|||
def __init__(self, *args, **kwds):
|
|||
# begin wxGlade: excursiones.__init__
|
|||
kwds["style"] = wx.DEFAULT_FRAME_STYLE
|
|||
wx.Frame.__init__(self, *args, **kwds)
|
|||
self.label_1 = wx.StaticText(self, -1, "Actividad", style=wx.ST_NO_AUTORESIZE)
|
|||
self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
|
|||
self.label_2 = wx.StaticText(self, -1, "Fecha")
|
|||
self.datepicker_ctrl_1 = wx.DatePickerCtrl(self, -1)
|
|||
self.label_3 = wx.StaticText(self, -1, "Curso")
|
|||
self.label_4 = wx.StaticText(self, -1, "Alumnos")
|
|||
self.label_5 = wx.StaticText(self, -1, "Incluidos")
|
|||
self.listCurso = wx.ListBox(self, -1, choices=[], style=wx.LB_SORT)
|
|||
self.listAlumnos = wx.ListBox(self, -1, choices=[], style=wx.LB_SORT)
|
|||
self.listSeleccionados = wx.ListBox(self, -1, choices=[], style=wx.LB_SORT)
|
|||
self.btPrint = wx.Button(self, -1, "Imprimir")
|
|||
self.btExit = wx.Button(self, -1, "Terminar")
|
|||
self.__set_properties()
|
|||
self.__do_layout()
|
|||
self.listCurso.InsertItems(self.consulta('cursos',''),0)
|
|||
self.Bind(wx.EVT_LISTBOX, self.cursoClic, self.listCurso)
|
|||
self.Bind(wx.EVT_LISTBOX, self.alumClic, self.listAlumnos)
|
|||
self.Bind(wx.EVT_LISTBOX, self.borraIncluido, self.listSeleccionados)
|
|||
self.Bind(wx.EVT_BUTTON, self.imprime, self.btPrint)
|
|||
self.Bind(wx.EVT_BUTTON, self.salir, self.btExit)
|
|||
# end wxGlade
|
|||
def __set_properties(self):
|
|||
# begin wxGlade: excursiones.__set_properties
|
|||
self.SetTitle("Actividad Extraescolar")
|
|||
self.SetSize((850, 800))
|
|||
self.text_ctrl_1.SetMinSize((480, 29))
|
|||
self.listCurso.SetMinSize((100, 584))
|
|||
self.listCurso.SetToolTipString("Clic para escoger curso")
|
|||
self.listAlumnos.SetMinSize((308, 584))
|
|||
self.listAlumnos.SetToolTipString("Clic para escoger alumno")
|
|||
self.listSeleccionados.SetMinSize((308, 584))
|
|||
self.listSeleccionados.SetToolTipString("Clic para borrar alumno")
|
|||
self.datepicker_ctrl_1.SetMinSize((200,29))
|
|||
# end wxGlade
|
|||
def __do_layout(self):
|
|||
# begin wxGlade: excursiones.__do_layout
|
|||
sizer_1 = wx.FlexGridSizer(3,1,5,5)
|
|||
sizer_1.AddGrowableCol(1)
|
|||
botones = wx.BoxSizer(wx.HORIZONTAL)
|
|||
cursoAlumnos = wx.FlexGridSizer(3, 3, 0, 5)
|
|||
titulofecha = wx.FlexGridSizer(1,4,5,5)
|
|||
titulofecha.Add(self.label_1, 0, 0, 0)
|
|||
titulofecha.Add(self.text_ctrl_1, 1, 0, 0)
|
|||
titulofecha.Add(self.label_2, 0, 0, 0)
|
|||
titulofecha.Add(self.datepicker_ctrl_1, 1, wx.ALIGN_RIGHT, 0)
|
|||
titulofecha.AddGrowableCol(1,3)
|
|||
sizer_1.Add(titulofecha, 0, wx.EXPAND, 0)
|
|||
cursoAlumnos.Add(self.label_3, 0, 0, 0)
|
|||
cursoAlumnos.Add(self.label_4, 0, 0, 0)
|
|||
cursoAlumnos.Add(self.label_5, 0, 0, 0)
|
|||
cursoAlumnos.Add(self.listCurso, 0, 0, 0)
|
|||
cursoAlumnos.Add(self.listAlumnos, 0, 0, 0)
|
|||
cursoAlumnos.Add(self.listSeleccionados, 0, 0, 0)
|
|||
sizer_1.Add(cursoAlumnos, 3, wx.EXPAND, 0)
|
|||
botones.Add(self.btPrint, 0, 0, 0)
|
|||
botones.Add(self.btExit, 0, 0, 0)
|
|||
sizer_1.Add(botones, 0, wx.ADJUST_MINSIZE, 0)
|
|||
self.SetSizer(sizer_1)
|
|||
#self.Maximize()
|
|||
self.Layout()
|
|||
# end wxGlade
|
|||
def cursoClic(self, event): # wxGlade: excursiones.<event_handler>
|
|||
#1ªclic no hay alumnos seleccionados
|
|||
self.listAlumnos.Clear()
|
|||
nombres = self.rellenaList(self.listCurso.GetStringSelection())
|
|||
self.listAlumnos.InsertItems(nombres,0)
|
|||
if self.listSeleccionados.GetStrings():
|
|||
self.otroCurso()
|
|||
self.tabla.append([self.listCurso.GetStringSelection(),[],[]])
|
|||
event.Skip()
|
|||
def alumClic(self, event): # wxGlade: excursiones.<event_handler>
|
|||
self.listSeleccionados.Append(self.listAlumnos.GetStringSelection().encode('utf-8'))
|
|||
def borraIncluido(self, event):
|
|||
self.listSeleccionados.Delete(self.listSeleccionados.GetSelection())
|
|||
event.Skip()
|
|||
def otroCurso(self): # wxGlade: excursiones.<event_handler>
|
|||
#self.tabla.append([self.listCurso.GetStringSelection().encode('utf-8'),''])
|
|||
tmp = []
|
|||
indice = 0
|
|||
for i in self.listSeleccionados.GetStrings():
|
|||
if i <> '':
|
|||
tmp.append(i)
|
|||
indice +=1
|
|||
#creo listas de 3 elementos para mandar 3 columnas al table
|
|||
if indice > 2 :
|
|||
self.tabla.append(tmp)
|
|||
tmp = []
|
|||
indice = 0
|
|||
while len(tmp) < 3:
|
|||
tmp.append([])
|
|||
self.tabla.append(tmp)
|
|||
self.listSeleccionados.Clear()
|
|||
#event.Skip()
|
|||
def imprime(self, event):
|
|||
self.otroCurso()
|
|||
year = self.datepicker_ctrl_1.GetValue().GetYear()
|
|||
dia = self.datepicker_ctrl_1.GetValue().GetDay()
|
|||
mes = wx.DateTime.GetMonthName(int(self.datepicker_ctrl_1.GetValue().GetMonth()))
|
|||
listado.hoy = ' ' +str(dia) + ' de ' + mes + ' de '+ str(year)
|
|||
listado.c = Canvas('ActividadExtraescolar.pdf',pagesize=A4)
|
|||
listado.actividad = self.text_ctrl_1.GetValue()
|
|||
listado.alumnos = self.tabla
|
|||
listado.contenido()
|
|||
mivar = subprocess.Popen(['evince',os.path.realpath('ActividadExtraescolar.pdf')])
|
|||
while mivar.poll() <> 0:
|
|||
pass
|
|||
event.Skip()
|
|||
def salir(self, event): # wxGlade: excursiones.<event_handler>
|
|||
self.Close(True)
|
|||
event.Skip()
|
|||
#lista de alumnos
|
|||
def rellenaList(self,curso):
|
|||
allcurso = []
|
|||
nombres = []
|
|||
allcurso.append(self.consulta('alumnocurso',curso))
|
|||
for i in allcurso[0][0]:
|
|||
if i != '':
|
|||
nombres.append(self.consulta('nombre',i)[0])
|
|||
return nombres
|
|||
def consulta(self,datoResultado,datoUsuario):
|
|||
datosConsulta = []
|
|||
# NO SIRVE ? BORRAR cursos = []
|
|||
tipo = datoResultado
|
|||
usuarioCurso = datoUsuario
|
|||
searchScope = ldap.SCOPE_SUBTREE
|
|||
#opcion de ricardo para ldaps
|
|||
try:
|
|||
l = ldap.initialize("ldaps://ldap")
|
|||
l.protocol_version = ldap.VERSION3
|
|||
#l = ldap.open("ldap")
|
|||
username = "cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es"
|
|||
password = "xxxxxxx"
|
|||
l.simple_bind(username,password)
|
|||
except ldap.LDAPError, e:
|
|||
print e
|
|||
return "ERRORLDAP"
|
|||
if tipo == 'cursos':
|
|||
#cursos
|
|||
base_dn = 'ou=Group,dc=instituto,dc=extremadura,dc=es'
|
|||
searchFilter = '(&(objectClass=posixGroup)(groupType=school_class))'
|
|||
retrieveAttributes = ['cn']
|
|||
elif tipo == 'alumnocurso':
|
|||
base_dn= 'ou=Group,dc=instituto,dc=extremadura,dc=es'
|
|||
searchFilter = '(&(&(objectClass=posixGroup)(groupType=school_class))(cn=' + usuarioCurso + '))'
|
|||
retrieveAttributes = ['memberUid'] #Extraer miembros
|
|||
elif tipo == 'profesores':
|
|||
base_dn = 'ou=Group,dc=instituto,dc=extremadura,dc=es '
|
|||
searchFilter = "(&(objectClass=posixGroup)(cn=teachers))"
|
|||
retrieveAttributes = ['memberUid']
|
|||
elif tipo == 'nombre':#Nombre de usuario
|
|||
base_dn= 'ou=People,dc=instituto,dc=extremadura,dc=es'
|
|||
searchFilter = '(uid=' + usuarioCurso +')'
|
|||
retrieveAttributes = ['cn']
|
|||
elif tipo == 'nif':
|
|||
base_dn= 'ou=People,dc=instituto,dc=extremadura,dc=es'
|
|||
searchFilter = '(uid=' + usuarioCurso +')'
|
|||
retrieveAttributes = ['employeeNumber']
|
|||
elif tipo == 'nie':
|
|||
base_dn= 'ou=People,dc=instituto,dc=extremadura,dc=es'
|
|||
searchFilter = '(employeeNumber=' + usuarioCurso +')'
|
|||
retrieveAttributes = ['uid']
|
|||
else :
|
|||
pass
|
|||
try:
|
|||
ldap_result_id = l.search(base_dn, searchScope, searchFilter, retrieveAttributes)
|
|||
result_type, result_data = l.result(ldap_result_id)
|
|||
if tipo == 'cursos':
|
|||
for i in result_data:
|
|||
datosConsulta.append(i[1]['cn'][0])
|
|||
elif tipo == 'alumnocurso' or tipo == 'profesores' :
|
|||
datosConsulta.append(result_data[0][1]['memberUid'])
|
|||
elif tipo == 'nombre':
|
|||
datosConsulta.append(result_data[0][1]['cn'][0])
|
|||
elif tipo == 'nif':
|
|||
if result_data[0][1] != {}:
|
|||
datosConsulta.append(result_data[0][1]['employeeNumber'][0])
|
|||
elif tipo == 'nie':
|
|||
if result_data[0][1] != {}:
|
|||
datosConsulta.append(result_data[0][1]['uid'][0])
|
|||
else :
|
|||
pass
|
|||
except ldap.LDAPError, e:
|
|||
print e
|
|||
print "ERRORLDAP"
|
|||
return datosConsulta
|
|||
# end of class excursiones
|
|||
if __name__ == "__main__":
|
|||
app = wx.PySimpleApp(0)
|
|||
wx.InitAllImageHandlers()
|
|||
Principal = excursiones(None, -1, "")
|
|||
app.SetTopWindow(Principal)
|
|||
Principal.Show()
|
|||
app.MainLoop()
|