12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- from datetime import timedelta
- from django.conf import settings
- from django.template import RequestContext as DjangoRequestContext
- from django.utils import timezone
- from django.utils.importlib import import_module
- from misago.users.models import User
- def RequestContext(request, context=None):
- if not context:
- context = {}
- context['fallback'] = request.path
-
- # Find out if we ignore or follow this user
- context['follows'] = False
- context['ignores'] = False
- if request.user.is_authenticated() and request.user.pk != context['profile'].pk:
- context['follows'] = request.user.is_following(context['profile'])
- context['ignores'] = request.user.is_ignoring(context['profile'])
-
- # Find out if this user allows us to see his activity
- if request.user.pk != context['profile'].pk:
- if context['profile'].hide_activity == 2:
- context['hidden'] = True
- if context['profile'].hide_activity == 1:
- context['hidden'] = context['profile'].is_following(request.user)
- else:
- context['hidden'] = False
- # Find out if this user is online:
- if request.user.pk != context['profile'].pk:
- try:
- context['online'] = context['profile'].sessions.filter(admin=False).filter(last__gt=(timezone.now() - timedelta(minutes=10))).order_by('-last')[0:1][0]
- except IndexError:
- context['online'] = False
- else:
- # Fake "right now" time
- context['online'] = {'last': timezone.now()}
- context['tabs'] = []
- for extension in settings.PROFILE_EXTENSIONS:
- profile_module = import_module(extension + '.profile')
- try:
- append_links = profile_module.register_profile_extension(request)
- if append_links:
- for link in append_links:
- link = list(link)
- token = link[0][link[0].find('_') + 1:]
- context['tabs'].append({
- 'route': link[0],
- 'active': context['tab'] == token,
- 'name': link[1],
- })
- except AttributeError:
- pass
- return DjangoRequestContext(request, context)
|