Просмотр исходного кода

Little tweaks of user on-line status in his profile

Ralfp 12 лет назад
Родитель
Сommit
0f7c91c24c
2 измененных файлов с 17 добавлено и 3 удалено
  1. 6 2
      misago/profiles/template.py
  2. 11 1
      templates/sora/profiles/profile.html

+ 6 - 2
misago/profiles/template.py

@@ -1,5 +1,6 @@
 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
 
@@ -26,9 +27,12 @@ def RequestContext(request, context=None):
 
     # Find out if this user is online:
     if request.user.pk != context['profile'].pk:
-        context['online'] = context['profile'].sessions.count() > 0
+        try:
+            context['online'] = context['profile'].sessions.filter(admin=False).order_by('-last')[0:1][0]
+        except IndexError:
+            context['online'] = False
     else:
-        context['online'] = True
+        context['online'] = timezone.now()
 
     context['tabs'] = []
     for extension in settings.PROFILE_EXTENSIONS:

+ 11 - 1
templates/sora/profiles/profile.html

@@ -20,7 +20,17 @@
               {% trans %}Online, hidden{% endtrans %}
               {%- else -%}
               {% trans %}Online{% endtrans %}
-              {%- endif %}</span>{% else %}<span class="badge">{% trans %}Offline{% endtrans %}</span>{% endif %} <span class="muted">{% trans last_visit=profile.last_date|reltimesince|low %}Last seen {{ last_visit }}{% endtrans %}</span>
+              {%- endif %}</span>{% else %}<span class="badge">{% trans %}Offline{% endtrans %}</span>{% endif %} <span class="muted">{% if not hidden or acl.users.can_see_hidden_users() -%}
+                    {%- if online -%}
+                      {% trans last_click=online|reltimesince|low %}Last click {{ last_click }}{% endtrans %}
+                    {%- elif profile.last_date -%}
+                      {% trans last_visit=profile.last_date|reltimesince|low %}Last seen {{ last_visit }}{% endtrans %}
+                    {%- else -%}
+                      {% trans %}Never visited{% endtrans %}
+                    {%- endif -%}
+                  {%- else -%}
+                    {% trans %}Hiding activity{% endtrans %}
+                  {%- endif %}</span>
         </p>
       </div>
     </div>