def from_file_add(self, id, archivo): """ Se espera : padron,nombre,email,telefono """ import csv lines = archivo.file.read().split('\n') ok = [] fail = [] curso = Curso.get(int(id)) 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')]) except: u = Alumno.byPadron(row[0]) try: u.email = row[2] u.telefono = row[3] u.password = row[0] u.activo = True curso.add_alumno(u) ok.append(row) except Exception, e: row.append(str(e)) fail.append(row)
def create(self, **kw): """Save or create record to model""" cursoId = kw['cursoID'] padron_responsable = kw['responsable'] try: # Busco el alumno inscripto resp = AlumnoInscripto.selectBy(cursoID=cursoId, alumno=Alumno.byPadron(padron_responsable)).getOne() except SQLObjectNotFound: resp = None kw['responsable'] = resp create_record(cursoId, kw)
def update(self, id, **kw): """Save or create record to model""" responsable = kw['responsable'] curso = kw['cursoID'] resp = kw['responsable'] try: # Busco el alumno inscripto resp = AlumnoInscripto.selectBy(cursoID=kw['cursoID'], alumno=Alumno.byPadron(kw['responsable'])).getOne() except SQLObjectNotFound: resp = None kw['responsable'] = resp r = validate_set(id, kw) flash(_(u'El %s fue actualizado.') % name) raise redirect('../list/%d' % r.curso.id)
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.nombre 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' % unicode(inst) error = True