Timetable

This commit is contained in:
Tomasz 2021-02-01 23:41:18 +01:00
parent 6f0e94c331
commit e9292e3f6a
3 changed files with 37 additions and 7 deletions

View file

@ -21,6 +21,7 @@ from .API.school_data import get_school_data
from .API.dashboard import get_dashboard
from .API.student_data import get_student_data
from .decrypt import decrypt_cookies
import datetime
#API
def login(request, *args, **kwargs):
@ -68,13 +69,30 @@ def grades(request, *args, **kwargs):
def timetable(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
week = data['week']
data = json.loads(data['cookies'])
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = data['data']['date']
now = datetime.datetime.now()
weekday = now.weekday()
for x in range(7):
if weekday == x:
now = now - datetime.timedelta(days=x)
now = now + datetime.timedelta(days=week*7)
day = now.day
month = now.month
year = now.year
date = datetime.date(year, month, day).isoformat()
date = f'{date}T00:00:00'
timetable = get_timetable(register_id, students, oun, s, date)
return JsonResponse(timetable)
else:

View file

@ -1,11 +1,23 @@
const timetable_ = document.querySelector('#timetable_');
myStorage = window.sessionStorage;
week = 0
const getTimetable = () => {
document.querySelector('#content').innerHTML = 'Here is timetable (in my imagination)';
document.querySelector('#content').innerHTML += '<button><i class="material-icons">keyboard_arrow_left</i></button>';
document.querySelector('#content').innerHTML += '<button><i class="material-icons">keyboard_arrow_right</i></button>';
const getTimetable = (event) => {
if (event.target.id == 'previous') {
week -= 1
}
else if (event.target.id == 'next') {
week += 1
}
else {
week = week
}
document.querySelector('#content').innerHTML = 'Here is timetable (in my imagination)<button id="previous" class="waves-light waves-effect btn red darken-1"><i class="material-icons">keyboard_arrow_left</i></button><button id="next" class="waves-light waves-effect btn red darken-1"><i class="material-icons">keyboard_arrow_right</i></button>';
const left_ = document.querySelector('#previous');
const right_ = document.querySelector('#next');
left_.addEventListener('click', getTimetable);
right_.addEventListener('click', getTimetable);
cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/timetable', {
@ -15,7 +27,7 @@ const getTimetable = () => {
'Content-Type': 'application/json',
'X-CSRFToken': csrfcookie_
},
body: cookies_data
body: JSON.stringify({"cookies": cookies_data, "week": week})
}).then(response => response.json()).then(data => {
console.log(data)
})

View file

@ -57,7 +57,7 @@ def get_data_test(client, cookies_data, assertEquals):
assertEquals(response.status_code, 200)
#TIMETABLE
response = client.post(reverse('timetable'), content_type='application/xml', data=json.dumps(cookies_data))
response = client.post(reverse('timetable'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
assertEquals(response.status_code, 200)
#EXAMS