base.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. """The base Controller API."""
  3. from tg import TGController, tmpl_context, flash
  4. from tg.render import render
  5. from tg import request, redirect
  6. from tg.i18n import ugettext as _, ungettext
  7. __all__ = ['BaseController']
  8. class BaseController(TGController):
  9. """
  10. Base class for the controllers in the application.
  11. Your web application should have one of these. The root of
  12. your application is used to compute URLs used by your app.
  13. """
  14. def __call__(self, environ, context):
  15. """Invoke the Controller"""
  16. # TGController.__call__ dispatches to the Controller method
  17. # the request is routed to.
  18. request.identity = request.environ.get('repoze.who.identity')
  19. tmpl_context.identity = request.identity
  20. return TGController.__call__(self, environ, context)
  21. def back_with_error(self, message):
  22. flash(message)
  23. redirect(request.headers['Referer'])
  24. def current_user():
  25. return request.environ.get('repoze.who.identity')['user']