context_processors.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.core.exceptions import PermissionDenied
  2. from django.urls import reverse
  3. from django.utils import six
  4. from .searchproviders import searchproviders
  5. def search_providers(request):
  6. allowed_providers = []
  7. try:
  8. if request.user.acl_cache['can_search']:
  9. allowed_providers = searchproviders.get_allowed_providers(request)
  10. except AttributeError:
  11. # is user has no acl_cache attribute, cease entire middleware
  12. # this is edge case that occurs when debug toolbar intercepts
  13. # the redirect response from logout page and runs context providers
  14. # with non-misago's anonymous user model that has no acl support
  15. return {}
  16. request.frontend_context['search'] = []
  17. for provider in allowed_providers:
  18. request.frontend_context['search'].append({
  19. 'id': provider.url,
  20. 'name': six.text_type(provider.name),
  21. 'icon': provider.icon,
  22. 'results': None,
  23. 'time': None,
  24. })
  25. return {}