msg.py 3.2 KB

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