X-Git-Url: https://git.llucax.com/z.facultad/75.52/sercom.git/blobdiff_plain/e9571fa510c7719a5b3e59a795fe8b7625112f3d..2cc63705e0752cf7fdd0bbc2660904b94f2d65be:/sercom/subcontrollers/alumno/__init__.py diff --git a/sercom/subcontrollers/alumno/__init__.py b/sercom/subcontrollers/alumno/__init__.py index 9e8c476..7dd7f01 100644 --- a/sercom/subcontrollers/alumno/__init__.py +++ b/sercom/subcontrollers/alumno/__init__.py @@ -10,7 +10,8 @@ from turbogears import identity from turbogears import paginate from docutils.core import publish_parts from sercom.subcontrollers import validate as val -from sercom.model import Alumno +from sercom.model import Alumno, Rol +from sqlobject import * #}}} #{{{ Configuración @@ -106,6 +107,7 @@ class AlumnoController(controllers.Controller, identity.SecureResource): @expose() def create(self, **kw): """Save or create record to model""" + kw['roles'] = [Rol.by_nombre('alumno')] validate_new(kw) flash(_(u'Se creó un nuevo %s.') % name) raise redirect('list') @@ -142,5 +144,56 @@ class AlumnoController(controllers.Controller, identity.SecureResource): r.destroySelf() flash(_(u'El %s fue eliminado permanentemente.') % name) raise redirect('../list') + + @expose(template='kid:%s.templates.from_file' % __name__) + def from_file(self): + return dict() + + @expose(template='kid:%s.templates.import_results' % __name__) + def from_file_add(self, archivo): + """ Se espera : + padron,nombre,email,telefono + """ + import csv + lines = archivo.file.read().split('\n') + ok = [] + fail = [] + entregador = Rol.get(2) + for line in lines: + for row in csv.reader([line]): + if row == []: + continue + try: + u = Alumno(row[0], nombre=row[1], roles=[Rol.by_nombre('alumno')]) + u.email = row[2] + u.telefono = row[3] + u.password = row[0] + u.activo = True + u.add_rol(entregador) + ok.append(row) + except Exception, e: + row.append(str(e)) + fail.append(row) + return dict(ok=ok, fail=fail) + + @expose('json') + def get_alumno(self, padron): + msg = u'' + error=False + try: + # Busco el alumno inscripto + alumno = Alumno.byPadron(padron=padron) + msg = {} + msg['id'] = alumno.id + msg['value'] = alumno.shortrepr() + except SQLObjectNotFound: + msg = 'No existe el alumno con padron: %s.' % padron + error=True + except Exception, (inst): + msg = u"""Se ha producido un error inesperado al buscar el registro:\n %s""" % str(inst) + error = True + return dict(msg=msg, error=error) + + #}}}