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 resumen_por_alumno(self,alumno_id=None): """Lista un resumen de entregas y correcciones para una alumno dado""" curso = self.get_curso_actual() if alumno_id: alumno = Alumno.get(alumno_id) r = alumno.get_resumen_entregas(curso) else: r = [] alumnos = [(ai.alumno.id, ai.alumno) for ai in sorted(curso.alumnos)] options = dict(alumno_id=alumnos) vfilter = dict(alumno_id=alumno_id) return dict(records=r, name=name, namepl=namepl, form=filtro_resumen_por_alumno, vfilter=vfilter, options=options, docenteActual=identity.current.user.id, limit_to=identity.current.user.paginador)
def get_inscripto(self, cursoid, padron): msg = u'' error=False try: # Busco el alumno inscripto alumno = AlumnoInscripto.selectBy(curso=cursoid, alumno=Alumno.byUsuario(padron)).getOne() msg = {} msg['id'] = alumno.id msg['value'] = alumno.alumno.nombre except SQLObjectNotFound: msg = 'No existe el alumno %s en el curso seleccionado.' % padron error=True except Exception, (inst): msg = u"""Se ha producido un error inesperado al buscar el registro:\n %s""" % str(inst) error = True
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
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)
def get_alumnos(): return [(a.id, a) for a in Alumno.select()]