From 19665c557f7999629cc470346b562802484d2032 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 8 Jun 2020 18:19:09 -0500 Subject: [PATCH] divide admin and users --- chat_box/views.py | 17 ++++++++++++++++- resources/chatbox.scss | 12 ++++++++---- templates/chat/chat.html | 28 ++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/chat_box/views.py b/chat_box/views.py index 8ca6462..d067cb0 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -21,6 +21,18 @@ def format_messages(messages): } for msg in messages] 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): model = Message @@ -47,7 +59,10 @@ class ChatView(ListView): context['title'] = self.title last_five_minutes = timezone.now()-timezone.timedelta(minutes=5) 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 def delete_message(request): diff --git a/resources/chatbox.scss b/resources/chatbox.scss index 2b6de7f..ad8ed17 100644 --- a/resources/chatbox.scss +++ b/resources/chatbox.scss @@ -101,16 +101,20 @@ width: 100%; } -.dot { +.green-dot, .red-dot { height: 0.8em; width: 0.8em; - background-color: #39ff14; border-radius: 50%; display: inline-block; - margin-bottom: -0.2em; - border: 1px lightgreen solid; + margin-bottom: -0.15em; +} +.green-dot { + background-color: #42f58d; } +.red-dot { + background-color: red; +} @media (min-width: 800px) { #chat-container { diff --git a/templates/chat/chat.html b/templates/chat/chat.html index 26fb1da..26c9522 100644 --- a/templates/chat/chat.html +++ b/templates/chat/chat.html @@ -212,8 +212,8 @@ {% endblock js_media %} -