msg.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. def get(self):
  13. self.common(
  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.commonList('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]['device'] = '未读'
  44. self.commonView('list')
  45. class msg_update_path(Load):
  46. @Web.auth
  47. def get(self):
  48. self.common(
  49. path = '/msg/msg'
  50. ,label = (u'所属农场',u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
  51. ,update = ('farm_id-select--uid','uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
  52. ,update_msg_type = self.service('common').list('msg_type')
  53. ,update_farm_id = Demeter.config['setting']['farmList']
  54. ,update_uid = self.service('common').list('farm_user')
  55. ,update_push = push
  56. )
  57. self.commonOne('msg')
  58. self.commonView('update')
  59. @Web.auth
  60. def post(self):
  61. # 发消息
  62. self.commonUpdate('msg')
  63. @Web.auth
  64. def delete(self):
  65. self.commonDelete('msg')
  66. class type_path(Load):
  67. @Web.auth
  68. def get(self):
  69. self.common(
  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. )
  79. self.commonList('msg_type')
  80. self.commonView('list')
  81. class type_update_path(Load):
  82. @Web.auth
  83. def get(self):
  84. self.common(
  85. path = '/msg/type'
  86. ,label = (u'类型名称', u'类型key',u'推送')
  87. ,update = ('name-input-required', 'key-input-required','push-checkbox-')
  88. ,update_push = push
  89. )
  90. self.commonOne('msg_type')
  91. self.commonView('update')
  92. @Web.auth
  93. def post(self):
  94. self.commonUpdate('msg_type')
  95. @Web.auth
  96. def delete(self):
  97. self.commonDelete('msg_type')