template.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from django.conf import settings
  2. from django.template import RequestContext as DjangoRequestContext
  3. from django.utils import timezone
  4. from django.utils.importlib import import_module
  5. from misago.users.models import User
  6. def RequestContext(request, context=None):
  7. if not context:
  8. context = {}
  9. context['fallback'] = request.path
  10. # Find out if we ignore or follow this user
  11. context['follows'] = False
  12. context['ignores'] = False
  13. if request.user.is_authenticated() and request.user.pk != context['profile'].pk:
  14. context['follows'] = request.user.is_following(context['profile'])
  15. context['ignores'] = request.user.is_ignoring(context['profile'])
  16. # Find out if this user allows us to see his activity
  17. if request.user.pk != context['profile'].pk:
  18. if context['profile'].hide_activity == 2:
  19. context['hidden'] = True
  20. if context['profile'].hide_activity == 1:
  21. context['hidden'] = context['profile'].is_following(request.user)
  22. else:
  23. context['hidden'] = False
  24. # Find out if this user is online:
  25. if request.user.pk != context['profile'].pk:
  26. try:
  27. context['online'] = context['profile'].sessions.filter(admin=False).order_by('-last')[0:1][0]
  28. except IndexError:
  29. context['online'] = False
  30. else:
  31. context['online'] = timezone.now()
  32. context['tabs'] = []
  33. for extension in settings.PROFILE_EXTENSIONS:
  34. profile_module = import_module(extension + '.profile')
  35. try:
  36. append_links = profile_module.register_profile_extension(request)
  37. if append_links:
  38. for link in append_links:
  39. link = list(link)
  40. token = link[0][link[0].find('_') + 1:]
  41. context['tabs'].append({
  42. 'route': link[0],
  43. 'active': context['tab'] == token,
  44. 'name': link[1],
  45. })
  46. except AttributeError:
  47. pass
  48. return DjangoRequestContext(request, context)