Getting student data - backend & tests
This commit is contained in:
parent
62cc1bcf87
commit
7cded5d5ba
4 changed files with 52 additions and 1 deletions
31
app/API/student_data.py
Normal file
31
app/API/student_data.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import json
|
||||
import requests
|
||||
|
||||
def get_student_data(register_id, register_r, oun, s):
|
||||
cookies = s
|
||||
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyDziennikWychowankowie": f"{register_r['data'][0]['IdWychowankowieDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||
})
|
||||
else:
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||
})
|
||||
|
||||
headers = {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': '*/*',
|
||||
'Connection': 'keep-alive',
|
||||
"User-Agent": "Wulkanowy-web :)"
|
||||
}
|
||||
|
||||
student_data = requests.post(f'{oun}/Uczen.mvc/Get', headers=headers, cookies=cookies)
|
||||
|
||||
return student_data.json()
|
15
app/views.py
15
app/views.py
|
@ -19,6 +19,7 @@ from .API.homeworks import get_homeworks
|
|||
from .API.mobile_access import get_registered_devices, register_device
|
||||
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
|
||||
|
||||
#API
|
||||
|
@ -300,5 +301,19 @@ def message_content(request, *args, **kwargs):
|
|||
message_id = data['message_id']
|
||||
content = get_message_content(register_id, register_r, oun, s, date, school_year, symbol, message_id)
|
||||
return JsonResponse(content, safe=False)
|
||||
else:
|
||||
return redirect('../')
|
||||
|
||||
def student_data(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']
|
||||
key = bytes(request.session[request.session.session_key], 'utf-8')
|
||||
s = decrypt_cookies(s, key)
|
||||
data = get_student_data(register_id, register_r, oun, s)
|
||||
return JsonResponse(data)
|
||||
else:
|
||||
return redirect('../')
|
|
@ -115,6 +115,10 @@ def get_data_test(client, cookies_data, assertEquals):
|
|||
assertEquals(response.status_code, 200)
|
||||
recipients = response.json()['addressee']['data']
|
||||
|
||||
#STUDENT DATA
|
||||
response = client.post(reverse('student_data'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||
assertEquals(response.status_code, 200)
|
||||
|
||||
#SEND MESSAGE
|
||||
for recipient in recipients:
|
||||
send_data = {
|
||||
|
|
|
@ -17,7 +17,7 @@ from django.urls import path
|
|||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
from frontend.views import default_view, content_view, account_manager_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, recipients, send, message_content
|
||||
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, send, message_content, student_data
|
||||
|
||||
urlpatterns = [
|
||||
#views
|
||||
|
@ -34,6 +34,7 @@ urlpatterns = [
|
|||
path('api/notes', notes, name='notes'),
|
||||
path('api/school_data', school_data, name='school_data'),
|
||||
path('api/dashboard', dashboard, name='dashboard'),
|
||||
path('api/student_data', student_data, name='student_data'),
|
||||
#MOBILE ACCESS
|
||||
path('api/mobile/registered', registered_devices, name='registered_devices'),
|
||||
path('api/mobile/register', register_device_, name='register_device'),
|
||||
|
|
Loading…
Reference in a new issue