Simple messages display

This commit is contained in:
Pengwius 2021-01-02 21:50:26 +01:00
parent b3f40570c9
commit 3661ddef7a
7 changed files with 108 additions and 13 deletions

View file

@ -13,7 +13,7 @@ def get_messages(register_id, register_r, oun, s, date, school_year, symbol):
sent_messages = []
deleted_messages = []
messages = s.get('https://uonetplus-uzytkownik.vulcan.net.pl/nowysacz/Wiadomosc.mvc/GetInboxMessages?_dc='+str(now)+'&dataOd=&dataDo=&page=1&start=0&limit=25', headers=headers)
messages = s.get(f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}/Wiadomosc.mvc/GetInboxMessages?_dc={now}&dataOd=&dataDo=&page=1&start=0&limit=25', headers=headers)
for j in messages.json()['data']:
received_messages.append({
'Subject': j['Temat'],
@ -23,7 +23,7 @@ def get_messages(register_id, register_r, oun, s, date, school_year, symbol):
'Id': j['Id']
})
messages = s.get('https://uonetplus-uzytkownik.vulcan.net.pl/nowysacz/Wiadomosc.mvc/GetOutboxMessages?_dc='+str(now)+'&dataOd=&dataDo=&page=1&start=0&limit=25')
messages = s.get(f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}/Wiadomosc.mvc/GetOutboxMessages?_dc={now}&dataOd=&dataDo=&page=1&start=0&limit=25')
for j in messages.json()['data']:
sent_messages.append({
'Subject': j['Temat'],
@ -35,7 +35,7 @@ def get_messages(register_id, register_r, oun, s, date, school_year, symbol):
})
messages = s.get('https://uonetplus-uzytkownik.vulcan.net.pl/nowysacz/Wiadomosc.mvc/GetTrashboxMessages?_dc='+str(now)+'&dataOd=&dataDo=&page=1&start=0&limit=25')
messages = s.get(f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}/Wiadomosc.mvc/GetTrashboxMessages?_dc={now}&dataOd=&dataDo=&page=1&start=0&limit=25')
for j in messages.json()['data']:
deleted_messages.append({
'Subject': j['Temat'],
@ -45,14 +45,9 @@ def get_messages(register_id, register_r, oun, s, date, school_year, symbol):
'Id': j['Id']
})
print(received_messages)
print('-------------------------------------------------------------------------')
print(sent_messages)
print('-------------------------------------------------------------------------')
print(deleted_messages)
print('-------------------------------------------------------------------------')
return 'Bla'
return received_messages, sent_messages, deleted_messages
def get_recipients(j):
Recipients = []

View file

@ -1,4 +1,5 @@
from requests import get
from django.http import HttpResponse
from django.shortcuts import render
from .login import sender, get_cookies
from .forms import loginForm
@ -143,7 +144,23 @@ def messages_view(request, *args, **kwargs):
if request.session.has_key('is_logged'):
cookies = get_cookies()
messages = get_messages(cookies[0], cookies[1], cookies[2], cookies[3], cookies[4], cookies[5], cookies[6])
content = {'json_data': messages}
content = {'messages': messages[0]}
return render(request, 'wiadomosci.html', content)
else:
return redirect(default_view)
def change_messages_content(request, *args, **kwargs):
if request.session.has_key('is_logged'):
cookies = get_cookies()
messages = get_messages(cookies[0], cookies[1], cookies[2], cookies[3], cookies[4], cookies[5], cookies[6])
id = request.GET.get('id')
if id == 'received':
content = {'messages': messages[0]}
elif id == 'sent':
content = {'messages': messages[1]}
elif id == 'deleted':
content = {'messages': messages[2]}
return render(request, 'messages_content.html', content)
else:
return redirect(default_view)

View file

@ -173,4 +173,53 @@ li{
.day-name{
background-color: #bcbcbc;
}
.button{
text-align: center;
display: inline-block;
border-radius: 10px;
padding-top: 1%;
padding-bottom: 1%;
width: 33%;
background: -webkit-gradient(linear,left top,left bottom,from(rgb(81, 142, 240)),to(rgb(168, 201, 255)));
cursor: pointer;
font-family: 'Open Sans Condensed', sans-serif;
font-family: 'Quicksand', sans-serif;
}
.message-item {
border-top: 2px solid black;
width: 100%;
margin-bottom: 1vh;
border-radius: 10px;
overflow: auto;
color: black;
-ms-overflow-style: none;
scrollbar-width: none;
font-family: 'Open Sans Condensed', sans-serif;
font-family: 'Quicksand', sans-serif;
}
.message-block-left{
display: inline;
text-align: center;
float: left;
width: 60%;
}
.message-block-right{
margin-top: 1%;
float: right;
margin-right: 10%;
}
#buttons{
position: -webkit-sticky;
position: sticky;
margin-bottom: 1vh;
top: 0;
background-color: #ededed;
padding: 2%;
margin-top: 0;
}

View file

@ -7,4 +7,16 @@ function grade_action(id) {
else if(element.style.display == 'block'){
element.style.display = 'none';
}
}
function change_message_content(id) {
$.ajax({
url: '/change_messages_content/',
data: {
'id': id
},
success: function(data) {
document.querySelector('#messages_content').innerHTML = data;
}
});
}

View file

@ -16,7 +16,7 @@ Including another URLconf
from django.urls import path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from Wulkanowy.views import default_view, error_view, grades_view, timetable_view, exams_view, homework_view, attendance_view, messages_view, notes_view
from Wulkanowy.views import default_view, error_view, grades_view, timetable_view, exams_view, homework_view, attendance_view, messages_view, notes_view, change_messages_content
urlpatterns = [
path('', default_view, name='home'),
@ -28,6 +28,7 @@ urlpatterns = [
path('frekwencja/', attendance_view, name='attendance'),
path('wiadomosci/', messages_view, name='messeges'),
path('uwagi/', notes_view, name='notes'),
path('change_messages_content/', change_messages_content)
]
urlpatterns += staticfiles_urlpatterns()

View file

@ -0,0 +1,11 @@
{% for i in messages %}
{% if 'Sender' in i %}
<div class='message-item'><div class='message-block-left'>Temat: {{ i.Subject|force_escape }}<br />Nadawca: {{ i.Sender|force_escape }}</div><div class='message-block-right'>Data: {{ i.Date|force_escape }}</div></div>
{% else %}
<div class='message-item'><div class='message-block-left'>Temat: {{ i.Subject|force_escape }}<br />Obiorca:
{% for j in i.Recipients %}
{{ j.Name|force_escape }}
{% endfor %}
</div><div class='message-block-right'>Data: {{ i.Date|force_escape }}</div></div>
{% endif %}
{% endfor %}

View file

@ -9,6 +9,7 @@
<link rel="stylesheet" href="{% static 'start.css' %}" type="text/css" />
<link rel="stylesheet" media="min-width: 768px" href="{% static 'start.css' %}" />
<script src="{% static 'start.js' %}"></script>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<link rel="shortcut icon" href="{% static 'img/27146352.png' %}">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Lora:wght@500&display=swap" rel="stylesheet">
@ -29,8 +30,17 @@
<a href="/oceny/"><div id="oceny" class="option">Oceny</div></a>
</h1>
</div>
<div class="content">
{{ json_data }}
<div class="content" style='padding-top: 0;'>
<div id='buttons'>
<div id='received' onclick='change_message_content(this.id)' class='button'>ODEBRANE</div>
<div id='sent' onclick='change_message_content(this.id)' class='button'>WYSŁANE</div>
<div id='deleted' onclick='change_message_content(this.id)' class='button'>USUNIĘTE</div>
</div>
<div id='messages_content'>
{% for i in messages %}
<div class='message-item'><div class='message-block-left'>Temat: {{ i.Subject|force_escape }}<br />Nadawca: {{ i.Sender|force_escape }}</div><div class='message-block-right'>Data: {{ i.Date|force_escape }}</div></div>
{% endfor %}
</div>
</div>
</div>
</body>