home.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. __author__ = 'Ulric Qin'
  16. from rrd import app
  17. from rrd import config
  18. from flask import render_template, request, g
  19. from rrd.model.portal.host_group import HostGroup
  20. from rrd.utils.logger import logging
  21. log = logging.getLogger(__file__)
  22. @app.route('/portal/hostgroup', methods=["GET",])
  23. def home_get():
  24. page = int(request.args.get('p', 1))
  25. limit = int(request.args.get('limit', 10))
  26. query = request.args.get('q', '').strip()
  27. mine = request.args.get('mine', '1')
  28. me = g.user.name if mine == '1' else None
  29. vs, total = HostGroup.query(page, limit, query, me)
  30. log.debug(vs)
  31. return render_template(
  32. 'portal/group/index.html',
  33. data={
  34. 'vs': vs,
  35. 'total': total,
  36. 'query': query,
  37. 'limit': limit,
  38. 'page': page,
  39. 'mine': mine,
  40. 'is_root': g.user.name in config.MAINTAINERS,
  41. }
  42. )