Fakultas Ilmu Komputer UI

Commit ed4ac06e authored by Joshua Casey's avatar Joshua Casey
Browse files

[#140655219] #32 Implemented student transcript scrapper

parent 7f88c0c4
import requests
from django.conf import settings
from rest_framework import viewsets, status
from rest_framework.exceptions import ValidationError
from rest_framework.generics import get_object_or_404
......@@ -111,6 +113,20 @@ class CompanyApplicationStatusViewSet(viewsets.GenericViewSet):
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def retrieve(self, request, pk=None):
application = self.get_object()
student = application.student
if student.show_transcript:
s = requests.Session()
credentials = settings.API_CS_CREDENTIALS
s.get('https://api.cs.ui.ac.id/api-auth/login/')
csrf = s.cookies['csrftoken']
s.post('https://api.cs.ui.ac.id/api-auth/login/', data={'username' : credentials["user"], 'password' : credentials["password"], 'csrfmiddlewaretoken' : csrf})
response = s.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/' + str(student.npm) + '/riwayat/')
return Response(response.json(), status=status.HTTP_200_OK)
else:
return Response({'error' : 'student does not allow transcript to be shown'}, status=status.HTTP_200_OK)
class CompanyVacanciesViewSet(viewsets.GenericViewSet):
queryset = Vacancy.objects.all()
......
......@@ -158,3 +158,5 @@ GZIP_CONTENT_TYPES = (
SESSION_COOKIE_HTTPONLY = False
RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')
API_CS_CREDENTIALS = {'user' : 'lalala', 'password' : 'lalala'}
......@@ -22,15 +22,10 @@ from rest_framework import routers
from rest_framework_swagger.views import get_swagger_view
from core import apps
<<<<<<< HEAD
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, \
CompanyRegisterViewSet, StudentProfileViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet, CompanyApplicationViewSet, CompanyVacanciesViewSet
=======
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, CompanyRegisterViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet, \
CompanyApplicationViewSet, CompanyVacanciesViewSet, CompanyApplicationStatusViewSet
>>>>>>> ca12893633723b0b5543f4e23d9be11a968295a9
schema_view = get_swagger_view()
router = routers.DefaultRouter()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment