]> git.llucax.com Git - software/sercom.git/commitdiff
ABM de Tarea Fuente.
authorRicardo Markiewicz <rmarkie@fi.uba.ar>
Wed, 14 Mar 2007 04:09:01 +0000 (04:09 +0000)
committerRicardo Markiewicz <rmarkie@fi.uba.ar>
Wed, 14 Mar 2007 04:09:01 +0000 (04:09 +0000)
sercom/controllers.py
sercom/subcontrollers/__init__.py
sercom/subcontrollers/tarea_fuente/__init__.py [new file with mode: 0644]
sercom/subcontrollers/tarea_fuente/templates/__init__.py [new file with mode: 0644]
sercom/subcontrollers/tarea_fuente/templates/edit.kid [new file with mode: 0644]
sercom/subcontrollers/tarea_fuente/templates/list.kid [new file with mode: 0644]
sercom/subcontrollers/tarea_fuente/templates/new.kid [new file with mode: 0644]
sercom/subcontrollers/tarea_fuente/templates/show.kid [new file with mode: 0644]

index 732755b840b7f0c75d8dcf93d81befd4223f853f..ed65ccefe929640e79c295cc31999d7d4d5235fb 100644 (file)
@@ -119,6 +119,8 @@ class Root(controllers.RootController):
 
     ejercicio = EjercicioController()
 
+    tarea_fuente = TareaFuenteController()
+
     caso_de_prueba = CasoDePruebaController()
 
     curso = CursoController()
index 906540c40e08abd04e76daea33fc8793ff59fe95..b20fd272a4607e276b3e018e13b134f8e1154b5c 100644 (file)
@@ -10,3 +10,4 @@ from correccion import CorreccionController
 from misentregas import MisEntregasController
 from grupo_admin import GrupoAdminController
 from miscorrecciones import MisCorreccionesController
+from tarea_fuente import TareaFuenteController
diff --git a/sercom/subcontrollers/tarea_fuente/__init__.py b/sercom/subcontrollers/tarea_fuente/__init__.py
new file mode 100644 (file)
index 0000000..25d773f
--- /dev/null
@@ -0,0 +1,110 @@
+# 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 TareaFuente 
+from sqlobject import *
+#}}}
+
+#{{{ Configuración
+cls = TareaFuente
+name = 'tarea fuente'
+namepl = 'tareas fuente'
+#}}}
+
+#{{{ 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
+class TareaFuenteForm(W.TableForm):
+    class Fields(W.WidgetsList):
+        nombre = W.TextField(label=_(u'Nombre'),validator=V.UnicodeString(min=3, max=30, strip=True))
+        descripcion = W.TextField(label=_(u'Descripcion'),
+            validator=V.UnicodeString(not_empty=False, max=255, strip=True))
+    fields = Fields()
+    javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")]
+
+form = TareaFuenteForm()
+#}}}
+
+#{{{ Controlador
+class TareaFuenteController(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(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/tarea_fuente/templates/__init__.py b/sercom/subcontrollers/tarea_fuente/templates/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sercom/subcontrollers/tarea_fuente/templates/edit.kid b/sercom/subcontrollers/tarea_fuente/templates/edit.kid
new file mode 100644 (file)
index 0000000..9f9b04f
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+    py:extends="'../../../templates/master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
+<title>edit</title>
+</head>
+<body>
+
+<h1>Modificación de <span py:replace="name">Objeto</span></h1>
+
+<div py:replace="form(value=record, action=tg.url('/tarea_fuente/update/%d' % record.id),
+       submit_text=_(u'Guardar'))">Formulario</div>
+
+<br/>
+<a href="${tg.url('/tarea_fuente/show/%d' % record.id)}">Ver (cancela)</a> |
+<a href="${tg.url('/tarea_fuente/list')}">Volver (cancela)</a>
+
+</body>
+</html>
diff --git a/sercom/subcontrollers/tarea_fuente/templates/list.kid b/sercom/subcontrollers/tarea_fuente/templates/list.kid
new file mode 100644 (file)
index 0000000..041a8b0
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+    py:extends="'../../../templates/master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
+<title>list</title>
+</head>
+<body>
+
+<h1>Administración de <span py:replace="namepl">Objetos</span></h1>
+
+<table class="list">
+    <tr>
+        <th>Nombre</th>
+        <th>Descripcion</th>
+        <th>Operaciones</th>
+    </tr>
+    <tr py:for="record in records">
+        <td><span py:replace="record.nombre">nombre</span></td>
+        <td><span py:replace="record.descripcion">nota</span></td>
+        <td><a href="${tg.url('/tarea_fuente/edit/%d' % record.id)}">Editar</a>
+            <a href="${tg.url('/tarea_fuente/delete/%d' % record.id)}" onclick="if (confirm('${_(u'Estás seguro? Tal vez sólo quieras desactivarlo mejor...')}')) { var f = document.createElement('form'); this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;">Eliminar</a></td>
+    </tr>
+</table>
+
+<br/>
+<a href="${tg.url('/tarea_fuente/new')}">Agregar</a>
+
+<div py:for="page in tg.paginate.pages">
+    <a py:if="page != tg.paginate.current_page"
+        href="${tg.paginate.get_href(page)}">${page}</a>
+    <b py:if="page == tg.paginate.current_page">${page}</b>
+</div>
+
+</body>
+</html>
+
+<!-- vim: set et sw=4 sts=4 : -->
diff --git a/sercom/subcontrollers/tarea_fuente/templates/new.kid b/sercom/subcontrollers/tarea_fuente/templates/new.kid
new file mode 100644 (file)
index 0000000..a5f3168
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+    py:extends="'../../../templates/master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
+<title>new</title>
+</head>
+<body>
+
+<h1>Crear Nuevo <span py:replace="name">Objeto</span></h1>
+
+<p py:replace="form(action=tg.url('/tarea_fuente/create'), value=values, submit_text=_('Crear'))">Formulario</p>
+
+<br/>
+<a href="${tg.url('/tarea_fuente/list')}">Cancelar</a>
+
+</body>
+</html>
diff --git a/sercom/subcontrollers/tarea_fuente/templates/show.kid b/sercom/subcontrollers/tarea_fuente/templates/show.kid
new file mode 100644 (file)
index 0000000..1957468
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+    py:extends="'../../../templates/master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
+<title>show</title>
+</head>
+<body>
+
+<table class="show">
+    <tr>
+        <th>Nombre:</th>
+       <td><span py:replace="record.nombre">nombre</span></td>
+    </tr>
+    <tr>
+        <th>Descripcion:</th>
+       <td><span py:replace="record.descripcion">nombre</span></td>
+    </tr>
+</table>
+
+<br/>
+<a href="${tg.url('/tarea_fuente/edit/%d' % record.id)}">Editar</a> |
+<a href="${tg.url('/tarea_fuente/list')}">Volver</a>
+
+</body>
+</html>