msg.py 3.1 KB

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