template.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # Fake "right now" time
  32. context['online'] = {'last': timezone.now()}
  33. context['tabs'] = []
  34. for extension in settings.PROFILE_EXTENSIONS:
  35. profile_module = import_module(extension + '.profile')
  36. try:
  37. append_links = profile_module.register_profile_extension(request)
  38. if append_links:
  39. for link in append_links:
  40. link = list(link)
  41. token = link[0][link[0].find('_') + 1:]
  42. context['tabs'].append({
  43. 'route': link[0],
  44. 'active': context['tab'] == token,
  45. 'name': link[1],
  46. })
  47. except AttributeError:
  48. pass
  49. return DjangoRequestContext(request, context)