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
23 fknamepl = fkname + 's'
27 def validate_fk(data):
28 fk = data.get(fkname + 'ID', None)
34 flash(_(u'No se pudo crear el nuevo %s porque el %s con '
35 'identificador %d no existe.' % (name, fkname, fk)))
36 raise redirect('new', **data)
37 data.pop(fkname + 'ID', None)
42 return val.validate_get(cls, name, id)
44 def validate_set(id, data):
46 return val.validate_set(cls, name, id, data)
48 def validate_new(data):
50 return val.validate_new(cls, name, data)
55 return [(fk1.id, fk1.shortrepr()) for fk1 in Docente.select()]
58 return [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()]
60 class GrupoForm(W.TableForm):
61 class Fields(W.WidgetsList):
62 curso = W.SingleSelectField(name='cursoID', label=_(u'Curso'), options = get_cursos,
63 validator = V.Int(not_empty=True))
64 nombre = W.TextField(label=_(u'Nombre'), validator=V.UnicodeString(not_empty=True,strip=True))
67 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('curso');")]
74 class GrupoController(controllers.Controller, identity.SecureResource):
75 """Basic model admin interface"""
76 require = identity.has_permission('admin')
79 def default(self, tg_errors=None):
80 """handle non exist urls"""
81 raise redirect('list')
85 raise redirect('list')
87 @expose(template='kid:%s.templates.list' % __name__)
90 """List records in model"""
92 return dict(records=r, name=name, namepl=namepl)
95 def activate(self, id, activo):
96 """Save or create record to model"""
98 raise redirect('../../list')
100 @expose(template='kid:%s.templates.new' % __name__)
102 """Create new records in model"""
103 return dict(name=name, namepl=namepl, form=form, values=kw)
108 def create(self, **kw):
109 """Save or create record to model"""
111 flash(_(u'Se creó un nuevo %s.') % name)
112 raise redirect('list')
114 @expose(template='kid:%s.templates.edit' % __name__)
115 def edit(self, id, **kw):
116 """Edit record in model"""
118 return dict(name=name, namepl=namepl, record=r, form=form)
123 def update(self, id, **kw):
124 """Save or create record to model"""
125 r = validate_set(id, kw)
126 flash(_(u'El %s fue actualizado.') % name)
127 raise redirect('../list')
129 @expose(template='kid:%s.templates.show' % __name__)
130 def show(self,id, **kw):
131 """Show record in model"""
133 return dict(name=name, namepl=namepl, record=r)
136 def delete(self, id):
137 """Destroy record in model"""
140 flash(_(u'El %s fue eliminado permanentemente.') % name)
141 raise redirect('../list')