1 # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker :
5 from turbogears import controllers, expose, redirect, url
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()]
37 class DocenteInscriptoForm(W.TableForm):
38 class Fields(W.WidgetsList):
39 cursoID = W.HiddenField()
40 docente = W.SingleSelectField(label=_(u'Docente'), options = get_docentes,
41 validator = V.Int(not_empty=True))
43 corrige = W.CheckBox(label=_(u'Corrige?'))
45 observaciones = W.TextArea(name='observaciones', label=_(u'Observaciones'),
46 validator=V.UnicodeString(not_empty=False, strip=True))
49 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")]
50 form = DocenteInscriptoForm()
54 class DocenteInscriptoController(controllers.Controller, identity.SecureResource):
55 """Basic model admin interface"""
56 require = identity.has_permission('admin')
59 def default(self, tg_errors=None):
60 """handle non exist urls"""
61 raise redirect(url('/curso/list'))
65 raise redirect(url('/curso/list'))
68 @expose(template='kid:%s.templates.list' % __name__)
70 def list(self, cursoID):
71 """List records in model"""
72 r = cls.select(cls.q.cursoID==cursoID)
73 return dict(records=r, name=name, namepl=namepl, curso=Curso.get(cursoID))
75 @expose(template='kid:%s.templates.new' % __name__)
76 def new(self, cursoID, **kw):
77 """Create new records in model"""
78 form.fields[0].attrs['value'] = cursoID
79 return dict(name=name, namepl=namepl, form=form, values=kw, curso=Curso.get(cursoID))
84 def create(self, **kw):
85 """Save or create record to model"""
87 flash(_(u'Se creó un nuevo %s.') % name)
88 raise redirect(url('/curso/docente/list/%d' % r.curso.id))
90 @expose(template='kid:%s.templates.edit' % __name__)
91 def edit(self, id, **kw):
92 """Edit record in model"""
98 values.docente = r.docente.id
99 values.corrige = r.corrige
100 values.observaciones = r.observaciones
101 values.curso = r.curso
102 values.cursoID = r.curso.id
103 return dict(name=name, namepl=namepl, record=values, 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(url('/curso/docente/list/%d' % r.curso.id))
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, cursoID, id):
122 """Destroy record in model"""
125 flash(_(u'El %s fue eliminado permanentemente.') % name)
126 raise redirect(url('/curso/docente/list/%s' % cursoID))