From 527c6790e47d8725f6b9306049b3aa89006c393e Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 26 Feb 2007 02:42:58 +0000 Subject: [PATCH] Grupos creo que no puedo agregar porque necesito AlumnoInscripto --- sercom/controllers.py | 2 + sercom/model.py | 3 +- sercom/subcontrollers/__init__.py | 1 + sercom/subcontrollers/grupo/__init__.py | 123 ++++++++++++++++++ .../grupo/templates/__init__.py | 0 .../subcontrollers/grupo/templates/edit.kid | 20 +++ .../subcontrollers/grupo/templates/list.kid | 41 ++++++ sercom/subcontrollers/grupo/templates/new.kid | 18 +++ .../subcontrollers/grupo/templates/show.kid | 35 +++++ 9 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 sercom/subcontrollers/grupo/__init__.py create mode 100644 sercom/subcontrollers/grupo/templates/__init__.py create mode 100644 sercom/subcontrollers/grupo/templates/edit.kid create mode 100644 sercom/subcontrollers/grupo/templates/list.kid create mode 100644 sercom/subcontrollers/grupo/templates/new.kid create mode 100644 sercom/subcontrollers/grupo/templates/show.kid diff --git a/sercom/controllers.py b/sercom/controllers.py index 3c3eb04..233d796 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -79,6 +79,8 @@ class Root(controllers.RootController): docente = DocenteController() + grupo = GrupoController() + alumno = AlumnoController() enunciado = EnunciadoController() diff --git a/sercom/model.py b/sercom/model.py index 9112694..918657a 100644 --- a/sercom/model.py +++ b/sercom/model.py @@ -592,7 +592,8 @@ class Grupo(Entregador): #{{{ def __init__(self, curso=None, nombre=None, responsable=None, **kargs): resp_id = responsable and responsable.id - InheritableSQLObject.__init__(self, cursoID=curso.id, nombre=nombre, + curso_id = curso and curso.id + InheritableSQLObject.__init__(self, cursoID=curso_id, nombre=nombre, responsableID=resp_id, **kargs) def add_alumno(self, alumno, *args, **kargs): diff --git a/sercom/subcontrollers/__init__.py b/sercom/subcontrollers/__init__.py index ebf6f40..d54492e 100644 --- a/sercom/subcontrollers/__init__.py +++ b/sercom/subcontrollers/__init__.py @@ -5,3 +5,4 @@ from enunciado import EnunciadoController from caso_de_prueba import CasoDePruebaController from ejercicio import EjercicioController from docente_inscripto import DocenteInscriptoController +from grupo import GrupoController diff --git a/sercom/subcontrollers/grupo/__init__.py b/sercom/subcontrollers/grupo/__init__.py new file mode 100644 index 0000000..58e6d95 --- /dev/null +++ b/sercom/subcontrollers/grupo/__init__.py @@ -0,0 +1,123 @@ +# 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, AlumnoInscripto, Docente, Grupo +#}}} + +#{{{ Configuración +cls = Grupo +name = 'grupo' +namepl = 'grupos' +#}}} + +#{{{ 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) +#}}} + +#{{{ Formulario +def get_docentes(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()] + +def get_cursos(): + return [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()] + +class GrupoForm(W.TableForm): + class Fields(W.WidgetsList): + curso = W.SingleSelectField(label=_(u'Curso'), options = get_cursos, + validator = V.Int(not_empty=True)) + nombre = W.TextField(label=_(u'Nombre'), validator=V.UnicodeString(not_empty=True,strip=True)) + + fields = Fields() + javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")] + +form = GrupoForm() + +#}}} + +#{{{ Controlador +class GrupoController(controllers.Controller, identity.SecureResource): + """Basic model admin interface""" + require = identity.has_permission('admin') + + @expose() + def default(self, tg_errors=None): + """handle non exist urls""" + raise redirect('list') + + @expose() + def index(self): + raise redirect('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) + raise redirect('../../list') + + @expose(template='kid:%s.templates.new' % __name__) + def new(self, **kw): + """Create new records in model""" + 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""" + validate_new(kw) + 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/grupo/templates/__init__.py b/sercom/subcontrollers/grupo/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sercom/subcontrollers/grupo/templates/edit.kid b/sercom/subcontrollers/grupo/templates/edit.kid new file mode 100644 index 0000000..7b50a66 --- /dev/null +++ b/sercom/subcontrollers/grupo/templates/edit.kid @@ -0,0 +1,20 @@ + + + + +edit + + + +

Modificación de Objeto

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

Administración de Objetos

+ + + + + + + + + + + + + +
CursoNombreResponsable
cursonombre + Editar + Eliminar +
+ +
+Agregar + +
+ ${page} + ${page} +
+ + + + + diff --git a/sercom/subcontrollers/grupo/templates/new.kid b/sercom/subcontrollers/grupo/templates/new.kid new file mode 100644 index 0000000..359422d --- /dev/null +++ b/sercom/subcontrollers/grupo/templates/new.kid @@ -0,0 +1,18 @@ + + + + +new + + + +

Crear Nuevo Objeto

+ +

Formulario

+ +
+Cancelar + + + diff --git a/sercom/subcontrollers/grupo/templates/show.kid b/sercom/subcontrollers/grupo/templates/show.kid new file mode 100644 index 0000000..c8b3049 --- /dev/null +++ b/sercom/subcontrollers/grupo/templates/show.kid @@ -0,0 +1,35 @@ + + + + +show + + + + + + + + + + + + + + + + + + + + + +
Curso:curso
Docente:docente
Corrige:numero
Descripcion:SINO
+ +
+Editar | +Volver + + + -- 2.43.0