main.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:work.py
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. class index_path(Load):
  9. #权限控制,需要在Load类中自行做判断
  10. #@Web.auth
  11. #异步加载,增加执行效率
  12. @Web.setting
  13. def get(self):
  14. self.view("index.html")
  15. # 测试数据库 查询 /main/select
  16. class select_path(Load):
  17. @Web.setting
  18. def get(self):
  19. # 从get、post获取数据,默认值为1
  20. id = int(self.input('site', 1))
  21. site = Demeter.model('site')
  22. site.id = id
  23. self.data['site'] = site.select(type='fetchone')
  24. product = Demeter.model('product')
  25. product.site_id = id
  26. self.data['product'] = product.select(col = '*', order = 'cda2te desc', group = '', limit = '0,100')
  27. if not self.data['product']:
  28. Demeter.echo(product.sql)
  29. Demeter.echo(product.bind)
  30. Demeter.echo(product.log)
  31. self.view('index.html')
  32. # 测试数据库 更新和插入 /main/update
  33. class update_path(Load):
  34. @Web.setting
  35. def get(self):
  36. id = int(self.input('site', 1))
  37. name = self.input('name', 'tests')
  38. site = Demeter.model('site')
  39. site.id = id
  40. state = site.update(name=name)
  41. self.data['site'] = site.select(type='fetchone')
  42. self.view('index.html')
  43. # 测试json /main/json
  44. class json_path(Load):
  45. @Web.setting
  46. def get(self):
  47. id = int(self.input('site', 1))
  48. name = self.input('name', 'tests')
  49. site = Demeter.model('site')
  50. site.id = id
  51. state = site.update(name=name)
  52. data = site.select(type='fetchone')
  53. self.out('yes', data)
  54. # 测试数据库 使用sql(不建议使用) /main/sql.html
  55. class sql_html(Load):
  56. @Web.setting
  57. def get(self):
  58. id = int(self.input('site', 1))
  59. name = self.input('name', 'tests')
  60. site = Demeter.model('site')
  61. state = site.query('update demeter_site set name = %s where id = %s', (name,id))
  62. self.data['site'] = site.query('select * from demeter_site where id = %s', (id))
  63. self.view('index.html')