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, Curso, Docente
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)
35 return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()]
38 return [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()]
40 class DocenteInscriptoForm(W.TableForm):
41 class Fields(W.WidgetsList):
42 curso = W.SingleSelectField(label=_(u'Curso'), options = get_cursos,
43 validator = V.Int(not_empty=True))
45 docente = W.SingleSelectField(label=_(u'Docente'), options = get_docentes,
46 validator = V.Int(not_empty=True))
48 corrige = W.CheckBox(label=_(u'Corrige'))
50 observaciones = W.TextArea(name='observaciones', label=_(u'Observaciones'),
51 validator=V.UnicodeString(not_empty=False, strip=True))
54 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")]
55 form = DocenteInscriptoForm()
59 class DocenteInscriptoController(controllers.Controller, identity.SecureResource):
60 """Basic model admin interface"""
61 require = identity.has_permission('admin')
64 def default(self, tg_errors=None):
65 """handle non exist urls"""
66 raise redirect('list')
70 raise redirect('list')
72 @expose(template='kid:%s.templates.list' % __name__)
75 """List records in model"""
77 return dict(records=r, name=name, namepl=namepl)
80 def activate(self, id, activo):
81 """Save or create record to model"""
83 raise redirect('../../list')
85 @expose(template='kid:%s.templates.new' % __name__)
87 """Create new records in model"""
88 return dict(name=name, namepl=namepl, form=form, values=kw)
93 def create(self, **kw):
94 """Save or create record to model"""
96 flash(_(u'Se creó un nuevo %s.') % name)
97 raise redirect('list')
99 @expose(template='kid:%s.templates.edit' % __name__)
100 def edit(self, id, **kw):
101 """Edit record in model"""
103 return dict(name=name, namepl=namepl, record=r, form=form)
108 def update(self, id, **kw):
109 """Save or create record to model"""
110 r = validate_set(id, kw)
111 flash(_(u'El %s fue actualizado.') % name)
112 raise redirect('../list')
114 @expose(template='kid:%s.templates.show' % __name__)
115 def show(self,id, **kw):
116 """Show record in model"""
118 return dict(name=name, namepl=namepl, record=r)
121 def delete(self, id):
122 """Destroy record in model"""
125 flash(_(u'El %s fue eliminado permanentemente.') % name)
126 raise redirect('../list')