1 # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker :
5 from turbogears import controllers, expose, redirect
6 from turbogears import validate, flash, error_handler
7 from turbogears import validators as V
8 from turbogears import widgets as W
9 from turbogears import identity
10 from turbogears import paginate
11 from docutils.core import publish_parts
12 from sercom.subcontrollers import validate as val
13 from sercom.model import Curso, Ejercicio, Alumno, Docente, Grupo
24 return val.validate_get(cls, name, id)
26 def validate_set(id, data):
27 return val.validate_set(cls, name, id, data)
29 def validate_new(data):
30 return val.validate_new(cls, name, data)
34 return [(fk1.id, fk1.shortrepr()) for fk1 in Ejercicio.select()]
37 return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()]
40 return [(fk1.id, fk1.shortrepr()) for fk1 in Alumno.select()]
43 return [(fk1.id, fk1.shortrepr()) for fk1 in Grupo.select()]
46 class CursoForm(W.TableForm):
47 class Fields(W.WidgetsList):
48 anio = W.TextField(label=_(u'Anio'),
49 help_text=_(u'Requerido y único.'),
50 validator=V.Number(min=4, max=4, strip=True))
51 cuatrimestre = W.TextField(label=_(u'Cuatrimestre'),
52 help_text=_(u'Requerido.'),
53 validator=V.Number(min=1, max=1, strip=True))
54 numero = W.TextField(label=_(u'Numero'),
55 help_text=_(u'Requerido'),
56 validator=V.Number(min=1, max=2, strip=True))
57 descripcion = W.TextArea(name='descripcion', label=_(u'Descripcion'),
58 help_text=_(u'Descripcion.'),
59 validator=V.UnicodeString(not_empty=False, strip=True))
60 # docentes = W.MultipleSelectField(name="docentes", label=_(u'Docentes'),
61 # help_text=_(u'Docentes asignados al curso'), options=get_docentes,
62 # validator=V.Int(not_empty=True))
63 # alumnos = W.MultipleSelectField(name="alumnos", label=_(u'Alumnos'),
64 # help_text=_(u'Alumnos del curso'), options=get_alumnos,
65 # validator=V.Int(not_empty=True))
66 # grupos = W.MultipleSelectField(name="grupos", label=_(u'Grupos'),
67 # help_text=_(u'Grupos del curso'), options=get_grupos,
68 # validator=V.Int(not_empty=False))
69 # ejercicios = W.MultipleSelectField(name="ejercicios", label=_(u'Ejercicios'),
70 # help_text=_(u'Ejercicios'), options=get_ejercicios,
71 # validator=V.Int(not_empty=True))
73 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('anio');")]
78 class CursoController(controllers.Controller, identity.SecureResource):
79 """Basic model admin interface"""
80 require = identity.has_permission('admin')
83 def default(self, tg_errors=None):
84 """handle non exist urls"""
85 raise redirect('list')
89 raise redirect('list')
91 @expose(template='kid:%s.templates.list' % __name__)
94 """List records in model"""
96 return dict(records=r, name=name, namepl=namepl)
99 def activate(self, id, activo):
100 """Save or create record to model"""
103 r.activo = bool(int(activo))
105 raise cherrypy.NotFound
106 raise redirect('../../list')
108 @expose(template='kid:%s.templates.new' % __name__)
110 """Create new records in model"""
111 return dict(name=name, namepl=namepl, form=form, values=kw)
116 def create(self, **kw):
117 """Save or create record to model"""
119 flash(_(u'Se creó un nuevo %s.') % name)
120 raise redirect('list')
122 @expose(template='kid:%s.templates.edit' % __name__)
123 def edit(self, id, **kw):
124 """Edit record in model"""
126 return dict(name=name, namepl=namepl, record=r, form=form)
131 def update(self, id, **kw):
132 """Save or create record to model"""
133 r = validate_set(id, kw)
134 flash(_(u'El %s fue actualizado.') % name)
135 raise redirect('../list')
137 @expose(template='kid:%s.templates.show' % __name__)
138 def show(self,id, **kw):
139 """Show record in model"""
141 return dict(name=name, namepl=namepl, record=r)
144 def delete(self, id):
145 """Destroy record in model"""
148 flash(_(u'El %s fue eliminado permanentemente.') % name)
149 raise redirect('../list')