site.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:site.py 站点相关
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. class site_path(Load):
  9. @Web.auth
  10. @Web.setting
  11. def get(self):
  12. self.set(
  13. name = u'站点管理'
  14. ,path = '/site/site'
  15. ,width = '600'
  16. ,height = '600'
  17. ,search = (('label-1','workdate-time-start','workdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'站点名称'))
  18. ,thead = (u'站点名称', u'快捷功能', u'授权信息', u'授权时间')
  19. ,tbody = ('name', 'func', 'app', 'time')
  20. ,state = True
  21. )
  22. menu = (
  23. {'name':'转换文件列表', 'url':'/site/convert'}
  24. ,
  25. )
  26. self.list('site')
  27. if self.data['list']:
  28. for key, value in enumerate(self.data['list']):
  29. id = str(value['id'])
  30. self.data['list'][key]['time'] = Demeter.date(value['sdate']) + ' 至 ' + Demeter.date(value['edate'])
  31. self.data['list'][key]['app'] = u'[appid]:' + value['appid'] + u'<br />[appsecret]:' + value['appsecret']
  32. param = '?search_site_id-select-=' + id
  33. self.data['list'][key]['func'] = ''
  34. for i in menu:
  35. self.data['list'][key]['func'] = self.data['list'][key]['func'] + '<a href="'+i['url']+''+param+'">'+i['name']+'</a>&nbsp;&nbsp;&nbsp;&nbsp;'
  36. self.show('list')
  37. class site_update_path(Load):
  38. @Web.auth
  39. @Web.setting
  40. def get(self):
  41. self.set(
  42. path = '/site/site'
  43. ,label = (u'站点名称',u'站点网址',u'通知接口',u'限制页数',u'开始时间', u'结束时间')
  44. ,update = ('name-input-required','link-input-required','api-input-required','page-input-required','sdate-date-required','edate-date-required')
  45. )
  46. self.one('site')
  47. self.show('update')
  48. @Web.auth
  49. @Web.setting
  50. def post(self):
  51. id = self.input('id')
  52. if not id:
  53. self.getAppId()
  54. else:
  55. info = self.service('common').one('site', id=id)
  56. if not info['appid']:
  57. self.getAppId()
  58. self.update('site')
  59. @Web.auth
  60. @Web.setting
  61. def delete(self):
  62. self.drop('site')
  63. @Web.auth
  64. @Web.setting
  65. def getAppId(self):
  66. self.data['update']['appid'] = Demeter.compressUuid(Demeter.uuid('convert'))
  67. self.data['update']['appsecret'] = Demeter.hash()
  68. model = Demeter.model('site')
  69. model.appid = self.data['update']['appid']
  70. model.appsecret = self.data['update']['appsecret']
  71. info = model.select(type='fetchone')
  72. if info:
  73. self.getAppId()
  74. class convert_path(Load):
  75. @Web.auth
  76. @Web.setting
  77. def get(self):
  78. self.set(
  79. name = u'转换的文件'
  80. ,path = '/site/convert'
  81. ,width = '600'
  82. ,height = '600'
  83. ,edit = False
  84. ,search = (('label-1','cdate-time-start','cdate-time-end','site_id-select-','status-select-','name-input-mlike','url-input-mlike','file_id-input-'), (u'日期范围',u'开始时间',u'截止时间',u'选择站点',u'选择状态',u'源文件名',u'新文件名',u'文件ID'))
  85. ,thead = (u'文件id',u'所属站点', u'源文件', u'文件名', u'访问路径', u'状态', u'更新时间')
  86. ,tbody = ('id','site', 'file','name', 'url', 'status', 'cdate')
  87. ,state = True
  88. )
  89. self.data['common']['search_site_id-select-'] = self.service('common').list('site')
  90. self.data['common']['search_status-select-'] = [{'id':1,'value':1,'name':u'待机'},{'id':2,'value':2, 'name':u'转换中'},{'id':3,'value':3,'name':u'转换完成'},{'id':4,'value':4,'name':u'转换失败'}]
  91. self.list('convert')
  92. status = {}
  93. status[1] = '待机'
  94. status[2] = '转换中'
  95. status[3] = '转换完成'
  96. status[4] = '转换失败'
  97. if self.data['list']:
  98. for key, value in enumerate(self.data['list']):
  99. site = self.service('common').one('site', id=value['site_id'])
  100. self.data['list'][key]['site'] = site['name']
  101. if value['status'] == 3:
  102. self.data['list'][key]['url'] = '<a href="'+str(value['url']).replace('.html', '.pdf')+'" target="_blank">[点此访问]</a>'
  103. else:
  104. self.data['list'][key]['url'] = '无法访问'
  105. self.data['list'][key]['status'] = status[value['status']]
  106. if 'file_id' in value:
  107. self.data['list'][key]['file'] = value['file'] + ':' + value['file_id']
  108. self.show('list')
  109. class convert_update_path(Load):
  110. @Web.auth
  111. @Web.setting
  112. def get(self):
  113. status = [
  114. {'id':'1', 'name': '待机'},
  115. ]
  116. self.set(
  117. path = '/site/convert'
  118. ,label = (u'所属站点', u'源文件路径', u'状态')
  119. ,update = ('site_id-select-required', 'file-input-required', 'status-select-')
  120. ,update_site_id = self.service('common').list('site')
  121. ,update_status = status
  122. )
  123. self.one('convert')
  124. self.show('update')
  125. @Web.auth
  126. @Web.setting
  127. def post(self):
  128. model = Demeter.model('site')
  129. model.id = self.data['update']['site_id']
  130. site = model.select(type='fetchone')
  131. info = self.service('convert').getFile(site['key'], self.data['update']['file'])
  132. self.data['update']['uid'] = -1
  133. self.data['update']['file_id'] = -1
  134. self.data['update']['file_type'] = 2
  135. self.data['update']['name'] = info['name']
  136. self.data['update']['key'] = info['key']
  137. self.data['update']['ext'] = info['ext']
  138. self.data['update']['local'] = info['local']
  139. self.data['update']['path'] = info['path']
  140. self.data['update']['pdf'] = info['pdf']
  141. self.data['update']['html'] = info['html']
  142. self.data['update']['url'] = info['url']
  143. sid = self.update('convert')
  144. if sid:
  145. redis = Demeter.redis()
  146. config = Demeter.config['redis']
  147. redis.rpush(config['name'], sid)
  148. @Web.auth
  149. @Web.setting
  150. def delete(self):
  151. self.drop('convert')