From 7bee4072574324ca7b3e6d8dc6deec589b13126f Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 31 Jan 2007 05:10:55 +0000 Subject: [PATCH] =?utf8?q?ABM=20de=20docentes.=20El=20ABM=20de=20docentes?= =?utf8?q?=20usa=20decentemente=20la=20infrastructura=20de=20widgets=20de?= =?utf8?q?=20TG=20y=20es=20un=20buen=20ejemplo=20para=20usar=20de=20planti?= =?utf8?q?lla=20para=20ABM=20de=20otras=20cosas.=20Adem=C3=A1s=20usa=20doc?= =?utf8?q?utils=20para=20que=20las=20observaciones=20tengan=20formato=20ti?= =?utf8?q?po=20wiki=20y=20una=20funci=C3=B3n=20de=20utilidad=20para=20KID?= =?utf8?q?=20para=20resumir=20un=20campo=20para=20que=20la=20tabla=20no=20?= =?utf8?q?se=20deforme.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sercom/controllers.py | 4 + sercom/kidutil.py | 7 ++ sercom/subcontrollers/__init__.py | 1 + sercom/subcontrollers/docente/__init__.py | 118 ++++++++++++++++++ .../docente/templates/__init__.py | 0 .../subcontrollers/docente/templates/edit.kid | 19 +++ .../subcontrollers/docente/templates/list.kid | 56 +++++++++ .../subcontrollers/docente/templates/new.kid | 18 +++ .../subcontrollers/docente/templates/show.kid | 45 +++++++ 9 files changed, 268 insertions(+) create mode 100644 sercom/kidutil.py create mode 100644 sercom/subcontrollers/__init__.py create mode 100644 sercom/subcontrollers/docente/__init__.py create mode 100644 sercom/subcontrollers/docente/templates/__init__.py create mode 100644 sercom/subcontrollers/docente/templates/edit.kid create mode 100644 sercom/subcontrollers/docente/templates/list.kid create mode 100644 sercom/subcontrollers/docente/templates/new.kid create mode 100644 sercom/subcontrollers/docente/templates/show.kid diff --git a/sercom/controllers.py b/sercom/controllers.py index 4d999ce..13f6172 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -7,6 +7,8 @@ from cherrypy import request, response from model import * # from sercom import json +from subcontrollers import DocenteController + import logging log = logging.getLogger("sercom.controllers") @@ -73,3 +75,5 @@ class Root(controllers.RootController): identity.current.logout() raise redirect('/') + docente = DocenteController() + diff --git a/sercom/kidutil.py b/sercom/kidutil.py new file mode 100644 index 0000000..82feb16 --- /dev/null +++ b/sercom/kidutil.py @@ -0,0 +1,7 @@ +# vim: set et sw=4 sts=4 encoding=utf-8 : + +def resume(text, size=15): + if text is not None and len(text) > size: + text = text[:size-3] + '...' + return text + diff --git a/sercom/subcontrollers/__init__.py b/sercom/subcontrollers/__init__.py new file mode 100644 index 0000000..41c6761 --- /dev/null +++ b/sercom/subcontrollers/__init__.py @@ -0,0 +1 @@ +from docente import DocenteController diff --git a/sercom/subcontrollers/docente/__init__.py b/sercom/subcontrollers/docente/__init__.py new file mode 100644 index 0000000..e01023d --- /dev/null +++ b/sercom/subcontrollers/docente/__init__.py @@ -0,0 +1,118 @@ +# vim: set et sw=4 sts=4 encoding=utf-8 : + +from turbogears import controllers, expose, redirect +from turbogears import validate, validators, flash, error_handler +from sercom.model import Docente +from turbogears.widgets import * +from turbogears import identity +from turbogears import paginate +from docutils.core import publish_parts + +cls = Docente +name = 'docente' +namepl = name + 's' + +form = TableForm(fields=[ + TextField(name='usuario', label=_(u'Usuario'), + help_text=_(u'Requerido.'), + validator=validators.UnicodeString(min=3, max=10, strip=True)), + TextField(name='nombre', label=_(u'Nombre'), + help_text=_(u'Requerido.'), + validator=validators.UnicodeString(min=10, max=255, strip=True)), + TextField(name='email', label=_(u'E-Mail'), + #help_text=_(u'Dirección de e-mail.'), + validator=validators.All( + validators.Email(not_empty=False, resolve_domain=True), + validators.UnicodeString(not_empty=False, max=255, strip=True))), + TextField(name='telefono', label=_(u'Teléfono'), + #help_text=_(u'Texto libre para teléfono, se puede incluir horarios o varias entradas.'), + validator=validators.UnicodeString(not_empty=False, min=7, max=255, strip=True)), + TextArea(name='observaciones', label=_(u'Observaciones'), + #help_text=_(u'Observaciones.'), + validator=validators.UnicodeString(not_empty=False, strip=True)), + CheckBox(name='nombrado', label=_(u'Nombrado'), default=1, + #help_text=_(u'Indica si tiene cargo.'), + validator=validators.Bool(if_empty=1)), + CheckBox(name='activo', label=_(u'Activo'), default=1, + #help_text=_(u'Si no está activo no puede ingresar al sistema.'), + validator=validators.Bool(if_empty=1)), +]) + +def minimize(text, size=15): + if text is not None and len(text) > size: + text = text[:size] + '...' + return text + +class DocenteController(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:sercom.subcontrollers.%s.templates.list' % name) + @paginate('records') + def list(self, **kw): + """List records in model""" + f = kw.get('tg_flash', None) + r = cls.select() + + return dict(records=r, name=name, namepl=namepl, tg_flash=f) + + @expose(template='kid:sercom.subcontrollers.%s.templates.new' % name) + def new(self, **kw): + """Create new records in model""" + return dict(name=name, namepl=namepl, form=form) + + @validate(form=form) + @error_handler(new) + @expose() + def create(self, **kw): + """Save or create record to model""" + Docente(**kw) + + raise redirect('list', tg_flash=_(u'Se creó un nuevo %s.') % name) + + @expose(template='kid:sercom.subcontrollers.%s.templates.edit' % name) + def edit(self, id, **kw): + """Edit record in model""" + try: + r = cls.get(int(id)) + except LookupError: + flash = _('No existe el docente con identificador %d.') % 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""" + record = cls.get(int(id)) + record.set(**kw) + + raise redirect('../list', + tg_flash=_(u'El %s fue actualizado.') % name) + + @expose(template='kid:sercom.subcontrollers.%s.templates.show' % name) + def show(self,id, **kw): + """Show record in model""" + r = cls.get(int(id)) + r.obs = publish_parts(r.observaciones, writer_name='html')['html_body'] + + return dict(name=name, namepl=namepl, record=r) + + @expose() + def delete(self, id): + """Destroy record in model""" + cls.delete(int(id)) + + raise redirect('../list', + tg_flash=_(u'El %s fue eliminado permanentemente.') % name) + diff --git a/sercom/subcontrollers/docente/templates/__init__.py b/sercom/subcontrollers/docente/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sercom/subcontrollers/docente/templates/edit.kid b/sercom/subcontrollers/docente/templates/edit.kid new file mode 100644 index 0000000..afe699e --- /dev/null +++ b/sercom/subcontrollers/docente/templates/edit.kid @@ -0,0 +1,19 @@ + + + + +edit + + + +

Modificación de Objeto

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

Administración de Objetos

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
UsuarioNombreE-MailTeléfonoNombradoActivoObservacionesOperaciones
usuarionombreemailtelefononombradoactivoobservacionesVer + Editar + Eliminar
+ +
+Agregar + +
+ ${page} + ${page} +
+ + + diff --git a/sercom/subcontrollers/docente/templates/new.kid b/sercom/subcontrollers/docente/templates/new.kid new file mode 100644 index 0000000..232f80d --- /dev/null +++ b/sercom/subcontrollers/docente/templates/new.kid @@ -0,0 +1,18 @@ + + + + +new + + + +

Crear Nuevo Objeto

+ +

Formulario

+ +
+Cancelar + + + diff --git a/sercom/subcontrollers/docente/templates/show.kid b/sercom/subcontrollers/docente/templates/show.kid new file mode 100644 index 0000000..cb9af0a --- /dev/null +++ b/sercom/subcontrollers/docente/templates/show.kid @@ -0,0 +1,45 @@ + + + + +show + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Usuario:usuario
Nombre:nombre
E-Mail:email
Teléfono:telefono
Nombrado:nombrado
Activo:activo
Observaciones:observaciones
+ +
+Editar | Volver + + + -- 2.43.0