host.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from flask import Blueprint, render_template, url_for, request
  5. import requests
  6. from math import ceil
  7. __author__ = 'James Iter'
  8. __date__ = '2017/8/10'
  9. __contact__ = 'james.iter.cn@gmail.com'
  10. __copyright__ = '(c) 2017 by James Iter.'
  11. blueprint = Blueprint(
  12. 'v_host',
  13. __name__,
  14. url_prefix='/host'
  15. )
  16. blueprints = Blueprint(
  17. 'v_hosts',
  18. __name__,
  19. url_prefix='/hosts'
  20. )
  21. def show():
  22. args = list()
  23. page = int(request.args.get('page', 1))
  24. page_size = int(request.args.get('page_size', 10))
  25. keyword = request.args.get('keyword', None)
  26. resource_path = request.path
  27. if page is not None:
  28. args.append('page=' + page.__str__())
  29. if page_size is not None:
  30. args.append('page_size=' + page_size.__str__())
  31. if keyword is not None:
  32. args.append('keyword=' + keyword.__str__())
  33. host_url = request.host_url.rstrip('/')
  34. hosts_url = host_url + url_for('api_hosts.r_get_by_filter')
  35. if keyword is not None:
  36. hosts_url = host_url + url_for('api_hosts.r_content_search')
  37. if args.__len__() > 0:
  38. hosts_url = hosts_url + '?' + '&'.join(args)
  39. hosts_ret = requests.get(url=hosts_url)
  40. hosts_ret = json.loads(hosts_ret.content)
  41. return render_template('hosts_show.html', hosts_ret=hosts_ret, resource_path=resource_path, keyword=keyword)