divide admin and users

This commit is contained in:
cuom1999 2020-06-08 18:19:09 -05:00
parent 7e4c104a56
commit 19665c557f
3 changed files with 46 additions and 11 deletions

View file

@ -21,6 +21,18 @@ def format_messages(messages):
} for msg in messages] } for msg in messages]
return json.dumps(msg_list, default=str) return json.dumps(msg_list, default=str)
def get_admin_online_status():
all_admin = Profile.objects.filter(display_rank='admin')
last_five_minutes = timezone.now()-timezone.timedelta(minutes=5)
ret = []
for admin in all_admin:
is_online = False
if (admin.last_access >= last_five_minutes):
is_online = True
ret.append({'user': admin, 'is_online': is_online})
return ret
class ChatView(ListView): class ChatView(ListView):
model = Message model = Message
@ -47,7 +59,10 @@ class ChatView(ListView):
context['title'] = self.title context['title'] = self.title
last_five_minutes = timezone.now()-timezone.timedelta(minutes=5) last_five_minutes = timezone.now()-timezone.timedelta(minutes=5)
context['online_users'] = Profile.objects \ context['online_users'] = Profile.objects \
.filter(last_access__gte = last_five_minutes) .filter(display_rank='user',
last_access__gte = last_five_minutes)\
.order_by('-rating')
context['admin_status'] = get_admin_online_status()
return context return context
def delete_message(request): def delete_message(request):

View file

@ -101,16 +101,20 @@
width: 100%; width: 100%;
} }
.dot { .green-dot, .red-dot {
height: 0.8em; height: 0.8em;
width: 0.8em; width: 0.8em;
background-color: #39ff14;
border-radius: 50%; border-radius: 50%;
display: inline-block; display: inline-block;
margin-bottom: -0.2em; margin-bottom: -0.15em;
border: 1px lightgreen solid; }
.green-dot {
background-color: #42f58d;
} }
.red-dot {
background-color: red;
}
@media (min-width: 800px) { @media (min-width: 800px) {
#chat-container { #chat-container {

View file

@ -212,8 +212,8 @@
</script> </script>
{% endblock js_media %} {% endblock js_media %}
<!--
{% block media %} <!-- {% block media %}
<style> <style>
</style> </style>
{% endblock media %} {% endblock media %}
@ -246,11 +246,27 @@
<i class="fa fa-wifi"></i> <i class="fa fa-wifi"></i>
</h3> </h3>
<ul id="chat-online-content"> <ul id="chat-online-content">
{% for user in online_users %} <h4>{{_('Admins')}}: </h4>
<li> <hr/>
<span class="dot"></span> {% for user in admin_status %}
<li style="padding-left: 1em">
{% if user.is_online %}
<span class="green-dot"></span>
{% else %}
<span class="red-dot"></span>
{% endif %}
<span style="padding-left:0.25em"> <span style="padding-left:0.25em">
{{ link_user(user) }} {{ link_user(user.user) }}
</span>
</li>
{% endfor %}
<h4 style="margin-top:1em;">{{_('Users')}}: </h4>
<hr/>
{% for user in online_users %}
<li style="padding-left: 1em">
<span class="green-dot"></span>
<span style="padding-left:0.25em">
{{ link_user(user.user) }}
</span> </span>
</li> </li>
{% endfor %} {% endfor %}