Browse Source

completadas los add y edit de todos los tipos de usuarios

En estos momentos cuando se cambia el id a mano y resulta que es otro tipo de usuario se envía a /admin/error.
Falta usar autenticación
parent
commit
6cd3b7ec7e

BIN
__pycache__/administracion.cpython-38.pyc View File


BIN
__pycache__/adminstracion.cpython-38.pyc View File


BIN
__pycache__/enfermera.cpython-38.pyc View File


BIN
__pycache__/estudiante.cpython-38.pyc View File


BIN
__pycache__/facultad.cpython-38.pyc View File


BIN
__pycache__/funciones.cpython-38.pyc View File


BIN
__pycache__/index.cpython-38.pyc View File


BIN
__pycache__/madre.cpython-38.pyc View File


+ 106
- 0
administracion.py View File

1
+from connect import connection, engine, metadata
2
+import sqlalchemy as db
3
+from flask import jsonify, redirect, url_for, render_template
4
+import json
5
+# import index.py 
6
+from funciones import valida_fecha
7
+
8
+col1=[{"label":"Nombres","type":"text","name":"nombres","require":"1"},{"label":"Apellidos","type":"text","name":"apellidos","require":"1"},{"label":"Email","type":"email","name":"email","require":"1"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","require":"1"},{"label":"Genero","type":"select","options":[{"id":"0","label":"Femenino"},{"id":"1","label":"Masculino"},{"id":"2","label":"Otro"}],"name":"genero","require":True},{"label":"Posicion","type":"text","name":"posicion","require":False},{"label":"Otro","type":"text","name":"otro","require":False}]
9
+col2=[{"label":"Dirección 1","type":"text","name":"direccion1","require":"1"},{"label":"Dirección 2","type":"text","name":"direccion2","require":False},{"label":"Ciudad","type":"text","name":"ciudad","require":"1"},{"label":"Pais","type":"text","name":"pais","require":"1"},{"label":"Zipcode","type":"text","name":"zipcode","require":"1"},{"label":"Teléfono 1","type":"tel","name":"telefono1","require":"1"},{"label":"Teléfono 2","type":"tel","name":"telefono2","require":False}]
10
+form_order= {"entradas":{"col1":col1,"col2":col2}}
11
+usuarios_col=["nombres", "apellidos", "email", "fecha_nacimiento", "genero", "direccion1", "direccion2", "ciudad", "pais", "zipcode", "telefono1", "telefono2"]
12
+administracion_col=["posicion","otro"]
13
+
14
+def prepara_values_usuario(data):
15
+	values_list={}
16
+	for item in usuarios_col:
17
+		if item=="fecha_nacimiento":
18
+			values_list.update({item:valida_fecha(data[item])})			
19
+		else:
20
+			values_list.update({item:data[item]})
21
+	return values_list
22
+
23
+def prepara_values_administracion(data):
24
+	values_list={}
25
+	for item in administracion_col:
26
+		if item=="educacion_especial" and ("educacion_especial" not in data or data[item]=="0"):
27
+			values_list.update({item:0})
28
+		else:
29
+			values_list.update({item:data[item]})
30
+	return values_list
31
+	
32
+def edit(data):
33
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
34
+	values_list=prepara_values_usuario(data)
35
+	query = db.update(usuarios).values(values_list)
36
+	query = query.where(usuarios.columns.id == data['id'])
37
+	ResultProxy = connection.execute(query,values_list)
38
+
39
+	administracion = db.Table('administracion', metadata, autoload=True, autoload_with=engine)
40
+	values_list=prepara_values_administracion(data)
41
+	query = db.update(administracion).values(values_list)
42
+	query = query.where(administracion.columns.user_id == data['id'])
43
+	ResultProxy = connection.execute(query,values_list)
44
+	return redirect(url_for("formas",accion="edit", tipo="administracion", id=data['id']))
45
+
46
+def add(data):
47
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
48
+	values_list=prepara_values_usuario(data)
49
+	query = db.insert(usuarios).values(values_list)
50
+	ResultProxy = connection.execute(query,values_list)
51
+	inst_id=ResultProxy.lastrowid
52
+
53
+	administracion = db.Table('administracion', metadata, autoload=True, autoload_with=engine)
54
+	values_list=prepara_values_administracion(data)
55
+	values_list.update({"user_id":inst_id})
56
+	query = db.insert(administracion).values(values_list)
57
+	ResultProxy = connection.execute(query,values_list)
58
+	return redirect(url_for("formas",accion="edit", tipo="administracion", id=inst_id))
59
+
60
+
61
+def add_form():
62
+	data= {"titulo":"Administración","accion":"Añadir"}
63
+	data.update(form_order)
64
+	return jsonify(data)
65
+	
66
+def edit_form(id):
67
+	administracion = db.Table('administracion', metadata, autoload=True, autoload_with=engine)
68
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
69
+	query = db.select([usuarios, administracion.columns.otro1, administracion.columns.otro2])
70
+	query = query.select_from(usuarios.join(administracion, usuarios.columns.id == administracion.columns.user_id)).where(administracion.columns.user_id == id)
71
+	result = connection.execute(query).fetchall()
72
+# 	print(result)
73
+	if not len(result):
74
+# 		return add_form()
75
+# 		return render_template(url_for("formas",accion="add",tipo="administracion"))
76
+# 		return index.formas("add","administracion")
77
+		return False
78
+# 		return redirect("http://127.0.0.1:5000/error/administracion/"+id)
79
+# 		return redirect(url_for("maneja_error_user",id=id,tipo="administracion"))
80
+# 		return render_template("error.html",id=id,tipo="administracion")
81
+	for row in result:
82
+		row_as_dict = dict(row)
83
+	i=1
84
+	orden=1
85
+	entradas={}
86
+	for col in form_order["entradas"]:
87
+		col_data=[]
88
+		for item in form_order["entradas"][col]:
89
+			if item["type"]=="select":
90
+				item.update({"value":{"id":row_as_dict[item["name"]]}})
91
+			elif item["type"]=="checkbox":
92
+				item.update({"value":int(row_as_dict[item["name"]])})
93
+			else:
94
+				item.update({"value":str(row_as_dict[item["name"]])})
95
+			item.update({"tabindex":orden})
96
+			col_data.append(item)
97
+			orden+=1
98
+		entradas.update({"col"+str(i):col_data})
99
+		i+=1
100
+	data= {"titulo":"Administración","accion":"Editar"}
101
+	data.update({"entradas":entradas})
102
+# 	print(data)
103
+	return jsonify(data)
104
+	
105
+# print(edit_form(1))
106
+# add()

+ 105
- 4
enfermera.py View File

1
-def add():
2
-	return '{"titulo":"Enfermera","accion":"Añadir","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Posición","type":"text","name":"pos"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}]}}'
1
+from connect import connection, engine, metadata
2
+import sqlalchemy as db
3
+from flask import jsonify, redirect, url_for, render_template
4
+import json
5
+# import index.py 
6
+from funciones import valida_fecha
3
 
7
 
4
-def edit(id):
5
-	return '{"titulo":"Enfermera","accion":"Editar","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Posición","type":"text","name":"pos"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}]}}'
8
+col1=[{"label":"Nombres","type":"text","name":"nombres","require":"1"},{"label":"Apellidos","type":"text","name":"apellidos","require":"1"},{"label":"Email","type":"email","name":"email","require":"1"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","require":"1"},{"label":"Genero","type":"select","options":[{"id":"0","label":"Femenino"},{"id":"1","label":"Masculino"},{"id":"2","label":"Otro"}],"name":"genero","require":True},{"label":"Especialidad","type":"text","name":"especialidad","require":False},{"label":"Otro","type":"text","name":"otro","require":False}]
9
+col2=[{"label":"Dirección 1","type":"text","name":"direccion1","require":"1"},{"label":"Dirección 2","type":"text","name":"direccion2","require":False},{"label":"Ciudad","type":"text","name":"ciudad","require":"1"},{"label":"Pais","type":"text","name":"pais","require":"1"},{"label":"Zipcode","type":"text","name":"zipcode","require":"1"},{"label":"Teléfono 1","type":"tel","name":"telefono1","require":"1"},{"label":"Teléfono 2","type":"tel","name":"telefono2","require":False}]
10
+form_order= {"entradas":{"col1":col1,"col2":col2}}
11
+usuarios_col=["nombres", "apellidos", "email", "fecha_nacimiento", "genero", "direccion1", "direccion2", "ciudad", "pais", "zipcode", "telefono1", "telefono2"]
12
+enfermera_col=["especialidad","otro"]
13
+
14
+def prepara_values_usuario(data):
15
+	values_list={}
16
+	for item in usuarios_col:
17
+		if item=="fecha_nacimiento":
18
+			values_list.update({item:valida_fecha(data[item])})			
19
+		else:
20
+			values_list.update({item:data[item]})
21
+	return values_list
22
+
23
+def prepara_values_enfermera(data):
24
+	values_list={}
25
+	for item in enfermera_col:
26
+		if item=="educacion_especial" and ("educacion_especial" not in data or data[item]=="0"):
27
+			values_list.update({item:0})
28
+		else:
29
+			values_list.update({item:data[item]})
30
+	return values_list
31
+	
32
+def edit(data):
33
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
34
+	values_list=prepara_values_usuario(data)
35
+	query = db.update(usuarios).values(values_list)
36
+	query = query.where(usuarios.columns.id == data['id'])
37
+	ResultProxy = connection.execute(query,values_list)
38
+
39
+	enfermera = db.Table('enfermeras', metadata, autoload=True, autoload_with=engine)
40
+	values_list=prepara_values_enfermera(data)
41
+	query = db.update(enfermera).values(values_list)
42
+	query = query.where(enfermera.columns.user_id == data['id'])
43
+	ResultProxy = connection.execute(query,values_list)
44
+	return redirect(url_for("formas",accion="edit", tipo="enfermera", id=data['id']))
45
+
46
+def add(data):
47
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
48
+	values_list=prepara_values_usuario(data)
49
+	query = db.insert(usuarios).values(values_list)
50
+	ResultProxy = connection.execute(query,values_list)
51
+	inst_id=ResultProxy.lastrowid
52
+
53
+	enfermera = db.Table('enfermeras', metadata, autoload=True, autoload_with=engine)
54
+	values_list=prepara_values_enfermera(data)
55
+	values_list.update({"user_id":inst_id})
56
+	query = db.insert(enfermera).values(values_list)
57
+	ResultProxy = connection.execute(query,values_list)
58
+	return redirect(url_for("formas",accion="edit", tipo="enfermera", id=inst_id))
59
+
60
+
61
+def add_form():
62
+	data= {"titulo":"Enfermera","accion":"Añadir"}
63
+	data.update(form_order)
64
+	return jsonify(data)
65
+	
66
+def edit_form(id):
67
+	enfermera = db.Table('enfermeras', metadata, autoload=True, autoload_with=engine)
68
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
69
+	query = db.select([usuarios, enfermera.columns.especialidad, enfermera.columns.otro])
70
+	query = query.select_from(usuarios.join(enfermera, usuarios.columns.id == enfermera.columns.user_id)).where(enfermera.columns.user_id == id)
71
+	result = connection.execute(query).fetchall()
72
+# 	print(result)
73
+	if not len(result):
74
+# 		return add_form()
75
+# 		return render_template(url_for("formas",accion="add",tipo="enfermera"))
76
+# 		return index.formas("add","enfermera")
77
+		return False
78
+# 		return redirect("http://127.0.0.1:5000/error/enfermera/"+id)
79
+# 		return redirect(url_for("maneja_error_user",id=id,tipo="enfermera"))
80
+# 		return render_template("error.html",id=id,tipo="enfermera")
81
+	for row in result:
82
+		row_as_dict = dict(row)
83
+	i=1
84
+	orden=1
85
+	entradas={}
86
+	for col in form_order["entradas"]:
87
+		col_data=[]
88
+		for item in form_order["entradas"][col]:
89
+			if item["type"]=="select":
90
+				item.update({"value":{"id":row_as_dict[item["name"]]}})
91
+			elif item["type"]=="checkbox":
92
+				item.update({"value":int(row_as_dict[item["name"]])})
93
+			else:
94
+				item.update({"value":str(row_as_dict[item["name"]])})
95
+			item.update({"tabindex":orden})
96
+			col_data.append(item)
97
+			orden+=1
98
+		entradas.update({"col"+str(i):col_data})
99
+		i+=1
100
+	data= {"titulo":"Enfermera","accion":"Editar"}
101
+	data.update({"entradas":entradas})
102
+# 	print(data)
103
+	return jsonify(data)
104
+	
105
+# print(edit_form(1))
106
+# add()

+ 94
- 9
estudiante.py View File

1
 from connect import connection, engine, metadata
1
 from connect import connection, engine, metadata
2
 import sqlalchemy as db
2
 import sqlalchemy as db
3
+from flask import jsonify, redirect, url_for, render_template
4
+import json
5
+# import index.py 
6
+from funciones import valida_fecha
3
 
7
 
4
-def add():
5
-	return '{"titulo":"Estudiante","accion":"A\u00f1adir","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Grado","type":"text","name":"grado"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Educaci\u00f3n Especial","type":"checkbox","name":"ed_especial"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}]}}'
8
+col1=[{"label":"Nombres","type":"text","name":"nombres","require":"1"},{"label":"Apellidos","type":"text","name":"apellidos","require":"1"},{"label":"Email","type":"email","name":"email","require":"1"},{"label":"Grado","type":"number","name":"grado","require":"1"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","require":"1"},{"label":"Genero","type":"select","options":[{"id":"0","label":"Femenino"},{"id":"1","label":"Masculino"},{"id":"2","label":"Otro"}],"name":"genero","require":True},{"label":"Educación Especial","type":"checkbox","name":"educacion_especial"}]
9
+col2=[{"label":"Dirección 1","type":"text","name":"direccion1","require":"1"},{"label":"Dirección 2","type":"text","name":"direccion2","require":False},{"label":"Ciudad","type":"text","name":"ciudad","require":"1"},{"label":"Pais","type":"text","name":"pais","require":"1"},{"label":"Zipcode","type":"text","name":"zipcode","require":"1"},{"label":"Teléfono 1","type":"tel","name":"telefono1","require":"1"},{"label":"Teléfono 2","type":"tel","name":"telefono2","require":False}]
10
+form_order= {"entradas":{"col1":col1,"col2":col2}}
11
+usuarios_col=["nombres", "apellidos", "email", "fecha_nacimiento", "genero", "direccion1", "direccion2", "ciudad", "pais", "zipcode", "telefono1", "telefono2"]
12
+estudiantes_col=["grado", "educacion_especial"]
13
+
14
+def prepara_values_usuario(data):
15
+	values_list={}
16
+	for item in usuarios_col:
17
+		if item=="fecha_nacimiento":
18
+			values_list.update({item:valida_fecha(data[item])})			
19
+		else:
20
+			values_list.update({item:data[item]})
21
+	return values_list
22
+
23
+def prepara_values_estudiante(data):
24
+	values_list={}
25
+	for item in estudiantes_col:
26
+		if item=="educacion_especial" and ("educacion_especial" not in data or data[item]=="0"):
27
+			values_list.update({item:0})
28
+		else:
29
+			values_list.update({item:data[item]})
30
+	return values_list
31
+	
32
+def edit(data):
33
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
34
+	values_list=prepara_values_usuario(data)
35
+	query = db.update(usuarios).values(values_list)
36
+	query = query.where(usuarios.columns.id == data['id'])
37
+	ResultProxy = connection.execute(query,values_list)
38
+
39
+	estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
40
+	values_list=prepara_values_estudiante(data)
41
+	query = db.update(estudiantes).values(values_list)
42
+	query = query.where(estudiantes.columns.user_id == data['id'])
43
+	ResultProxy = connection.execute(query,values_list)
44
+	return redirect(url_for("formas",accion="edit", tipo="estudiante", id=data['id']))
45
+
46
+def add(data):
47
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
48
+	values_list=prepara_values_usuario(data)
49
+	query = db.insert(usuarios).values(values_list)
50
+	ResultProxy = connection.execute(query,values_list)
51
+	inst_id=ResultProxy.lastrowid
52
+
53
+	estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
54
+	values_list=prepara_values_estudiante(data)
55
+	values_list.update({"user_id":inst_id})
56
+	query = db.insert(estudiantes).values(values_list)
57
+	ResultProxy = connection.execute(query,values_list)
58
+	return redirect(url_for("formas",accion="edit", tipo="estudiante", id=inst_id))
59
+
60
+
61
+def add_form():
62
+	data= {"titulo":"Estudiante","accion":"Añadir"}
63
+	data.update(form_order)
64
+	return jsonify(data)
6
 	
65
 	
7
-def edit(id):
66
+def edit_form(id):
8
 	estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
67
 	estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
9
 	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
68
 	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
10
-	query = db.select([usuarios, estudiantes])
69
+	query = db.select([usuarios, estudiantes.columns.grado, estudiantes.columns.educacion_especial])
11
 	query = query.select_from(usuarios.join(estudiantes, usuarios.columns.id == estudiantes.columns.user_id)).where(estudiantes.columns.user_id == id)
70
 	query = query.select_from(usuarios.join(estudiantes, usuarios.columns.id == estudiantes.columns.user_id)).where(estudiantes.columns.user_id == id)
12
-	results = connection.execute(query).fetchall()
13
-# 	print(results[0]["nombres"])
14
-# 	print(js)
15
-	return ('{"titulo":"Estudiante","accion":"Editar","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres","value":"'+results[0]["nombres"]+'"},{"label":"Apellidos","type":"text","name":"apellidos","value":"'+results[0]["apellidos"]+'"},{"label":"Email","type":"text","name":"email","value":"'+results[0]["email"]+'"},{"label":"Grado","type":"text","name":"grado","value":"'+str(results[0]["grado"])+'"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","value":"'+str(results[0]["fecha_nacimiento"])+'"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero","value":"'+results[0]["genero"]+'"},{"label":"Educaci\u00f3n Especial","type":"checkbox","name":"educacion_especial","value":"'+results[0]["educacion_especial"]+'"}],"col2":[{"label":"Direcci\u00f3n 1","type":"text","name":"direccion1","value":"'+results[0]["direccion1"]+'"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2","value":"'+results[0]["direccion2"]+'"},{"label":"Ciudad","type":"text","name":"ciudad","value":"'+results[0]["ciudad"]+'"},{"label":"País","type":"text","name":"pais","value":"'+results[0]["pais"]+'"},{"label":"Zipcode","type":"text","name":"zipcode","value":"'+results[0]["zipcode"]+'"},{"label":"Tel\u00e9fono 1","type":"tel","name":"telefono1","value":"'+results[0]["telefono1"]+'"},{"label":"Tel\u00e9fono 2","type":"tel","name":"telefono2","value":"'+results[0]["telefono2"]+'"}]}}')
71
+	result = connection.execute(query).fetchall()
72
+	if not len(result):
73
+# 		return add_form()
74
+# 		return redirect(url_for("formas",accion="add",tipo="estudiante"))
75
+# 		return index.formas("add","estudiante")
76
+		return False
77
+	for row in result:
78
+		row_as_dict = dict(row)
79
+	i=1
80
+	orden=1
81
+	entradas={}
82
+	for col in form_order["entradas"]:
83
+		col_data=[]
84
+		for item in form_order["entradas"][col]:
85
+			if item["type"]=="select":
86
+				item.update({"value":{"id":row_as_dict[item["name"]]}})
87
+			elif item["type"]=="checkbox":
88
+				item.update({"value":int(row_as_dict[item["name"]])})
89
+			else:
90
+				item.update({"value":str(row_as_dict[item["name"]])})
91
+			item.update({"tabindex":orden})
92
+			col_data.append(item)
93
+			orden+=1
94
+		entradas.update({"col"+str(i):col_data})
95
+		i+=1
96
+	data= {"titulo":"Estudiante","accion":"Editar"}
97
+	data.update({"entradas":entradas})
98
+# 	print(data)
99
+	return jsonify(data)
16
 	
100
 	
17
-print(edit(1))
101
+# print(edit_form(1))
102
+# add()

+ 105
- 4
facultad.py View File

1
-def add():
2
-	return '{"titulo":"Facultad","accion":"Añadir","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Posición","type":"text","name":"pos"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}]}}'
1
+from connect import connection, engine, metadata
2
+import sqlalchemy as db
3
+from flask import jsonify, redirect, url_for, render_template
4
+import json
5
+# import index.py 
6
+from funciones import valida_fecha
3
 
7
 
4
-def edit(id):
5
-	return '{"titulo":"Facultad","accion":"Editar","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Posición","type":"text","name":"pos"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}]}}'
8
+col1=[{"label":"Nombres","type":"text","name":"nombres","require":"1"},{"label":"Apellidos","type":"text","name":"apellidos","require":"1"},{"label":"Email","type":"email","name":"email","require":"1"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","require":"1"},{"label":"Genero","type":"select","options":[{"id":"0","label":"Femenino"},{"id":"1","label":"Masculino"},{"id":"2","label":"Otro"}],"name":"genero","require":True},{"label":"Especialidad","type":"text","name":"especialidad","require":"1"},{"label":"Educaci\u00f3n Especial","type":"checkbox","name":"educacion_especial"}]
9
+col2=[{"label":"Dirección 1","type":"text","name":"direccion1","require":"1"},{"label":"Dirección 2","type":"text","name":"direccion2","require":False},{"label":"Ciudad","type":"text","name":"ciudad","require":"1"},{"label":"Pais","type":"text","name":"pais","require":"1"},{"label":"Zipcode","type":"text","name":"zipcode","require":"1"},{"label":"Teléfono 1","type":"tel","name":"telefono1","require":"1"},{"label":"Teléfono 2","type":"tel","name":"telefono2","require":False}]
10
+form_order= {"entradas":{"col1":col1,"col2":col2}}
11
+usuarios_col=["nombres", "apellidos", "email", "fecha_nacimiento", "genero", "direccion1", "direccion2", "ciudad", "pais", "zipcode", "telefono1", "telefono2"]
12
+facultad_col=["especialidad","educacion_especial"]
13
+
14
+def prepara_values_usuario(data):
15
+	values_list={}
16
+	for item in usuarios_col:
17
+		if item=="fecha_nacimiento":
18
+			values_list.update({item:valida_fecha(data[item])})			
19
+		else:
20
+			values_list.update({item:data[item]})
21
+	return values_list
22
+
23
+def prepara_values_facultad(data):
24
+	values_list={}
25
+	for item in facultad_col:
26
+		if item=="educacion_especial" and ("educacion_especial" not in data or data[item]=="0"):
27
+			values_list.update({item:0})
28
+		else:
29
+			values_list.update({item:data[item]})
30
+	return values_list
31
+	
32
+def edit(data):
33
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
34
+	values_list=prepara_values_usuario(data)
35
+	query = db.update(usuarios).values(values_list)
36
+	query = query.where(usuarios.columns.id == data['id'])
37
+	ResultProxy = connection.execute(query,values_list)
38
+
39
+	facultad = db.Table('facultad', metadata, autoload=True, autoload_with=engine)
40
+	values_list=prepara_values_facultad(data)
41
+	query = db.update(facultad).values(values_list)
42
+	query = query.where(facultad.columns.user_id == data['id'])
43
+	ResultProxy = connection.execute(query,values_list)
44
+	return redirect(url_for("formas",accion="edit", tipo="facultad", id=data['id']))
45
+
46
+def add(data):
47
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
48
+	values_list=prepara_values_usuario(data)
49
+	query = db.insert(usuarios).values(values_list)
50
+	ResultProxy = connection.execute(query,values_list)
51
+	inst_id=ResultProxy.lastrowid
52
+
53
+	facultad = db.Table('facultad', metadata, autoload=True, autoload_with=engine)
54
+	values_list=prepara_values_facultad(data)
55
+	values_list.update({"user_id":inst_id})
56
+	query = db.insert(facultad).values(values_list)
57
+	ResultProxy = connection.execute(query,values_list)
58
+	return redirect(url_for("formas",accion="edit", tipo="facultad", id=inst_id))
59
+
60
+
61
+def add_form():
62
+	data= {"titulo":"Facultad","accion":"Añadir"}
63
+	data.update(form_order)
64
+	return jsonify(data)
65
+	
66
+def edit_form(id):
67
+	facultad = db.Table('facultad', metadata, autoload=True, autoload_with=engine)
68
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
69
+	query = db.select([usuarios, facultad.columns.especialidad, facultad.columns.educacion_especial])
70
+	query = query.select_from(usuarios.join(facultad, usuarios.columns.id == facultad.columns.user_id)).where(facultad.columns.user_id == id)
71
+	result = connection.execute(query).fetchall()
72
+# 	print(result)
73
+	if not len(result):
74
+# 		return add_form()
75
+# 		return render_template(url_for("formas",accion="add",tipo="facultad"))
76
+# 		return index.formas("add","facultad")
77
+		return False
78
+# 		return redirect("http://127.0.0.1:5000/error/facultad/"+id)
79
+# 		return redirect(url_for("maneja_error_user",id=id,tipo="facultad"))
80
+# 		return render_template("error.html",id=id,tipo="facultad")
81
+	for row in result:
82
+		row_as_dict = dict(row)
83
+	i=1
84
+	orden=1
85
+	entradas={}
86
+	for col in form_order["entradas"]:
87
+		col_data=[]
88
+		for item in form_order["entradas"][col]:
89
+			if item["type"]=="select":
90
+				item.update({"value":{"id":row_as_dict[item["name"]]}})
91
+			elif item["type"]=="checkbox":
92
+				item.update({"value":int(row_as_dict[item["name"]])})
93
+			else:
94
+				item.update({"value":str(row_as_dict[item["name"]])})
95
+			item.update({"tabindex":orden})
96
+			col_data.append(item)
97
+			orden+=1
98
+		entradas.update({"col"+str(i):col_data})
99
+		i+=1
100
+	data= {"titulo":"Facultad","accion":"Editar"}
101
+	data.update({"entradas":entradas})
102
+# 	print(data)
103
+	return jsonify(data)
104
+	
105
+# print(edit_form(1))
106
+# add()

+ 28
- 0
funciones.py View File

1
+import time
2
+from datetime import datetime, date
3
+
4
+def valida_fecha(fecha):
5
+	valid = False
6
+	while not valid:
7
+		fechaSplit=fecha.split("-")
8
+		try:
9
+			d = date(int(fechaSplit[0]), int(fechaSplit[1]), int(fechaSplit[2]))
10
+			valid=True
11
+		except ValueError as ve:
12
+			error=str(ve)
13
+# 			print(error)
14
+			if "year" in error:
15
+				fecha = "2000-"+fechaSplit[1]+"-"+fechaSplit[2]
16
+			elif "must" in error: #manejar el mes
17
+				mes=int(fechaSplit[1])-1
18
+# 				print(mes)
19
+				fecha = fechaSplit[0]+"-"+str(mes)+"-"+fechaSplit[2]
20
+			elif "day" in error:
21
+				dia=int(fechaSplit[2])-1
22
+				fecha = fechaSplit[0]+"-"+fechaSplit[1]+"-"+str(dia)
23
+	unixtime = time.mktime(d.timetuple())
24
+
25
+	timestamp2 = date.fromtimestamp(unixtime)
26
+	return timestamp2
27
+
28
+	return d

+ 35
- 36
index.py View File

1
-from flask import Flask, render_template
1
+from flask import Flask, render_template, request, redirect, url_for
2
 import json
2
 import json
3
 import estudiante, madre, admin, enfermera, facultad
3
 import estudiante, madre, admin, enfermera, facultad
4
 
4
 
5
 app = Flask(__name__)
5
 app = Flask(__name__)
6
 
6
 
7
-@app.route('/', methods=['GET', 'POST'])
7
+@app.route('/admin/', methods=['GET', 'POST'])
8
 def index():
8
 def index():
9
 #     return "Hello, World!"
9
 #     return "Hello, World!"
10
     return render_template('dashAdministracion.html')
10
     return render_template('dashAdministracion.html')
11
 
11
 
12
-@app.route('/forma/<accion>/<tipo>/', methods=['GET', 'POST'])
13
-@app.route('/forma/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
12
+@app.route('/admin/procesaUser', methods=['GET', 'POST'])
13
+def procesaUser():
14
+	data = request.form
15
+	tipo_accion = getattr(__import__(data["tipo"]), data["accion"])
16
+	return tipo_accion(data)
17
+	
18
+	
19
+@app.route('/admin/forma/<accion>/<tipo>/', methods=['GET', 'POST'])
20
+@app.route('/admin/forma/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
14
 def formas(accion,tipo,id=None):
21
 def formas(accion,tipo,id=None):
15
-	return render_template('forma.html', tipo=tipo, accion=accion, id=id)
22
+	return render_template('forma.html', tipo=tipo, accion=accion, id=id, user_type="admin")
16
 
23
 
17
     
24
     
18
-@app.route('/formaDatos/<accion>/<tipo>/', methods=['GET', 'POST'])
19
-@app.route('/formaDatos/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
25
+@app.route('/admin/formaDatos/<accion>/<tipo>/', methods=['GET', 'POST'])
26
+@app.route('/admin/formaDatos/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
20
 def formaEst(accion, tipo, id=None):
27
 def formaEst(accion, tipo, id=None):
21
 # 	data = json.loads('formaEstudiantes.json')
28
 # 	data = json.loads('formaEstudiantes.json')
22
-	if(tipo=="estudiante"):
23
-		if(accion=="add"):
24
-			return estudiante.add()
25
-		if(accion=="edit"):
26
-			return estudiante.edit(id)
27
-	if(tipo=="madre"):
28
-		if(accion=="add"):
29
-			return madre.add()
30
-		if(accion=="edit"):
31
-			return madre.edit(id)
32
-	if(tipo=="admin"):
33
-		if(accion=="add"):
34
-			return admin.add()
35
-		if(accion=="edit"):
36
-			return admin.edit(id)
37
-	if(tipo=="enfermera"):
38
-		if(accion=="add"):
39
-			return enfermera.add()
40
-		if(accion=="edit"):
41
-			return enfermera.edit(id)
42
-	if(tipo=="facultad"):
43
-		if(accion=="add"):
44
-			return facultad.add()
45
-		if(accion=="edit"):
46
-			return facultad.edit(id)
47
-
48
-
49
-@app.route('/dashAdmin', methods=['GET', 'POST'])
29
+	if(accion=="add"):
30
+		return __import__(tipo).add_form()
31
+	if(accion=="edit"):
32
+		resultado=__import__(tipo).edit_form(id)
33
+		if resultado==False:
34
+# 			return __import__(tipo).add_form()
35
+# 			return render_template('error.html',tipo=tipo)
36
+# 			return redirect(url_for("maneja_error_user",tipo="facultad"))
37
+			return {"error":True,"tipo":tipo,"user_type":"admin"}
38
+		else:
39
+			return resultado
40
+
41
+@app.route('/admin/dashAdmin', methods=['GET', 'POST'])
50
 def dashAdmin():
42
 def dashAdmin():
51
 # 	data = json.loads('formaEstudiantes.json')
43
 # 	data = json.loads('formaEstudiantes.json')
52
-	return '{"tasks": [    {      "titulo": "Estudiantes",      "url": "admin/estudiantes.html"    }, {      "titulo": "Facultad",      "url": "admin/facultad.html"    },     {      "titulo": "Administración",      "url": "admin/adminstracion.html"    },     {      "titulo": "Enfermeria",      "url": "admin/enfermeria.html"    },     {      "titulo": "Madres",      "url": "admin/madres.html"    },     {      "titulo": "Cursos",      "url": "admin/cursos.html"    },     {      "titulo": "Matricula",      "url": "admin/matricula.html"    },     {      "titulo": "Transcripción",      "url": "admin/transcripcion.html"    },     {      "titulo": "Oferta",      "url": "admin/oferta.html"    },     {      "titulo": "Visita Oficina",      "url": "admin/oficina.html"    },     {      "titulo": "Mensajes",      "url": "admin/mensajes.html"    }  ], "titulo": "Administración"}'
44
+	return '{"tasks": [ { "titulo": "Estudiantes", "url": "admin/estudiantes.html" }, { "titulo": "Facultad", "url": "admin/facultad.html" }, { "titulo": "Administración", "url": "admin/adminstracion.html" }, { "titulo": "Enfermeria", "url": "admin/enfermeria.html" }, { "titulo": "Madres", "url": "admin/madres.html" }, { "titulo": "Cursos", "url": "admin/cursos.html" }, { "titulo": "Matricula", "url": "admin/matricula.html" }, { "titulo": "Transcripción", "url": "admin/transcripcion.html" }, { "titulo": "Oferta", "url": "admin/oferta.html" }, { "titulo": "Visita Oficina", "url": "admin/oficina.html" }, { "titulo": "Mensajes", "url": "admin/mensajes.html" } ], "titulo": "Administración"}'
45
+
46
+
47
+@app.route('/admin/error/<tipo>', methods=['GET', 'POST'])
48
+def maneja_error_user(tipo):
49
+	return render_template('error.html',tipo=tipo)
50
+
51
+# print(formaEst("edit","estudiante",3))

+ 105
- 4
madre.py View File

1
-def add():
2
-	return '{"titulo":"Madre","accion":"A\u00f1adir","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"}]}}'
1
+from connect import connection, engine, metadata
2
+import sqlalchemy as db
3
+from flask import jsonify, redirect, url_for, render_template
4
+import json
5
+# import index.py 
6
+from funciones import valida_fecha
3
 
7
 
4
-def edit(id):
5
-	return '{"titulo":"Madre","accion":"Editar","entradas":{"col1":[{"label":"Nombres","type":"text","name":"nombres"},{"label":"Apellidos","type":"text","name":"apellidos"},{"label":"Email","type":"text","name":"email"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nac"},{"label":"Genero","type":"select","options":["","Femenino","Masculino","Otro"],"name":"genero"},{"label":"Tel\u00e9fono 2","type":"tel","name":"tel2"}],"col2":[{"label":"Direcci\u00f3n 1","name":"direccion1"},{"label":"Direcci\u00f3n 2","type":"text","name":"direccion2"},{"label":"Ciudad","type":"text","name":"ciudad"},{"label":"Zipcode","type":"text","name":"zipcode"},{"label":"Tel\u00e9fono 1","type":"tel","name":"tel1"}]}}'
8
+col1=[{"label":"Nombres","type":"text","name":"nombres","require":"1"},{"label":"Apellidos","type":"text","name":"apellidos","require":"1"},{"label":"Email","type":"email","name":"email","require":"1"},{"label":"Fecha de Nacimiento","type":"date","name":"fecha_nacimiento","require":"1"},{"label":"Genero","type":"select","options":[{"id":"0","label":"Femenino"},{"id":"1","label":"Masculino"},{"id":"2","label":"Otro"}],"name":"genero","require":True},{"label":"Otro","type":"text","name":"otro1","require":False},{"label":"Otro","type":"text","name":"otro2","require":False}]
9
+col2=[{"label":"Dirección 1","type":"text","name":"direccion1","require":"1"},{"label":"Dirección 2","type":"text","name":"direccion2","require":False},{"label":"Ciudad","type":"text","name":"ciudad","require":"1"},{"label":"Pais","type":"text","name":"pais","require":"1"},{"label":"Zipcode","type":"text","name":"zipcode","require":"1"},{"label":"Teléfono 1","type":"tel","name":"telefono1","require":"1"},{"label":"Teléfono 2","type":"tel","name":"telefono2","require":False}]
10
+form_order= {"entradas":{"col1":col1,"col2":col2}}
11
+usuarios_col=["nombres", "apellidos", "email", "fecha_nacimiento", "genero", "direccion1", "direccion2", "ciudad", "pais", "zipcode", "telefono1", "telefono2"]
12
+madre_col=["otro1","otro2"]
13
+
14
+def prepara_values_usuario(data):
15
+	values_list={}
16
+	for item in usuarios_col:
17
+		if item=="fecha_nacimiento":
18
+			values_list.update({item:valida_fecha(data[item])})			
19
+		else:
20
+			values_list.update({item:data[item]})
21
+	return values_list
22
+
23
+def prepara_values_madre(data):
24
+	values_list={}
25
+	for item in madre_col:
26
+		if item=="educacion_especial" and ("educacion_especial" not in data or data[item]=="0"):
27
+			values_list.update({item:0})
28
+		else:
29
+			values_list.update({item:data[item]})
30
+	return values_list
31
+	
32
+def edit(data):
33
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
34
+	values_list=prepara_values_usuario(data)
35
+	query = db.update(usuarios).values(values_list)
36
+	query = query.where(usuarios.columns.id == data['id'])
37
+	ResultProxy = connection.execute(query,values_list)
38
+
39
+	madre = db.Table('madres', metadata, autoload=True, autoload_with=engine)
40
+	values_list=prepara_values_madre(data)
41
+	query = db.update(madre).values(values_list)
42
+	query = query.where(madre.columns.user_id == data['id'])
43
+	ResultProxy = connection.execute(query,values_list)
44
+	return redirect(url_for("formas",accion="edit", tipo="madre", id=data['id']))
45
+
46
+def add(data):
47
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
48
+	values_list=prepara_values_usuario(data)
49
+	query = db.insert(usuarios).values(values_list)
50
+	ResultProxy = connection.execute(query,values_list)
51
+	inst_id=ResultProxy.lastrowid
52
+
53
+	madre = db.Table('madres', metadata, autoload=True, autoload_with=engine)
54
+	values_list=prepara_values_madre(data)
55
+	values_list.update({"user_id":inst_id})
56
+	query = db.insert(madre).values(values_list)
57
+	ResultProxy = connection.execute(query,values_list)
58
+	return redirect(url_for("formas",accion="edit", tipo="madre", id=inst_id))
59
+
60
+
61
+def add_form():
62
+	data= {"titulo":"Madre","accion":"Añadir"}
63
+	data.update(form_order)
64
+	return jsonify(data)
65
+	
66
+def edit_form(id):
67
+	madre = db.Table('madres', metadata, autoload=True, autoload_with=engine)
68
+	usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
69
+	query = db.select([usuarios, madre.columns.otro1, madre.columns.otro2])
70
+	query = query.select_from(usuarios.join(madre, usuarios.columns.id == madre.columns.user_id)).where(madre.columns.user_id == id)
71
+	result = connection.execute(query).fetchall()
72
+# 	print(result)
73
+	if not len(result):
74
+# 		return add_form()
75
+# 		return render_template(url_for("formas",accion="add",tipo="madre"))
76
+# 		return index.formas("add","madre")
77
+		return False
78
+# 		return redirect("http://127.0.0.1:5000/error/madre/"+id)
79
+# 		return redirect(url_for("maneja_error_user",id=id,tipo="madre"))
80
+# 		return render_template("error.html",id=id,tipo="madre")
81
+	for row in result:
82
+		row_as_dict = dict(row)
83
+	i=1
84
+	orden=1
85
+	entradas={}
86
+	for col in form_order["entradas"]:
87
+		col_data=[]
88
+		for item in form_order["entradas"][col]:
89
+			if item["type"]=="select":
90
+				item.update({"value":{"id":row_as_dict[item["name"]]}})
91
+			elif item["type"]=="checkbox":
92
+				item.update({"value":int(row_as_dict[item["name"]])})
93
+			else:
94
+				item.update({"value":str(row_as_dict[item["name"]])})
95
+			item.update({"tabindex":orden})
96
+			col_data.append(item)
97
+			orden+=1
98
+		entradas.update({"col"+str(i):col_data})
99
+		i+=1
100
+	data= {"titulo":"Madre","accion":"Editar"}
101
+	data.update({"entradas":entradas})
102
+# 	print(data)
103
+	return jsonify(data)
104
+	
105
+# print(edit_form(1))
106
+# add()

+ 22
- 0
static/error.js View File

1
+var error = angular.module('error', ['ngSanitize']);
2
+
3
+// Define the `PhoneListController` controller on the `phonecatApp` module
4
+
5
+// error.controller('ErrorController', function ErrorController($http, $scope, tipo, id) {
6
+error.controller('ErrorController', function ErrorController(tipo) {
7
+  	console.log(tipo);
8
+//   	$window.location.href = '/index';
9
+//   	var url = '/formaDatos/'+accion+'/'+tipo+'/'
10
+//   	if(id!="none")
11
+//   	{
12
+//   		url+= id;
13
+//   	}
14
+//     $http.get(url).then(function(response) {
15
+//       $scope.entradas = response.data.entradas;
16
+//       $scope.titulo = response.data.titulo;
17
+//       $scope.accion = response.data.accion;
18
+// //       $scope.selectedForm=
19
+//     console.log(response.data);
20
+//     });
21
+});
22
+

+ 18
- 7
static/forma.js View File

1
-var forma = angular.module('forma', []);
1
+var forma = angular.module('forma', ['ngSanitize']);
2
 
2
 
3
 // Define the `PhoneListController` controller on the `phonecatApp` module
3
 // Define the `PhoneListController` controller on the `phonecatApp` module
4
 
4
 
5
-forma.controller('FormController', function FormController($http, $scope, accion, tipo, id) {
5
+forma.controller('FormController', function FormController($http, $scope, accion, tipo, id, user_type, $window) {
6
   	console.log(accion +","+ tipo +","+ id);
6
   	console.log(accion +","+ tipo +","+ id);
7
-  	var url = '/formaDatos/'+accion+'/'+tipo+'/'
7
+  	var url = '/'+user_type+'/formaDatos/'+accion+'/'+tipo+'/'
8
   	if(id!="none")
8
   	if(id!="none")
9
   	{
9
   	{
10
   		url+= id;
10
   		url+= id;
11
   	}
11
   	}
12
     $http.get(url).then(function(response) {
12
     $http.get(url).then(function(response) {
13
-      $scope.entradas = response.data.entradas;
14
-      $scope.titulo = response.data.titulo;
15
-      $scope.accion = response.data.accion;
16
-    console.log(response.data);
13
+      if(response.data.error!==true)
14
+      {
15
+		
16
+		  $scope.entradas = response.data.entradas;
17
+		  $scope.titulo = response.data.titulo;
18
+		  $scope.accion = response.data.accion;
19
+	  }
20
+	  else
21
+	  {
22
+	   	  $window.location.href = '/'+user_type+'/error/'+response.data.tipo;
23
+	    console.log(response.data);
24
+	  }
25
+	
26
+//       $scope.selectedForm=
27
+//     console.log(response.data);
17
     });
28
     });
18
 });
29
 });
19
 
30
 

+ 19
- 0
templates/error.html View File

1
+<html>
2
+<head>
3
+    <meta charset="utf-8">
4
+	<link rel="stylesheet" href="{{ url_for('static', filename='estilo.css') }}" />
5
+<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
6
+<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
7
+<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
8
+<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
9
+  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
10
+<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
11
+	<script src="{{ url_for('static', filename='error.js') }}"></script>
12
+    <script>
13
+       error.value("tipo", "{{tipo}}");
14
+    </script>
15
+</head>
16
+<body ng-app="error" ng-controller="ErrorController">
17
+Ese usuario no existe o no es {{tipo}}
18
+</body>
19
+</html>

+ 42
- 25
templates/forma.html View File

6
 <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
6
 <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
7
 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
7
 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
8
 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
8
 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
9
-  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
9
+  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
10
+<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
10
 	<script src="{{ url_for('static', filename='forma.js') }}"></script>
11
 	<script src="{{ url_for('static', filename='forma.js') }}"></script>
11
     <script>
12
     <script>
12
-       forma.value("accion", "{{accion}}").value("tipo", "{{tipo}}").value("id", "{{id}}");
13
+       forma.value("accion", "{{accion}}").value("tipo", "{{tipo}}").value("id", "{{id}}").value("user_type", "{{user_type}}");
13
     </script>
14
     </script>
14
 </head>
15
 </head>
15
 <body ng-app="forma" ng-controller="FormController">
16
 <body ng-app="forma" ng-controller="FormController">
37
  </div>
38
  </div>
38
 </div>
39
 </div>
39
 <div class="container" align="center">
40
 <div class="container" align="center">
40
-<form class="form">
41
+<!-- <form class="form" action="/procesaUser" method="POST"> -->
42
+<form class="form" action="/{{user_type}}/procesaUser" method="POST">
43
+      {% raw %}
41
 <span ng-repeat="entrada in entradas.col1">
44
 <span ng-repeat="entrada in entradas.col1">
42
 <div>
45
 <div>
43
-      {% raw %}
44
 	<span class="boton labelForma">
46
 	<span class="boton labelForma">
45
 		{{entrada.label}}
47
 		{{entrada.label}}
46
 	</span>
48
 	</span>
47
-      {% endraw %}
48
 	<span ng-if="entrada.type=='select'">
49
 	<span ng-if="entrada.type=='select'">
49
-      {% raw %}
50
-		<select class="form-control-inline"  style="width: 250px;height: 48px;">
51
-			<option ng-for="let opcion of entrada.options" [value]=$index [selected]="$index==opcion.value">{{opcion}}</option>
52
-		</select>
53
-      {% endraw %}
50
+		<select tabindex="{{entrada.tabindex}}" name="{{entrada.name}}" id="{{entrada.name}}" class="form-control-inline"  style="width: 250px;height: 48px;"
51
+      ng-options="opcion.label for opcion in entrada.options track by opcion.id"
52
+      ng-model="entrada.value"
53
+      ng-required="true" required
54
+      ></select>
54
 	</span>
55
 	</span>
55
-	      {% raw %}
56
-	<span ng-if="entrada.type!='select'">
57
-		<input  class="form-control-inline" type="{{entrada.type}}" name="{{entrada.name}}" value="{{entrada.value}}" style="width: 250px;height: 48px;align:left;">
56
+	<span ng-if="entrada.type=='checkbox'">
57
+		<input  tabindex="{{entrada.tabindex}}" class="form-control-inline" type="{{entrada.type}}" name="{{entrada.name}}" value="1" ng-checked="{{entrada.value}}" style="width: 250px;height: 48px;align:left;">
58
+	</span>
59
+	<span ng-if="entrada.type=='tel'">
60
+		<input tabindex="{{entrada.tabindex}}" class="form-control-inline" type="tel" placeholder="787-123-4567" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" ng-required="entrada.require" name="{{entrada.name}}" value="{{entrada.value}}" style="width: 250px;height: 48px;align:left;">
61
+	</span>
62
+	<span ng-if="entrada.type=='date'">
63
+		<input tabindex="{{entrada.tabindex}}" class="form-control-inline" type="date" placeholder="yyyy-MM-dd" pattern="\d{4}-\d{1,2}-\d{1,2}" ng-required="entrada.require" name="{{entrada.name}}" value="{{entrada.value}}" style="width: 250px;height: 48px;align:left;">
64
+	</span>
65
+	<span ng-if="entrada.type!='select' && entrada.type!='checkbox' && entrada.type!='tel' && entrada.type!='date'">
66
+		<input tabindex="{{entrada.tabindex}}" ng-required="entrada.require" class="form-control-inline" type="{{entrada.type}}" name="{{entrada.name}}" value="{{entrada.value}}" style="width: 250px;height: 48px;align:left;">
58
 	</span>
67
 	</span>
59
-      {% endraw %}
60
 
68
 
61
   <span ng-if="entradas.col2[$index].name">
69
   <span ng-if="entradas.col2[$index].name">
62
-      {% raw %}
63
 	<span class="boton labelForma">
70
 	<span class="boton labelForma">
64
 		{{entradas.col2[$index].label}}
71
 		{{entradas.col2[$index].label}}
65
 	</span>
72
 	</span>
66
-      {% endraw %}
67
 	<span ng-if="entradas.col2[$index].type=='select'">
73
 	<span ng-if="entradas.col2[$index].type=='select'">
68
-      {% raw %}
69
-		<select class="form-control-inline"  style="width: 250px;height: 48px;">
70
-			<option ng-repeat="opcion in entradas.col2[$index].options" value="{{$index}}" [selected]="$index == entradas.col2[$index].value">{{opcion}}</option>
71
-		</select>
72
-      {% endraw %}
74
+		<select name="{{entradas.col2[$index].name}}" id="{{entradas.col2[$index].name}}" class="form-control-inline"  style="width: 250px;height: 48px;"
75
+      ng-options="opcion.label for opcion in entradas.col2[$index].options track by opcion.id"
76
+      ng-model="entradas.col2[$index].value"
77
+      ng-required="entradas.col2[$index].require"
78
+      ></select>
73
 	</span>
79
 	</span>
74
-	      {% raw %}
75
-	<span ng-if="entradas.col2[$index].type!='select'">
76
-		<input class="form-control-inline" type="{{entradas.col2[$index].type}}" name="{{entradas.col2[$index].name}}" value="{{entradas.col2[$index].value}}" style="width: 250px;height: 48px;align:left;">
80
+	<span ng-if="entradas.col2[$index].type=='checkbox'">
81
+			<input class="form-control-inline" type="checkbox" name="{{entradas.col2[$index].name}}" value="1" ng-checked="{{entradas.col2[$index].value}}" style="width: 250px;height: 48px;align:left;">
82
+	</span>
83
+	<span ng-if="entradas.col2[$index].type=='tel'">
84
+		<input class="form-control-inline" type="tel" placeholder="787-123-4567" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" ng-required="entradas.col2[$index].require" name="{{entradas.col2[$index].name}}" value="{{entradas.col2[$index].value}}" style="width: 250px;height: 48px;align:left;">
85
+	</span>
86
+	<span ng-if="entradas.col2[$index].type=='date'">
87
+		<input class="form-control-inline" type="date" placeholder="yyyy-MM-dd" pattern="\d{4}-\d{1,2}-\d{1,2}" ng-required="entradas.col2[$index].require" name="{{entradas.col2[$index].name}}" value="{{entradas.col2[$index].value}}" style="width: 250px;height: 48px;align:left;">
88
+	</span>
89
+	<span ng-if="entradas.col2[$index].type!='select' && entradas.col2[$index].type!='checkbox' && entradas.col2[$index].type!='tel' && entradas.col2[$index].type!='date'">
90
+		<input class="form-control-inline" type="{{entradas.col2[$index].type}}" ng-required="entradas.col2[$index].require" name="{{entradas.col2[$index].name}}" value="{{entradas.col2[$index].value}}" style="width: 250px;height: 48px;align:left;">
77
 	</span>
91
 	</span>
78
-      {% endraw %}
79
   </span>
92
   </span>
80
 </div>
93
 </div>
81
 </span>
94
 </span>
95
+      {% endraw %}
96
+<input type="hidden" name="id" value="{{id}}">
97
+<input type="hidden" name="accion" value="{{accion}}">
98
+<input type="hidden" name="tipo" value="{{tipo}}">
82
 <input class="boton labelForma" type="submit">
99
 <input class="boton labelForma" type="submit">
83
 </form>
100
 </form>
84
 </div>
101
 </div>