-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinicio.py
49 lines (28 loc) · 1.17 KB
/
inicio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
import cherrypy
from cherrypy.lib.cptools import accept
import modelo
import templater
class Inicio:
"Clase que contiene los metodos principales para mostrar en el sitio web"
@cherrypy.expose
def index(self,entidad="nalada"):
methods = ('OPTIONS','GET','POST','PUT','DELETE')
method=cherrypy.request.method
if method not in methods:
raise cherrypy.HTTPError(400,'Bad Request')
best = accept(['text/html', 'application/json','text/json'])
respuesta=""
if best=="text/html":
respuesta= self.html(entidad)
else:
cherrypy.response.headers['Content-Type'] = 'application/json;charset=utf-8'
respuesta= self.json(entidad)
print entidad
return respuesta
def json(self,entidad):
return modelo.getLista(entidad)
def html(self,entidad):
return templater.leerArchivo("pruebajax")
if __name__ == "__main__":
print modelo.getLista("roles")