template.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. # Find out if this user allows us to see his activity
  16. if request.user.pk != context['profile'].pk:
  17. if context['profile'].hide_activity == 2:
  18. context['hidden'] = True
  19. if context['profile'].hide_activity == 1:
  20. context['hidden'] = context['profile'].is_following(request.user)
  21. else:
  22. context['hidden'] = False
  23. # Find out if this user is online:
  24. if request.user.pk != context['profile'].pk:
  25. context['online'] = context['profile'].sessions.count() > 0
  26. else:
  27. context['online'] = True
  28. context['tabs'] = []
  29. for extension in settings.PROFILE_EXTENSIONS:
  30. profile_module = import_module(extension + '.profile')
  31. try:
  32. append_links = profile_module.register_profile_extension(request)
  33. if append_links:
  34. for link in append_links:
  35. link = list(link)
  36. token = link[0][link[0].find('_') + 1:]
  37. context['tabs'].append({
  38. 'route': link[0],
  39. 'active': context['tab'] == token,
  40. 'name': link[1],
  41. })
  42. except AttributeError:
  43. pass
  44. return DjangoRequestContext(request, context)