mixins.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # coding: utf-8
  2. #
  3. # Copyright (C) 2014 Enrico Zini <enrico@debian.org>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. from __future__ import print_function
  18. from __future__ import absolute_import
  19. from __future__ import division
  20. from __future__ import unicode_literals
  21. from backend.mixins import VisitorMixin
  22. from . import authenticate
  23. class APIVisitorMixin(VisitorMixin):
  24. """
  25. Allow to use api keys to set visitor information
  26. """
  27. def set_visitor_info(self):
  28. # Try the default from VisitorMixin
  29. super(APIVisitorMixin, self).set_visitor_info()
  30. # If it failed, try again with API key
  31. if self.visitor is None:
  32. self.visitor = authenticate(self.request)