From d9cd422b175f8e5ebb8c98d974c139586da8217d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 10 Feb 2007 00:42:00 +0000 Subject: [PATCH] =?utf8?q?Agregar=20controlador=20para=20ABM=20de=20enunci?= =?utf8?q?ados.=20Controlador=20para=20ABM=20de=20enunciados.=20Tal=20vez?= =?utf8?q?=20se=20pueda=20hacer=20una=20superclase=20para=20no=20repetir?= =?utf8?q?=20tanto=20c=C3=B3digo,=20pero=20como=20las=20personalizaciones?= =?utf8?q?=20van=20a=20ser=20cada=20vez=20m=C3=A1s=20frecuentes,=20no=20s?= =?utf8?q?=C3=A9=20si=20ser=C3=A1=20de=20mucha=20utilidad.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sercom/controllers.py | 3 +- sercom/subcontrollers/__init__.py | 1 + sercom/subcontrollers/enunciado/__init__.py | 118 ++++++++++++++++++ .../enunciado/templates/__init__.py | 0 .../enunciado/templates/edit.kid | 19 +++ .../enunciado/templates/list.kid | 42 +++++++ .../enunciado/templates/new.kid | 18 +++ .../enunciado/templates/show.kid | 29 +++++ 8 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 sercom/subcontrollers/enunciado/__init__.py create mode 100644 sercom/subcontrollers/enunciado/templates/__init__.py create mode 100644 sercom/subcontrollers/enunciado/templates/edit.kid create mode 100644 sercom/subcontrollers/enunciado/templates/list.kid create mode 100644 sercom/subcontrollers/enunciado/templates/new.kid create mode 100644 sercom/subcontrollers/enunciado/templates/show.kid diff --git a/sercom/controllers.py b/sercom/controllers.py index 5e785ea..abc3767 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -7,7 +7,7 @@ from cherrypy import request, response from model import * # from sercom import json -from subcontrollers import DocenteController +from subcontrollers import * import logging log = logging.getLogger("sercom.controllers") @@ -76,6 +76,7 @@ class Root(controllers.RootController): raise redirect('/') docente = DocenteController() + enunciado = EnunciadoController() #{{{ Agrega summarize a namespace tg de KID def summarize(text, size, concat=True, continuation='...'): diff --git a/sercom/subcontrollers/__init__.py b/sercom/subcontrollers/__init__.py index 41c6761..3ac9677 100644 --- a/sercom/subcontrollers/__init__.py +++ b/sercom/subcontrollers/__init__.py @@ -1 +1,2 @@ from docente import DocenteController +from enunciado import EnunciadoController diff --git a/sercom/subcontrollers/enunciado/__init__.py b/sercom/subcontrollers/enunciado/__init__.py new file mode 100644 index 0000000..569b2ac --- /dev/null +++ b/sercom/subcontrollers/enunciado/__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 Enunciado, Docente +from turbogears.widgets import * +from turbogears import identity +from turbogears import paginate +from docutils.core import publish_parts +from sercom.subcontrollers import validate as val + +cls = Enunciado +name = 'enunciado' +namepl = name + 's' + +def validate_autor(data): + autor = data.get('autorID', None) + if autor == 0: autor = None + if autor is not None: + try: + autor = Docente.get(autor) + except LookupError: + raise redirect('new', tg_flash=_(u'No se pudo crear el nuevo ' \ + '%s porque el autor con identificador %d no existe.' + % (name, autor)), **data) + data.pop('autorID', None) + data['autor'] = autor + +def validate_get(id): + return val.validate_get(cls, name, id) + +def validate_set(id, data): + validate_autor(data) + return val.validate_set(cls, name, id, data) + +def validate_new(data): + validate_autor(data) + return val.validate_new(cls, name, data) + +def get_options(): + return [(0, _(u'--'))] + [(a.id, a.shortrepr()) for a in Docente.select()] + +form = TableForm(fields=[ + TextField(name='nombre', label=_(u'Nombre'), + help_text=_(u'Requerido y único.'), + validator=validators.UnicodeString(min=5, max=60, strip=True)), + SingleSelectField(name='autorID', label=_(u'Autor'), + options=get_options, validator=validators.Int(not_empty=False)), + TextField(name='descripcion', label=_(u'Descripción'), + validator=validators.UnicodeString(not_empty=False, max=255, strip=True)), +]) + +class EnunciadoController(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""" + f = kw.get('tg_flash', None) + return dict(name=name, namepl=namepl, form=form, tg_flash=f, values=kw) + + @validate(form=form) + @error_handler(new) + @expose() + def create(self, **kw): + """Save or create record to model""" + validate_new(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""" + r = validate_get(id) + return dict(name=name, namepl=namepl, record=r, form=form, + tg_flash=kw.get('tg_flash', None)) + + @validate(form=form) + @error_handler(edit) + @expose() + def update(self, id, **kw): + """Save or create record to model""" + r = validate_set(id, 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 = validate_get(id) + r.desc = publish_parts(r.descripcion, writer_name='html')['html_body'] + return dict(name=name, namepl=namepl, record=r) + + @expose() + def delete(self, id): + """Destroy record in model""" + r = validate_get(id) + r.destroySelf() + raise redirect('../list', + tg_flash=_(u'El %s fue eliminado permanentemente.') % name) + diff --git a/sercom/subcontrollers/enunciado/templates/__init__.py b/sercom/subcontrollers/enunciado/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sercom/subcontrollers/enunciado/templates/edit.kid b/sercom/subcontrollers/enunciado/templates/edit.kid new file mode 100644 index 0000000..afe699e --- /dev/null +++ b/sercom/subcontrollers/enunciado/templates/edit.kid @@ -0,0 +1,19 @@ + + + + +edit + + + +

Modificación de Objeto

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

Administración de Objetos

+ + + + + + + + + + + + + + +
NombreDescripciónAutorOperaciones
nombredescripciónautorEditar + Eliminar
+ +
+Agregar + +
+ ${page} + ${page} +
+ + + + + diff --git a/sercom/subcontrollers/enunciado/templates/new.kid b/sercom/subcontrollers/enunciado/templates/new.kid new file mode 100644 index 0000000..c7e0d4b --- /dev/null +++ b/sercom/subcontrollers/enunciado/templates/new.kid @@ -0,0 +1,18 @@ + + + + +new + + + +

Crear Nuevo Objeto

+ +

Formulario

+ +
+Cancelar + + + diff --git a/sercom/subcontrollers/enunciado/templates/show.kid b/sercom/subcontrollers/enunciado/templates/show.kid new file mode 100644 index 0000000..e788e67 --- /dev/null +++ b/sercom/subcontrollers/enunciado/templates/show.kid @@ -0,0 +1,29 @@ + + + + +show + + + + + + + + + + + + + + + + +
Nombre:nombre
Descripción:descripcion
Autor:autor
+ +
+Editar | Volver + + + -- 2.43.0