msg.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:msg.py 消息相关
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. push = ({'id':'sms', 'name':'短信'}, {'id':'weixin', 'name':'微信'})
  9. class msg_path(Load):
  10. @Web.auth
  11. @Web.setting
  12. def get(self):
  13. self.set(
  14. name = u'消息'
  15. ,path = '/msg/msg'
  16. ,width = '600'
  17. ,height = '600'
  18. ,add = False
  19. ,edit = False
  20. ,full = True
  21. ,search = (('type_id-select-','content-input-mlike'), (u'硬件类型', u'消息内容'))
  22. ,thead = ( u'消息类型', u'消息内容', u'是否已读',u'发送时间')
  23. ,tbody = ('type', 'content', 'status', 'cdate')
  24. ,state = False
  25. )
  26. self.data['common']['search_type_id-select-'] = self.service('common').list('msg_type')
  27. self.list('msg')
  28. if self.data['list']:
  29. for key, value in enumerate(self.data['list']):
  30. htype = self.service('common').one('msg_type', id=value['type_id'])
  31. self.data['list'][key]['type'] = htype['name']
  32. if value['uid']:
  33. user = self.service('common').one('farm_user', id=value['uid'])
  34. self.data['list'][key]['user'] = user['username']
  35. else:
  36. self.data['list'][key]['user'] = '无'
  37. if value['status'] == True:
  38. self.data['list'][key]['status'] = '已读'
  39. else:
  40. self.data['list'][key]['status'] = '未读'
  41. self.show('list')
  42. class msg_update_path(Load):
  43. @Web.auth
  44. @Web.setting
  45. def get(self):
  46. self.set(
  47. path = '/msg/msg'
  48. ,label = (u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
  49. ,update = ('uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
  50. ,update_msg_type = self.service('common').list('msg_type')
  51. ,update_uid = self.service('common').list('farm_user')
  52. ,update_push = push
  53. )
  54. self.one('msg')
  55. self.show('update')
  56. @Web.auth
  57. @Web.setting
  58. def post(self):
  59. # 发消息
  60. self.update('msg')
  61. @Web.auth
  62. @Web.setting
  63. def delete(self):
  64. self.drop('msg')
  65. class type_path(Load):
  66. @Web.auth
  67. @Web.setting
  68. def get(self):
  69. self.set(
  70. name = u'消息类型'
  71. ,path = '/msg/type'
  72. ,width = '600'
  73. ,height = '300'
  74. ,search = (('name-input-mlike',), (u'类型名称',))
  75. ,thead = (u'类型ID', u'类型名称',u'类型key', u'更新时间')
  76. ,tbody = ('id', 'name', 'key', 'cdate')
  77. ,state = False
  78. ,add = False
  79. ,edit = False
  80. )
  81. self.list('msg_type')
  82. self.show('list')
  83. class type_update_path(Load):
  84. @Web.auth
  85. @Web.setting
  86. def get(self):
  87. self.set(
  88. path = '/msg/type'
  89. #,label = (u'类型名称', u'类型key',u'推送')
  90. #,update = ('name-input-required', 'key-input-required','push-checkbox-')
  91. ,label = (u'类型名称', u'类型key')
  92. ,update = ('name-input-required', 'key-input-required')
  93. ,update_push = push
  94. )
  95. self.one('msg_type')
  96. self.show('update')
  97. @Web.auth
  98. @Web.setting
  99. def post(self):
  100. self.update('msg_type')
  101. @Web.auth
  102. @Web.setting
  103. def delete(self):
  104. self.drop('msg_type')