From: tailor Date: Thu, 1 Mar 2007 01:51:23 +0000 (+0000) Subject: Cursos y alumnos X-Git-Tag: pre-merge~28 X-Git-Url: https://git.llucax.com/software/sercom.git/commitdiff_plain/a0fbd7a909e29af5349e41664feeb7dfb128304e?ds=inline Cursos y alumnos * Agrego provisoriamente ua pantalla para inscribir alumnos que todavia no hace mas que pasar registros de una lista a la otra.. --- diff --git a/sercom/controllers.py b/sercom/controllers.py index 4edbe60..f7e9d83 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -93,6 +93,7 @@ class Root(controllers.RootController): docente_inscripto = DocenteInscriptoController() + #{{{ Agrega summarize a namespace tg de KID def summarize(text, size, concat=True, continuation='...'): """Summarize a string if it's length is greater than a specified size. This diff --git a/sercom/subcontrollers/curso/__init__.py b/sercom/subcontrollers/curso/__init__.py index bd66334..8b3c082 100644 --- a/sercom/subcontrollers/curso/__init__.py +++ b/sercom/subcontrollers/curso/__init__.py @@ -11,6 +11,8 @@ from turbogears import paginate from docutils.core import publish_parts from sercom.subcontrollers import validate as val from sercom.model import Curso, Ejercicio, Alumno, Docente, Grupo, DocenteInscripto +from curso_alumno import * + #}}} #{{{ Configuración @@ -78,6 +80,7 @@ form = CursoForm() class CursoController(controllers.Controller, identity.SecureResource): """Basic model admin interface""" require = identity.has_permission('admin') + curso_alumno = CursoAlumnoController() @expose() def default(self, tg_errors=None): diff --git a/sercom/subcontrollers/curso/curso_alumno/__init__.py b/sercom/subcontrollers/curso/curso_alumno/__init__.py new file mode 100644 index 0000000..4ab007f --- /dev/null +++ b/sercom/subcontrollers/curso/curso_alumno/__init__.py @@ -0,0 +1,174 @@ +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : + +#{{{ Imports +import cherrypy +from turbogears import controllers, expose, redirect +from turbogears import validate, flash, error_handler +from turbogears import validators as V +from turbogears import widgets as W +from turbogears import identity +from turbogears import paginate +from docutils.core import publish_parts +from sercom.subcontrollers import validate as val +from sercom.model import Curso, Ejercicio, Alumno, Docente, Grupo, DocenteInscripto, AlumnoInscripto +#}}} + +#{{{ Configuración +cls = Curso +name = 'Alumno del curso' +namepl = 'Alumnos del curso' +#}}} + +#{{{ Validación +def validate_get(id): + return val.validate_get(cls, name, id) + +def validate_set(id, data): + return val.validate_set(cls, name, id, data) + +def validate_new(data): + return val.validate_new(cls, name, data) +#}}} + +def get_ejercicios(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Ejercicio.select()] + +def get_docentes(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()] + +def get_alumnos_inscriptos(curso): + return [(fk1.id, fk1.shortrepr()) for fk1 in AlumnoInscripto.selectBy(curso)] + +def get_alumnos(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Alumno.select()] + +def get_grupos(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Grupo.select()] + +ajax = u""" +function makeOption(option) { + return OPTION({"value": option.value}, option.text); +} + +function moveOption( fromSelect, toSelect) { + // add 'selected' nodes toSelect + appendChildNodes(toSelect, + map( makeOption,ifilter(itemgetter('selected'), $(fromSelect).options))); + // remove the 'selected' fromSelect + replaceChildNodes(fromSelect, + list(ifilterfalse(itemgetter('selected'), $(fromSelect).options)) + ); +} +""" + +#{{{ Formulario +class CursoAlumnoForm(W.TableForm): + class Fields(W.WidgetsList): + alumnos = W.MultipleSelectField(label=_(u'Alumnos'), + attrs=dict( style='width:250px'), + options=get_alumnos, + validator = V.Int(not_empty=False)) + inscribir = W.Button(default='Inscribir', label='', + attrs=dict( onclick='moveOption("form_alumnos","form_inscriptos")')) + desinscribir = W.Button(default='Desinscribir', label='', + attrs=dict( onclick='moveOption("form_inscriptos","form_alumnos")')) + inscriptos = W.MultipleSelectField(label=_(u'Alumnos Inscriptos'), + attrs=dict( style='width:250px'), + validator = V.Int(not_empty=False)) + fields = Fields() + javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('alumnos');"), + W.JSSource(ajax)] +form = CursoAlumnoForm() +#}}} + +#{{{ Controlador +class CursoAlumnoController(controllers.Controller, identity.SecureResource): + """Basic model admin interface""" + require = identity.has_permission('admin') + + @expose() + def default(self, curso_id): + """handle non exist urls""" + return dict(records=r, name=name, namepl=namepl, alumnos=alumnos) + + @expose() + def index(self): + raise redirect('/curso/list') + + @expose(template='kid:%s.templates.list' % __name__) + @paginate('records') + def list(self): + """List records in model""" + r = cls.select() + return dict(records=r, name=name, namepl=namepl) + + @expose() + def activate(self, id, activo): + """Save or create record to model""" + r = validate_get(id) + try: + r.activo = bool(int(activo)) + except ValueError: + raise cherrypy.NotFound + raise redirect('../../list') + + @expose(template='kid:%s.templates.new' % __name__) + def new(self,curso_id, **kw): + """Create new records in model""" + curso = Curso.get(curso_id) + alumnos_inscriptos = AlumnoInscripto.selectBy(curso=curso) +# kw['alumnos'] = alumnos_inscriptos +# form.fields.alumnos.options = alumnos_inscriptos + return dict(name=name, namepl=namepl, form=form, values=kw) + + @validate(form=form) + @error_handler(new) + @expose() + def create(self, **kw): + """Save or create record to model""" + r = validate_new(kw) + docentes = kw.get('docentes', []) + alumnos = kw.get('alumnos', []) + """ Elimino todos los docentes asignados al curso y los agrego nuevamente""" + for d in DocenteInscripto.selectBy(curso=r): + d.destroySelf() + """ Agrego la nueva seleccion """ + for d in docentes: + r.add_docente(Docente(d)) + """ Elimino a los alumnos y los vuelvo a agregar """ + for a in AlumnoInscripto.selectBy(curso=r): + d.destroySelf() + for a in alumnos: + r.add_alumno(Alumno(a)) + flash(_(u'Se creó un nuevo %s.') % name) + raise redirect('list') + + @expose(template='kid:%s.templates.edit' % __name__) + def edit(self, id, **kw): + """Edit record in model""" + r = validate_get(id) + return dict(name=name, namepl=namepl, record=r, form=form) + + @validate(form=form) + @error_handler(edit) + @expose() + def update(self, id, **kw): + """Save or create record to model""" + r = validate_set(id, kw) + flash(_(u'El %s fue actualizado.') % name) + raise redirect('../list') + + @expose(template='kid:%s.templates.show' % __name__) + def show(self,id, **kw): + """Show record in model""" + r = validate_get(id) + return dict(name=name, namepl=namepl, record=r) + + @expose() + def delete(self, id): + """Destroy record in model""" + r = validate_get(id) + r.destroySelf() + flash(_(u'El %s fue eliminado permanentemente.') % name) + raise redirect('../list') +#}}} diff --git a/sercom/subcontrollers/curso/curso_alumno/templates/__init__.py b/sercom/subcontrollers/curso/curso_alumno/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sercom/subcontrollers/curso/curso_alumno/templates/edit.kid b/sercom/subcontrollers/curso/curso_alumno/templates/edit.kid new file mode 100644 index 0000000..8c17c7b --- /dev/null +++ b/sercom/subcontrollers/curso/curso_alumno/templates/edit.kid @@ -0,0 +1,19 @@ + + + + +edit + + + +

Modificación de Objeto

+ +
Formulario
+
+Ver (cancela) | +Volver (cancela) + + + diff --git a/sercom/subcontrollers/curso/curso_alumno/templates/list.kid b/sercom/subcontrollers/curso/curso_alumno/templates/list.kid new file mode 100644 index 0000000..5222788 --- /dev/null +++ b/sercom/subcontrollers/curso/curso_alumno/templates/list.kid @@ -0,0 +1,56 @@ + + + + +list + + + +

Administración de Objetos

+ + + + + + + + + + + + + + + + + + + + + + + + + +
NumeroCuatrimestreAnioDescripcionDocentesAlumnosGruposEjerciciosOperaciones
numerocuatrimestreaniodescripcionDocentesAlumnosGruposEjercicioVer + Editar + Eliminar
+ +
+Agregar + +
+ ${page} + ${page} +
+ + + + + diff --git a/sercom/subcontrollers/curso/curso_alumno/templates/new.kid b/sercom/subcontrollers/curso/curso_alumno/templates/new.kid new file mode 100644 index 0000000..0d1719a --- /dev/null +++ b/sercom/subcontrollers/curso/curso_alumno/templates/new.kid @@ -0,0 +1,16 @@ + + + + +new + + + +

Asignar Nuevo Objeto

+

Formulario

+ +
+Cancelar + + + diff --git a/sercom/subcontrollers/curso/curso_alumno/templates/show.kid b/sercom/subcontrollers/curso/curso_alumno/templates/show.kid new file mode 100644 index 0000000..f241d50 --- /dev/null +++ b/sercom/subcontrollers/curso/curso_alumno/templates/show.kid @@ -0,0 +1,50 @@ + + + + +show + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Anio:anio
Cuatrimestre:cuatrimestre
Numero:numero
Descripcion:descripcion
Docentes:Docentes
Alumnos:alumnos
Grupos:grupos
Ejercicios:ejercicios
+ +
+Editar | +Volver + + + diff --git a/sercom/subcontrollers/curso/templates/edit.kid b/sercom/subcontrollers/curso/templates/edit.kid index 7b50a66..5c29a14 100644 --- a/sercom/subcontrollers/curso/templates/edit.kid +++ b/sercom/subcontrollers/curso/templates/edit.kid @@ -11,8 +11,9 @@
Formulario
- -
+Agregar Alumnos +
+
Ver (cancela) | Volver (cancela) diff --git a/sercom/subcontrollers/curso/templates/list.kid b/sercom/subcontrollers/curso/templates/list.kid index a1327df..2634178 100644 --- a/sercom/subcontrollers/curso/templates/list.kid +++ b/sercom/subcontrollers/curso/templates/list.kid @@ -18,8 +18,8 @@ Docentes Alumnos Grupos - Ejercicios - Operaciones + Ejercicios + Operaciones - numero + numero cuatrimestre anio descripcion @@ -36,7 +35,8 @@ Alumnos Grupos Ejercicio - Editar + Ver + Editar Eliminar diff --git a/sercom/subcontrollers/curso/templates/show.kid b/sercom/subcontrollers/curso/templates/show.kid index 5b6d63a..f241d50 100644 --- a/sercom/subcontrollers/curso/templates/show.kid +++ b/sercom/subcontrollers/curso/templates/show.kid @@ -26,19 +26,19 @@ Docentes: - docentes + Docentes Alumnos: - alumnos + alumnos Grupos: - grupos + grupos Ejercicios: - ejercicios + ejercicios