Browse Source

User profile sidebar

Rafał Pitoń 11 years ago
parent
commit
c326662cc4

+ 19 - 0
misago/static/misago/css/misago/profile.less

@@ -24,7 +24,14 @@
 .user-profile {
   .profile-side {
     .user-name {
+      margin-bottom: @line-height-computed;
+
       font-size: @font-size-base * 1.8;
+
+      .user-title {
+        display: block;
+        clear: both;
+      }
     }
   }
 }
@@ -58,3 +65,15 @@
     }
   }
 }
+
+
+// Flavours
+//
+//==
+.user-profile {
+  &.profile-team {
+    .user-title {
+      color: @brand-primary;
+    }
+  }
+}

+ 9 - 27
misago/templates/misago/profile/base.html

@@ -1,5 +1,5 @@
 {% extends "misago/base.html" %}
-{% load humanize i18n misago_avatars misago_capture %}
+{% load humanize i18n misago_avatars %}
 
 
 {% block title %}
@@ -8,10 +8,9 @@
 
 
 {% block content %}
-<div class="container user-profile">
+<div class="container user-profile {% if profile.rank.css_class %}profile-{{ profile.rank.css_class }}{% endif %}">
   <div class="row">
     <div class="col-md-3 profile-side">
-
       <div class="user-avatar">
         {% if authenticateds_profile %}
         <a href="{% url 'misago:usercp_change_avatar' %}" class="tooltip-top" title="{% trans "Change your avatar" %}">
@@ -22,7 +21,12 @@
         {% endif %}
       </div>
 
-      <h1 class="user-name">{{ profile.username }}</h1>
+      <h1 class="user-name">
+        {{ profile.username }}
+        {% if profile.full_title %}
+        <small class="user-title">{{ profile.full_title }}</small>
+        {% endif %}
+      </h1>
 
       <div class="user-details">
         <ul class="list-unstyled">
@@ -35,29 +39,7 @@
           </li>
           {% endif %}
           <li class="user-active">
-            {% if state.is_banned %}
-              <span class="fa fa-lock fa-fw user-banned"></span>
-              {% if state.banned_until %}
-              {% blocktrans trimmed with ban_date=state.banned_until|date %}
-                Banned until {{ ban_date }}
-              {% endblocktrans %}
-              {% else %}
-              {% trans "Banned" %}
-              {% endif %}
-            {% elif state.is_online %}
-              <span class="fa fa-circle fa-fw user-online"></span>
-              {% trans "Online" %}
-            {% else %}
-              {% capture trimmed as last_seen %}
-              <abbr class="tooltip-top dynamic time-ago" title="{{ state.last_click }}" data-timestamp="{{ state.last_click|date:"c" }}">
-                {{ state.last_click|date }}
-              </abbr>
-              {% endcapture %%}
-              <span class="fa fa-circle-o fa-fw user-offilne"></span>
-              {% blocktrans trimmed with last_seen=last_seen|safe %}
-                Seen {{ last_seen }}
-              {% endblocktrans %}
-            {% endif %}
+            {% include "misago/profile/state.html" %}
           </li>
           <li class="user-joined-on">
             <span class="tooltip-top" title="{% trans "Joined on" %}">

+ 40 - 0
misago/templates/misago/profile/state.html

@@ -0,0 +1,40 @@
+{% load i18n misago_capture %}
+{% if state.is_banned %}
+  <span class="fa fa-lock fa-fw user-banned"></span>
+  {% if state.banned_until %}
+  {% blocktrans trimmed with ban_date=state.banned_until|date %}
+    Banned until {{ ban_date }}
+  {% endblocktrans %}
+  {% else %}
+  {% trans "Banned" %}
+  {% endif %}
+{% elif state.is_hidden %}
+  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  {% trans "Hides activity" %}
+{% elif state.is_online_hidden %}
+  <span class="fa fa-circle fa-fw user-online"></span>
+  {% trans "Online, hidden" %}
+{% elif state.is_offline_hidden %}
+  {% capture trimmed as last_seen %}
+  <abbr class="tooltip-top dynamic time-ago" title="{{ state.last_click }}" data-timestamp="{{ state.last_click|date:"c" }}">
+    {{ state.last_click|date }}
+  </abbr>
+  {% endcapture %%}
+  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  {% blocktrans trimmed with last_seen=last_seen|safe %}
+    Seen {{ last_seen }}, hidden
+  {% endblocktrans %}
+{% elif state.is_online %}
+  <span class="fa fa-circle fa-fw user-online"></span>
+  {% trans "Online" %}
+{% elif state.is_offline %}
+  {% capture trimmed as last_seen %}
+  <abbr class="tooltip-top dynamic time-ago" title="{{ state.last_click }}" data-timestamp="{{ state.last_click|date:"c" }}">
+    {{ state.last_click|date }}
+  </abbr>
+  {% endcapture %%}
+  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  {% blocktrans trimmed with last_seen=last_seen|safe %}
+    Seen {{ last_seen }}
+  {% endblocktrans %}
+{% endif%}

+ 8 - 0
misago/users/models/user.py

@@ -235,6 +235,14 @@ class User(AbstractBaseUser, PermissionsMixin):
         raise TypeError('Cannot make User instances ACL aware')
 
     @property
+    def full_title(self):
+        return self.title or self.rank.name
+
+    @property
+    def short_title(self):
+        return self.title or self.rank.title
+
+    @property
     def requires_activation_by_admin(self):
         return self.requires_activation == ACTIVATION_REQUIRED_ADMIN
 

+ 26 - 7
misago/users/online.py

@@ -12,10 +12,14 @@ ACTIVITY_CUTOFF = timedelta(minutes=15)
 def state_for_acl(user, acl):
     user_state = {
         'is_banned': False,
-        'banned_until': False,
-        'is_online': False,
         'is_hidden': user.is_hiding_presence,
-        'last_click': user.last_login,
+        'is_online_hidden': False,
+        'is_offline_hidden': False,
+        'is_online': False,
+        'is_offline': False,
+
+        'banned_until': None,
+        'last_click': user.last_login or user.joined_on,
     }
 
     user_ban = get_user_ban(user)
@@ -24,11 +28,26 @@ def state_for_acl(user, acl):
         user_state['banned_until'] = user_ban.valid_until
 
     try:
-        online_tracker = user.online_tracker
-        if online_tracker.last_click >= timezone.now() - ACTIVITY_CUTOFF:
-            user_state['is_online'] = True
-            user_state['last_click'] = online_tracker.last_click
+        if not user.is_hiding_presence or acl['can_see_hidden_users']:
+            online_tracker = user.online_tracker
+            if online_tracker.last_click >= timezone.now() - ACTIVITY_CUTOFF:
+                user_state['is_online'] = True
+                user_state['last_click'] = online_tracker.last_click
     except Online.DoesNotExist:
         pass
 
+    if user_state['is_hidden']:
+        if acl['can_see_hidden_users']:
+            if user_state['is_online']:
+                user_state['is_online_hidden'] = True
+            else:
+                user_state['is_offline_hidden'] = True
+        else:
+            user_state['is_hidden'] = True
+    else:
+        if user_state['is_online']:
+            user_state['is_online'] = True
+        else:
+            user_state['is_offline'] = True
+
     return user_state

+ 1 - 0
misago/users/views/admin/users.py

@@ -225,6 +225,7 @@ class EditUser(UserAdmin, generic.ModelFormView):
         if 'staff_level' in form.cleaned_data:
             target.staff_level = form.cleaned_data['staff_level']
 
+        target.rank = form.cleaned_data.get('rank')
         if form.cleaned_data.get('roles'):
             target.roles.add(*form.cleaned_data['roles'])
 

+ 1 - 1
misago/users/views/profile.py

@@ -8,7 +8,7 @@ from misago.users import online
 
 def profile_view(f):
     def decorator(*args, **kwargs):
-        relations = ('online_tracker', 'ban_cache')
+        relations = ('rank', 'online_tracker', 'ban_cache')
         queryset = get_user_model().objects.select_related(*relations)
         profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))