msg.py 3.3 KB

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