Getting recipients

This commit is contained in:
Pengwius 2021-01-15 23:17:03 +01:00
parent bdeedecd4c
commit fa08d6d8eb
5 changed files with 60 additions and 4 deletions

View file

@ -53,3 +53,25 @@ def get_deleted_messages(register_id, register_r, oun, s, date, school_year, sym
deleted_messages = requests.get(f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}/Wiadomosc.mvc/GetOutboxMessages?_dc={now}&dataOd=&dataDo=&page=1&start=0&limit=25', headers=headers, cookies=s)
return deleted_messages.json()
def get_recipients(register_id, register_r, oun, s, date, school_year, symbol):
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept': '*/*',
'Connection': 'keep-alive',
"User-Agent": "Wulkanowy-web :)"
}
if oun == 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
link = f'http://uonetplus-uzytkownik.fakelog.cf/{symbol}'
else:
link = f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}'
get_jednostki = requests.get(f'{link}/NowaWiadomosc.mvc/GetJednostkiUzytkownika', headers=headers, cookies=s)
id_jednostka = get_jednostki.json()['data'][0]['IdJednostkaSprawozdawcza']
data = {
"paramsVo":{"IdJednostkaSprawozdawcza":id_jednostka, 'Rola': 2}
}
get_addressee = requests.post(f'{link}/Adresaci.mvc/GetAddressee', headers=headers, cookies=s, json=data)
return get_addressee.json()

View file

@ -12,7 +12,7 @@ from .API.exams import get_exams
from .API.timetable import get_timetable
from .API.notes import get_notes
from .API.attendance import get_attendance
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients
from .API.homeworks import get_homeworks
from .API.mobile_access import get_registered_devices, register_device
from .API.school_data import get_school_data
@ -197,6 +197,21 @@ def deleted_messages(request, *args, **kwargs):
else:
return redirect('../')
def recipients(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
register_r = data['data']['register_r']
oun = data['data']['oun']
s = data['data']['s']
date = data['data']['date']
school_year = data['data']['school_year']
symbol = data['data']['symbol']
recipients = get_recipients(register_id, register_r, oun, s, date, school_year, symbol)
return JsonResponse(recipients)
else:
return redirect('../')
def school_data(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)

View file

@ -1,7 +1,8 @@
const received_ = document.querySelector('#received_');
const sent_ = document.querySelector('#sent_');
const deleted_ = document.querySelector('#deleted_');
const content = document.getElementById("content")
const content = document.getElementById("content");
const send_ = document.querySelector('#send_')
const getReceivedMessages = () => {
content.innerHTML = ""
@ -156,7 +157,24 @@ const getDeletedMessages = () => {
})
}
const sendMessage = () => {
cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/messages/recipients', {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfcookie_
},
body: cookies_data
}).then(response => response.json()).then(data => {
console.log(data);
})
}
received_.addEventListener('click', getReceivedMessages);
sent_.addEventListener('click', getSentMessages);
deleted_.addEventListener('click', getDeletedMessages);
send_.addEventListener('click', sendMessage);

View file

@ -59,7 +59,7 @@
<ul id='dropdown1' class='dropdown-content'>
<li><a id='received_' class='option'>Odebrane</a></li>
<li><a id='sent_' class='option'>Wysłane</a></li>
<li><a href="#!" class='option'>Napisz Wiadomość</a></li>
<li><a id='send_' class='option'>Napisz Wiadomość</a></li>
<li><a id='deleted_' class='option'>Usunięte</a></li>
</ul>
</ul>

View file

@ -17,7 +17,7 @@ from django.urls import path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from app.views import default_view, content_view
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients
urlpatterns = [
#views
@ -40,6 +40,7 @@ urlpatterns = [
path('api/messages/received', received_messages, name='received_messages'),
path('api/messages/sent', sent_messages, name='sent_messages'),
path('api/messages/deleted', deleted_messages, name='deleted_messages'),
path('api/messages/recipients', recipients, name='recipients'),
]
urlpatterns += staticfiles_urlpatterns()