__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_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. if not config.DEBUG:
  25. @app.errorhandler(Exception)
  26. def all_exception_handler(error):
  27. tb = traceback.format_exc()
  28. err_tip = gettext('Temporary error, please contact your administrator.')
  29. err_msg = err_tip + '\n\nError: %s\n\nTraceback:\n%s' %(error, tb)
  30. return '<pre>' + err_msg + '</pre>', 500
  31. @babel.localeselector
  32. def get_locale():
  33. return request.accept_languages.best_match(config.LANGUAGES.keys())
  34. @babel.timezoneselector
  35. def get_timezone():
  36. return app.config.get("BABEL_DEFAULT_TIMEZONE")
  37. from view import index
  38. from view.auth import auth
  39. from view.user import user
  40. from view.team import team
  41. from view.dashboard import chart, screen
  42. from view.portal import *