config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from flask import Blueprint, render_template, request, abort, url_for
  5. import requests
  6. __author__ = 'James Iter'
  7. __date__ = '2017/8/29'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. blueprint = Blueprint(
  11. 'v_config',
  12. __name__,
  13. url_prefix='/config'
  14. )
  15. def show():
  16. config_url = url_for('api_config.r_get', _external=True)
  17. config_ret = requests.get(url=config_url, cookies=request.cookies)
  18. config_ret = json.loads(config_ret.content)
  19. # 检测 JimV 的配置是否已被初始化,只有未被初始化时,才展现初始化配置页面
  20. if config_ret['state']['code'] == '404':
  21. abort(404)
  22. return render_template('config_show.html', config=config_ret['data'])
  23. def create():
  24. config_url = url_for('api_config.r_get', _external=True)
  25. config_ret = requests.get(url=config_url, cookies=request.cookies)
  26. config_ret = json.loads(config_ret.content)
  27. # 检测 JimV 的配置是否已被初始化,只有未被初始化时,才展现初始化配置页面
  28. if config_ret['state']['code'] == '404':
  29. return render_template('config_init.html')
  30. else:
  31. abort(404)