__init__.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. import os
  16. import traceback
  17. from flask import Flask, request
  18. from flask.ext.babel import Babel, gettext
  19. from rrd import config
  20. #-- create app --
  21. app = Flask(__name__)
  22. app.config.from_object("rrd.config")
  23. babel = Babel(app)
  24. @app.errorhandler(Exception)
  25. def all_exception_handler(error):
  26. tb = traceback.format_exc()
  27. err_tip = gettext('Temporary error, please contact your administrator.')
  28. err_msg = err_tip + '\n\nError: %s\n\nTraceback:\n%s' %(error, tb)
  29. return '<pre>' + err_msg + '</pre>', 500
  30. @babel.localeselector
  31. def get_locale():
  32. return request.accept_languages.best_match(config.LANGUAGES.keys())
  33. @babel.timezoneselector
  34. def get_timezone():
  35. return app.config.get("BABEL_DEFAULT_TIMEZONE")
  36. from view import index
  37. from view.auth import auth
  38. from view.user import user
  39. from view.team import team
  40. from view.dashboard import chart, screen
  41. from view.portal import *