forked from elmau/empresa-libre
Editar alumnos
This commit is contained in:
parent
c21d14fe35
commit
85ff55a2db
|
@ -25,6 +25,9 @@ class StorageEngine(object):
|
|||
return getattr(self, '_get_{}'.format(table))(values, session)
|
||||
return getattr(self, '_get_{}'.format(table))(values)
|
||||
|
||||
def _get_schoolgroups(self, values):
|
||||
return main.Grupos.get_by(values)
|
||||
|
||||
def _get_nivedusat(self, values):
|
||||
return main.SATNivelesEducativos.get_by()
|
||||
|
||||
|
@ -252,6 +255,8 @@ class StorageEngine(object):
|
|||
return main.Configuracion.remove(id)
|
||||
if table == 'nivedu':
|
||||
return main.NivelesEducativos.remove(id)
|
||||
if table == 'students':
|
||||
return main.Alumnos.remove(id)
|
||||
return False
|
||||
|
||||
def _get_client(self, values):
|
||||
|
@ -306,6 +311,8 @@ class StorageEngine(object):
|
|||
opt = values.pop('opt')
|
||||
if opt == 'add':
|
||||
return main.Alumnos.add(values['values'])
|
||||
if opt == 'edit':
|
||||
return main.Alumnos.actualizar(values['values'])
|
||||
|
||||
def tickets(self, values, user):
|
||||
opt = values.pop('opt')
|
||||
|
|
|
@ -1427,10 +1427,16 @@ class NivelesEducativos(BaseModel):
|
|||
rows = NivelesEducativos.select().dicts()
|
||||
return tuple(rows)
|
||||
|
||||
def _add_group(self, obj):
|
||||
Grupos.get_or_create(**{'nivel': obj})
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def add(cls, values):
|
||||
try:
|
||||
NivelesEducativos.create(**values)
|
||||
obj = NivelesEducativos.create(**values)
|
||||
# Revisar
|
||||
cls._add_group(cls, obj)
|
||||
result = {'ok': True}
|
||||
except IntegrityError:
|
||||
msg = 'Nivel Educativo existente'
|
||||
|
@ -1457,6 +1463,17 @@ class Grupos(BaseModel):
|
|||
def __str__(self):
|
||||
return '{} {} {}'.format(self.nivel.nombre, self.grado, self.nombre)
|
||||
|
||||
@classmethod
|
||||
def get_by(cls, values):
|
||||
rows = (Grupos.select(
|
||||
Grupos.id.alias('id'),
|
||||
NivelesEducativos.nombre.alias('value'))
|
||||
.join(NivelesEducativos)
|
||||
.switch(Grupos)
|
||||
.dicts()
|
||||
)
|
||||
return tuple(rows)
|
||||
|
||||
|
||||
class CuentasBanco(BaseModel):
|
||||
de_emisor = BooleanField(default=False)
|
||||
|
@ -2174,6 +2191,12 @@ class Alumnos(BaseModel):
|
|||
|
||||
@classmethod
|
||||
def get_by(cls, values):
|
||||
if 'id' in values:
|
||||
id = int(values['id'])
|
||||
w = (Alumnos.id==id)
|
||||
rows = cls._get(cls, w)
|
||||
return rows[0]
|
||||
|
||||
if not values:
|
||||
w = None
|
||||
|
||||
|
@ -2192,6 +2215,26 @@ class Alumnos(BaseModel):
|
|||
data = {'ok': True}
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def actualizar(cls, values):
|
||||
fields = cls._clean(cls, values)
|
||||
id = int(fields.pop('id'))
|
||||
try:
|
||||
q = Alumnos.update(**fields).where(Alumnos.id==id)
|
||||
q.execute()
|
||||
except IntegrityError:
|
||||
msg = 'Ya existe un Alumno con este CURP'
|
||||
data = {'ok': False, 'msg': msg}
|
||||
return data
|
||||
|
||||
data = {'ok': True}
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def remove(cls, id):
|
||||
q = Alumnos.delete().where(Alumnos.id==id)
|
||||
return bool(q.execute())
|
||||
|
||||
|
||||
class AlumnosParientes(BaseModel):
|
||||
alumno = ForeignKeyField(Alumnos)
|
||||
|
|
|
@ -3,30 +3,110 @@
|
|||
var controllers_school = {
|
||||
init: function(){
|
||||
$$('cmd_new_student').attachEvent('onItemClick', cmd_new_student_click)
|
||||
$$('cmd_edit_student').attachEvent('onItemClick', cmd_edit_student_click)
|
||||
$$('cmd_delete_student').attachEvent('onItemClick', cmd_delete_student_click)
|
||||
$$('cmd_save_student').attachEvent('onItemClick', cmd_save_student_click)
|
||||
$$('cmd_cancel_student').attachEvent('onItemClick', cmd_cancel_student_click)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_school_groups(){
|
||||
webix.ajax().get('/values/schoolgroups', {
|
||||
error: function(text, data, xhr) {
|
||||
},
|
||||
success: function(text, data, xhr) {
|
||||
var values = data.json();
|
||||
$$('student_grupo').define('suggest', values)
|
||||
$$('student_grupo').refresh()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function init_config_school(){
|
||||
get_students()
|
||||
get_school_groups()
|
||||
}
|
||||
|
||||
|
||||
function cmd_new_student_click(){
|
||||
$$('form_student').setValues({})
|
||||
$$('grid_students').clearSelection()
|
||||
$$('multi_school').setValue('new_student')
|
||||
}
|
||||
|
||||
|
||||
function cmd_edit_student_click(){
|
||||
var row = $$('grid_students').getSelectedItem()
|
||||
|
||||
if (row == undefined){
|
||||
msg = 'Selecciona un Alumno'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
webix.ajax().get('/students', {id: row['id']}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg_error()
|
||||
},
|
||||
success: function(text, data, xhr){
|
||||
var values = data.json()
|
||||
$$('form_student').setValues(values)
|
||||
}
|
||||
})
|
||||
|
||||
$$('multi_school').setValue('new_student')
|
||||
}
|
||||
|
||||
|
||||
function delete_student(id){
|
||||
webix.ajax().del('/students', {id: id}, function(text, xml, xhr){
|
||||
msg = 'Alumno eliminado correctamente'
|
||||
if (xhr.status == 200){
|
||||
$$('grid_students').remove(id);
|
||||
msg_ok(msg)
|
||||
} else {
|
||||
msg = 'No se pudo eliminar.'
|
||||
msg_error(msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function cmd_delete_student_click(){
|
||||
var row = $$('grid_students').getSelectedItem()
|
||||
|
||||
if (row == undefined){
|
||||
msg = 'Selecciona un Alumno'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
msg = '¿Estás seguro de eliminar al Alumno?<BR><BR>'
|
||||
msg += row['nombre'] + ' ' + row['paterno'] + ' (' + row['rfc'] + ')'
|
||||
msg += '<BR><BR>ESTA ACCIÓN NO SE PUEDE DESHACER<BR><BR>'
|
||||
webix.confirm({
|
||||
title:'Eliminar Alumno',
|
||||
ok:'Si',
|
||||
cancel:'No',
|
||||
type:'confirm-error',
|
||||
text:msg,
|
||||
callback:function(result){
|
||||
if (result){
|
||||
delete_student(row['id'])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function cmd_cancel_student_click(){
|
||||
$$('multi_school').setValue('school_home')
|
||||
}
|
||||
|
||||
|
||||
function cmd_save_student_click(){
|
||||
var msg = 'Valores inválidos'
|
||||
var form = this.getFormView();
|
||||
|
||||
if (!form.validate()) {
|
||||
|
@ -35,8 +115,12 @@ function cmd_save_student_click(){
|
|||
}
|
||||
|
||||
var values = form.getValues();
|
||||
opt = 'add'
|
||||
if(values.id){
|
||||
opt = 'edit'
|
||||
}
|
||||
|
||||
webix.ajax().post('/students', {opt: 'add', values: values}, {
|
||||
webix.ajax().post('/students', {opt: opt, values: values}, {
|
||||
error:function(text, data, XmlHttpRequest){
|
||||
msg = 'Ocurrio un error, consulta a soporte técnico';
|
||||
msg_error(msg)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
|
||||
|
||||
|
||||
var toolbar_students = [
|
||||
{view: 'button', id: 'cmd_new_student', label: 'Nuevo', type: 'iconButton',
|
||||
autowidth: true, icon: 'user-plus'},
|
||||
|
@ -75,6 +73,12 @@ var student_controls_generales = [
|
|||
required: true, invalidMessage: 'CURP inválido', adjust: 'data',
|
||||
attributes: {maxlength: 20}},
|
||||
{}]},
|
||||
{cols: [
|
||||
{view: 'richselect', id: 'student_grupo', name: 'grupo',
|
||||
label: 'Nivel Educativo: ', required: true, options: [],
|
||||
invalidMessage: 'El Nivel Educativo es requerido'},
|
||||
{},
|
||||
]},
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue