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, AlumnoInscripto, 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)
35 return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()]
38 return [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()]
40 class GrupoForm(W.TableForm):
41 class Fields(W.WidgetsList):
42 curso = W.SingleSelectField(label=_(u'Curso'), options = get_cursos,
43 validator = V.Int(not_empty=True))
44 nombre = W.TextField(label=_(u'Nombre'), validator=V.UnicodeString(not_empty=True,strip=True))
47 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")]
54 class GrupoController(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('list')
65 raise redirect('list')
67 @expose(template='kid:%s.templates.list' % __name__)
70 """List records in model"""
72 return dict(records=r, name=name, namepl=namepl)
75 def activate(self, id, activo):
76 """Save or create record to model"""
78 raise redirect('../../list')
80 @expose(template='kid:%s.templates.new' % __name__)
82 """Create new records in model"""
83 return dict(name=name, namepl=namepl, form=form, values=kw)
88 def create(self, **kw):
89 """Save or create record to model"""
91 flash(_(u'Se creó un nuevo %s.') % name)
92 raise redirect('list')
94 @expose(template='kid:%s.templates.edit' % __name__)
95 def edit(self, id, **kw):
96 """Edit record in model"""
98 return dict(name=name, namepl=namepl, record=r, form=form)
103 def update(self, id, **kw):
104 """Save or create record to model"""
105 r = validate_set(id, kw)
106 flash(_(u'El %s fue actualizado.') % name)
107 raise redirect('../list')
109 @expose(template='kid:%s.templates.show' % __name__)
110 def show(self,id, **kw):
111 """Show record in model"""
113 return dict(name=name, namepl=namepl, record=r)
116 def delete(self, id):
117 """Destroy record in model"""
120 flash(_(u'El %s fue eliminado permanentemente.') % name)
121 raise redirect('../list')