msg.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 = (('farm_id-select-','type_id-select-','content-input-mlike'), (u'选择农场',u'硬件类型', u'消息内容'))
  22. ,thead = (u'所属农场', u'消息类型', u'消息内容', u'是否已读',u'发送时间')
  23. ,tbody = ('farm','type', 'content', 'status', 'cdate')
  24. ,state = False
  25. )
  26. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  27. self.data['common']['search_type_id-select-'] = self.service('common').list('msg_type')
  28. self.list('msg')
  29. if self.data['list']:
  30. for key, value in enumerate(self.data['list']):
  31. farm = self.service('common').one('farm', id=value['farm_id'])
  32. self.data['list'][key]['farm'] = farm['name']
  33. htype = self.service('common').one('msg_type', id=value['type_id'])
  34. self.data['list'][key]['type'] = htype['name']
  35. if value['uid']:
  36. user = self.service('common').one('farm_user', id=value['uid'])
  37. self.data['list'][key]['user'] = user['username']
  38. else:
  39. self.data['list'][key]['user'] = '无'
  40. if value['status'] == True:
  41. self.data['list'][key]['status'] = '已读'
  42. else:
  43. self.data['list'][key]['status'] = '未读'
  44. self.show('list')
  45. class msg_update_path(Load):
  46. @Web.auth
  47. @Web.setting
  48. def get(self):
  49. self.set(
  50. path = '/msg/msg'
  51. ,label = (u'所属农场',u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
  52. ,update = ('farm_id-select--uid','uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
  53. ,update_msg_type = self.service('common').list('msg_type')
  54. ,update_farm_id = self.service('common').list('farm', search={'eros_status':2})
  55. ,update_uid = self.service('common').list('farm_user')
  56. ,update_push = push
  57. )
  58. self.one('msg')
  59. self.show('update')
  60. @Web.auth
  61. @Web.setting
  62. def post(self):
  63. # 发消息
  64. self.update('msg')
  65. @Web.auth
  66. @Web.setting
  67. def delete(self):
  68. self.drop('msg')
  69. class type_path(Load):
  70. @Web.auth
  71. @Web.setting
  72. def get(self):
  73. self.set(
  74. name = u'消息类型'
  75. ,path = '/msg/type'
  76. ,width = '600'
  77. ,height = '300'
  78. ,search = (('name-input-mlike',), (u'类型名称',))
  79. ,thead = (u'类型ID', u'类型名称',u'类型key', u'更新时间')
  80. ,tbody = ('id', 'name', 'key', 'cdate')
  81. ,state = False
  82. )
  83. self.list('msg_type')
  84. self.show('list')
  85. class type_update_path(Load):
  86. @Web.auth
  87. @Web.setting
  88. def get(self):
  89. self.set(
  90. path = '/msg/type'
  91. #,label = (u'类型名称', u'类型key',u'推送')
  92. #,update = ('name-input-required', 'key-input-required','push-checkbox-')
  93. ,label = (u'类型名称', u'类型key')
  94. ,update = ('name-input-required', 'key-input-required')
  95. ,update_push = push
  96. )
  97. self.one('msg_type')
  98. self.show('update')
  99. @Web.auth
  100. @Web.setting
  101. def post(self):
  102. self.update('msg_type')
  103. @Web.auth
  104. @Web.setting
  105. def delete(self):
  106. self.drop('msg_type')