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 DocenteInscripto
17 cls = DocenteInscripto
18 name = 'Docente Inscripto'
19 namepl = 'Docentes Inscriptos'
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 DocenteInscriptoForm(W.TableForm):
35 class Fields(W.WidgetsList):
36 curso = W.SingleSelectField(label=_(u'Curso'),
37 help_text=_(u'Requerido'),
38 docente = W.SingleSelectField(label=_(u'Docente'),
39 help_text=_(u'Requerido'),
40 corrige = W.CheckBoxField(label=_(u'Corrige'), options=[(1='Corrige')],
41 help_text=_(u'Requerido.'),
42 validator=V.Number(min=1, max=1, strip=True))
43 observaciones = W.TextArea(name='observaciones', label=_(u'Observaciones'),
44 help_text=_(u'Observaciones'),
45 validator=V.UnicodeString(not_empty=False, strip=True))
46 #alumnos = W.MultipleSelectField(name="alumnos", label=_(u'Alumnos'),
47 # help_text=_(u'Alumnos del DocenteInscripto'),
48 # validator=V.UnicodeString(not_empty=True))
50 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")]
51 form = DocenteInscriptoForm()
55 class DocenteInscriptoController(controllers.Controller, identity.SecureResource):
56 """Basic model admin interface"""
57 require = identity.has_permission('admin')
60 def default(self, tg_errors=None):
61 """handle non exist urls"""
62 raise redirect('list')
66 raise redirect('list')
68 @expose(template='kid:%s.templates.list' % __name__)
71 """List records in model"""
73 return dict(records=r, name=name, namepl=namepl)
76 def activate(self, id, activo):
77 """Save or create record to model"""
79 raise redirect('../../list')
81 @expose(template='kid:%s.templates.new' % __name__)
83 """Create new records in model"""
84 return dict(name=name, namepl=namepl, form=form, values=kw)
89 def create(self, **kw):
90 """Save or create record to model"""
92 flash(_(u'Se creó un nuevo %s.') % name)
93 raise redirect('list')
95 @expose(template='kid:%s.templates.edit' % __name__)
96 def edit(self, id, **kw):
97 """Edit record in model"""
99 return dict(name=name, namepl=namepl, record=r, form=form)
104 def update(self, id, **kw):
105 """Save or create record to model"""
106 r = validate_set(id, kw)
107 flash(_(u'El %s fue actualizado.') % name)
108 raise redirect('../list')
110 @expose(template='kid:%s.templates.show' % __name__)
111 def show(self,id, **kw):
112 """Show record in model"""
114 return dict(name=name, namepl=namepl, record=r)
117 def delete(self, id):
118 """Destroy record in model"""
121 flash(_(u'El %s fue eliminado permanentemente.') % name)
122 raise redirect('../list')