template.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.conf import settings
  2. from django.template import RequestContext as DjangoRequestContext
  3. from django.utils.importlib import import_module
  4. from misago.users.models import User
  5. def RequestContext(request, context=None):
  6. if not context:
  7. context = {}
  8. context['fallback'] = request.path
  9. # Find out if we ignore or follow this user
  10. context['follows'] = False
  11. context['ignores'] = False
  12. if request.user.is_authenticated() and request.user.pk != context['profile'].pk:
  13. context['follows'] = request.user.is_following(context['profile'])
  14. context['ignores'] = request.user.is_ignoring(context['profile'])
  15. context['tabs'] = []
  16. for extension in settings.PROFILE_EXTENSIONS:
  17. profile_module = import_module(extension + '.profile')
  18. try:
  19. append_links = profile_module.register_profile_extension(request)
  20. if append_links:
  21. for link in append_links:
  22. link = list(link)
  23. token = link[0][link[0].find('_') + 1:]
  24. context['tabs'].append({
  25. 'route': link[0],
  26. 'active': context['tab'] == token,
  27. 'name': link[1],
  28. })
  29. except AttributeError:
  30. pass
  31. return DjangoRequestContext(request, context)