From: Ricardo Markiewicz Date: Sun, 25 Feb 2007 19:43:06 +0000 (+0000) Subject: Ejercicios X-Git-Url: https://git.llucax.com/software/sercom.git/commitdiff_plain/65b45e5ceacbabe6f5851b83a57e94fe72ab0317?ds=sidebyside Ejercicios --- diff --git a/sercom/controllers.py b/sercom/controllers.py index 0c4186e..b1e8ed1 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -83,6 +83,8 @@ class Root(controllers.RootController): enunciado = EnunciadoController() + ejercicio = EjercicioController() + caso_de_prueba = CasoDePruebaController() curso = CursoController() diff --git a/sercom/subcontrollers/__init__.py b/sercom/subcontrollers/__init__.py index 0f340da..f650c14 100644 --- a/sercom/subcontrollers/__init__.py +++ b/sercom/subcontrollers/__init__.py @@ -3,3 +3,4 @@ from alumno import AlumnoController from curso import CursoController from enunciado import EnunciadoController from caso_de_prueba import CasoDePruebaController +from ejercicio import EjercicioController diff --git a/sercom/subcontrollers/ejercicio/__init__.py b/sercom/subcontrollers/ejercicio/__init__.py new file mode 100644 index 0000000..f0b0157 --- /dev/null +++ b/sercom/subcontrollers/ejercicio/__init__.py @@ -0,0 +1,173 @@ +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : + +#{{{ Imports +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 Ejercicio, Curso, Enunciado +from cherrypy import request, response +#}}} + +#{{{ Configuración +cls = Ejercicio +name = 'ejercicio' +namepl = name + 's' + +fkcls = Curso +fkname = 'curso' +fknamepl = fkname + 's' + +fk1cls = Enunciado +fk1name = 'enunciado' +fk1namepl = fk1name + 's' +#}}} + +#{{{ Validación +def validate_fk(data): + fk = data.get(fkname + 'ID', None) + if fk == 0: fk = None + if fk is not None: + try: + fk = fkcls.get(fk) + except LookupError: + flash(_(u'No se pudo crear el nuevo %s porque el %s con ' + 'identificador %d no existe.' % (name, fkname, fk))) + raise redirect('new', **data) + data.pop(fkname + 'ID', None) + data[fkname] = fk + return fk + +def validate_fk1(data): + fk = data.get(fk1name + 'ID', None) + if fk == 0: fk = None + if fk is not None: + try: + fk = fk1cls.get(fk) + except LookupError: + flash(_(u'No se pudo crear el nuevo %s porque el %s con ' + 'identificador %d no existe.' % (name, fk1name, fk))) + raise redirect('new', **data) + data.pop(fk1name + 'ID', None) + data[fk1name] = fk + return fk + +def validate_get(id): + return val.validate_get(cls, name, id) + +def validate_set(id, data): + validate_fk(data) + validate_fk1(data) + return val.validate_set(cls, name, id, data) + +def validate_new(data): + validate_fk(data) + validate_fk1(data) + return val.validate_new(cls, name, data) +#}}} + +#{{{ Formulario +def get_options(): + return [(0, _(u'--'))] + [(fk.id, fk.shortrepr()) for fk in fkcls.select()] + +def get_options1(): + return [(0, _(u'--'))] + [(fk1.id, fk1.shortrepr()) for fk1 in fk1cls.select()] + +class EjercicioForm(W.TableForm): + class Fields(W.WidgetsList): + fk = W.SingleSelectField(name=fkname+'ID', label=_(fkname.capitalize()), + options=get_options, validator=V.Int(not_empty=True)) + numero = W.TextField(name="numero",label=_(u'Nro'), + help_text=_(u'Requerido.'), + validator=V.Int(not_empty=True)) + fk1 = W.SingleSelectField(name=fk1name+'ID', label=_(fk1name.capitalize()), + options=get_options1, validator=V.Int(not_empty=True)) + grupal = W.CheckBox(name='grupal', label=_(u"Grupal?")) + fields = Fields() + javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")] + +form = EjercicioForm() +#}}} + +#{{{ Controlador +class EjercicioController(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__) + @validate(validators=dict(autor=V.Int)) + @paginate('records') + def list(self, autor=None): + """List records in model""" + r = cls.select() + return dict(records=r, name=name, namepl=namepl, parcial=autor) + + @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) + if r.descripcion is None: + r.desc = '' + else: + 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() + flash(_(u'El %s fue eliminado permanentemente.') % name) + raise redirect('../list') + + @expose() + def files(self, id): + r = validate_get(id) + response.headers["Content-Type"] = r.archivo_type + response.headers["Content-disposition"] = "attachment;filename=%s" % (r.archivo_name) + flash(_(u'El %s fue eliminado permanentemente.') % name) + return r.archivo +#}}} + diff --git a/sercom/subcontrollers/ejercicio/templates/__init__.py b/sercom/subcontrollers/ejercicio/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sercom/subcontrollers/ejercicio/templates/edit.kid b/sercom/subcontrollers/ejercicio/templates/edit.kid new file mode 100644 index 0000000..319fcaa --- /dev/null +++ b/sercom/subcontrollers/ejercicio/templates/edit.kid @@ -0,0 +1,20 @@ + + + + +edit + + + +

Modificación de Objeto

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

Administración de Objetos

+ + + + + + + + + + + + + + + + +
CursoNumeroEnunciadoEs Grupal?Operaciones
cursonumeroenunciado + grupal + + Editar + Eliminar +
+ +
+Agregar +Ver todo + +
+ ${page} + ${page} +
+ + + + + diff --git a/sercom/subcontrollers/ejercicio/templates/new.kid b/sercom/subcontrollers/ejercicio/templates/new.kid new file mode 100644 index 0000000..18f4fa0 --- /dev/null +++ b/sercom/subcontrollers/ejercicio/templates/new.kid @@ -0,0 +1,18 @@ + + + + +new + + + +

Crear Nuevo Objeto

+ +

Formulario

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