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
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 class CursoForm(W.TableForm):
35 class Fields(W.WidgetsList):
36 anio = W.TextField(label=_(u'Anio'),
37 help_text=_(u'Requerido y único.'),
38 validator=V.Number(min=4, max=4, strip=True))
39 cuatrimestre = W.TextField(label=_(u'Cuatrimestre'),
40 help_text=_(u'Requerido.'),
41 validator=V.Number(min=1, max=1, strip=True))
42 numero = W.TextField(label=_(u'Numero'),
43 help_text=_(u'Requerido'),
44 validator=V.Number(min=1, max=2, strip=True))
45 descripcion = W.TextArea(name='descripcion', label=_(u'Descripcion'),
46 help_text=_(u'Descripcion.'),
47 validator=V.UnicodeString(not_empty=False, strip=True))
48 docentes = W.MultipleSelectField(name="docentes", label=_(u'Docentes'),
49 help_text=_(u'Docentes asignados al curso'),
50 validator=V.UnicodeString(not_empty=True))
51 alumnos = W.MultipleSelectField(name="alumnos", label=_(u'Alumnos'),
52 help_text=_(u'Alumnos del curso'),
53 validator=V.UnicodeString(not_empty=True))
54 grupos = W.MultipleSelectField(name="grupos", label=_(u'Grupos'),
55 help_text=_(u'Grupos del curso'),
56 validator=V.UnicodeString(not_empty=True))
57 ejercicios = W.MultipleSelectField(name="ejercicios", label=_(u'Ejercicios'),
58 help_text=_(u'Ejercicios'),
59 validator=V.UnicodeString(not_empty=True))
61 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('anio');")]
66 class CursoController(controllers.Controller, identity.SecureResource):
67 """Basic model admin interface"""
68 require = identity.has_permission('admin')
71 def default(self, tg_errors=None):
72 """handle non exist urls"""
73 raise redirect('list')
77 raise redirect('list')
79 @expose(template='kid:%s.templates.list' % __name__)
82 """List records in model"""
84 return dict(records=r, name=name, namepl=namepl)
87 def activate(self, id, activo):
88 """Save or create record to model"""
91 r.activo = bool(int(activo))
93 raise cherrypy.NotFound
94 raise redirect('../../list')
96 @expose(template='kid:%s.templates.new' % __name__)
98 """Create new records in model"""
99 return dict(name=name, namepl=namepl, form=form, values=kw)
104 def create(self, **kw):
105 """Save or create record to model"""
107 flash(_(u'Se creó un nuevo %s.') % name)
108 raise redirect('list')
110 @expose(template='kid:%s.templates.edit' % __name__)
111 def edit(self, id, **kw):
112 """Edit record in model"""
114 return dict(name=name, namepl=namepl, record=r, form=form)
119 def update(self, id, **kw):
120 """Save or create record to model"""
121 r = validate_set(id, kw)
122 flash(_(u'El %s fue actualizado.') % name)
123 raise redirect('../list')
125 @expose(template='kid:%s.templates.show' % __name__)
126 def show(self,id, **kw):
127 """Show record in model"""
129 return dict(name=name, namepl=namepl, record=r)
132 def delete(self, id):
133 """Destroy record in model"""
136 flash(_(u'El %s fue eliminado permanentemente.') % name)
137 raise redirect('../list')