Fakultas Ilmu Komputer UI

Commit 77ed36db authored by Zamil Majdy's avatar Zamil Majdy
Browse files

Add trancript page for student

parent be2a212f
...@@ -48,6 +48,7 @@ export default class ProfilePage extends React.Component { ...@@ -48,6 +48,7 @@ export default class ProfilePage extends React.Component {
this.handleFile = this.handleFile.bind(this); this.handleFile = this.handleFile.bind(this);
this.gotoLink = this.gotoLink.bind(this); this.gotoLink = this.gotoLink.bind(this);
this.gotoStudentResume = this.gotoStudentResume.bind(this); this.gotoStudentResume = this.gotoStudentResume.bind(this);
this.gotoStudentTranscript = this.gotoStudentTranscript.bind(this);
this.getProfile(); this.getProfile();
} }
...@@ -127,6 +128,8 @@ export default class ProfilePage extends React.Component { ...@@ -127,6 +128,8 @@ export default class ProfilePage extends React.Component {
gotoStudentResume = () => this.gotoLink(this.state.resume || '#'); gotoStudentResume = () => this.gotoLink(this.state.resume || '#');
gotoStudentTranscript = () => this.gotoLink(`transkrip/${this.state.id}`);
updateForm(show) { updateForm(show) {
if (show) { if (show) {
return ( return (
...@@ -241,6 +244,7 @@ export default class ProfilePage extends React.Component { ...@@ -241,6 +244,7 @@ export default class ProfilePage extends React.Component {
<Container textAlign="center"> <Container textAlign="center">
<div className="buttonProfile"> <div className="buttonProfile">
<Button onClick={this.gotoStudentResume} disabled={!this.state.resume} primary size="small">Resume</Button> <Button onClick={this.gotoStudentResume} disabled={!this.state.resume} primary size="small">Resume</Button>
<Button onClick={this.gotoStudentTranscript} color="green" size="small">Transkrip</Button>
</div> </div>
<br /> <br />
<div> <div>
......
...@@ -5,19 +5,20 @@ import Server from './lib/Server'; ...@@ -5,19 +5,20 @@ import Server from './lib/Server';
export default class TranscriptPage extends React.Component { export default class TranscriptPage extends React.Component {
static propTypes = { static propTypes = {
params: React.PropTypes.object.isRequired, params: React.PropTypes.object.isRequired,
user: React.PropTypes.object.isRequired,
}; };
constructor(props) { constructor(props) {
super(props); super(props);
/* istanbul ignore next */ /* istanbul ignore next */
console.log(this.props.params); this.state = { text: 'Mohon Tunggu..' };
this.state = {}; const url = this.props.user.role === 'student' ? `/students/${this.props.params.id}/transcript/` : `/applications/${this.props.params.id}/transcript/`;
Server.get(`/applications/${this.props.params.id}/transcript/`).then(response => this.setState({ data: response })); Server.get(url).then(response => this.setState({ data: response }), () => this.setState({ text: 'Anda tidak berhak untuk melihat transkrip ini' }));
} }
render() { render() {
return ( return (
this.state.data ? <CourseList data={this.state.data} /> : <h5 style={{ textAlign: 'center' }}> Mohon Tunggu.. </h5> this.state.data ? <CourseList data={this.state.data} /> : <h5 style={{ textAlign: 'center' }}> {this.state.text} </h5>
); );
} }
} }
...@@ -81,7 +81,7 @@ export default class ApproveModal extends React.Component { ...@@ -81,7 +81,7 @@ export default class ApproveModal extends React.Component {
gotoStudentResume = () => this.gotoLink(this.props.data.student.resume); gotoStudentResume = () => this.gotoLink(this.props.data.student.resume);
gotoStudentTranscript = () => this.gotoLink(`/transcript/${this.props.data.id}`); gotoStudentTranscript = () => this.gotoLink(`/transkrip/${this.props.data.id}`);
gotoStudentProfile = () => this.gotoLink(`/mahasiswa/${this.props.data.student.id}`); gotoStudentProfile = () => this.gotoLink(`/mahasiswa/${this.props.data.student.id}`);
......
...@@ -19,7 +19,7 @@ export default class CourseList extends React.Component { ...@@ -19,7 +19,7 @@ export default class CourseList extends React.Component {
return this.state.course.map((course, index) => course.kelas ? (<Course return this.state.course.map((course, index) => course.kelas ? (<Course
key={index} key={index}
grade={course.nilai} grade={course.nilai}
courseName={course.kelas.nm_kls} courseName={course.kelas.nm_mk_cl.nm_mk}
/>) : null); />) : null);
} }
......
...@@ -103,7 +103,7 @@ export default class App extends React.Component { ...@@ -103,7 +103,7 @@ export default class App extends React.Component {
<Router history={browserHistory}> <Router history={browserHistory}>
<Route path="/login" component={Login} /> <Route path="/login" component={Login} />
<Route component={all(Dashboard)} onEnter={this.handleAuth}> <Route component={all(Dashboard)} onEnter={this.handleAuth}>
<Route path="/transcript/:id" component={company(TranscriptPage)} /> <Route path="/transkrip/:id" component={commonUser(TranscriptPage)} />
<Route path="/lowongan" component={all(VacancyPage)} /> <Route path="/lowongan" component={all(VacancyPage)} />
<Route path="/admin-lowongan" component={AdminVacancyPage} /> <Route path="/admin-lowongan" component={AdminVacancyPage} />
<Route path="/buat-lowongan" component={company(CreateVacancy)} /> <Route path="/buat-lowongan" component={company(CreateVacancy)} />
...@@ -115,7 +115,6 @@ export default class App extends React.Component { ...@@ -115,7 +115,6 @@ export default class App extends React.Component {
<Route path="/perusahaan/:id" component={facultyMember(CompanyProfile)} /> <Route path="/perusahaan/:id" component={facultyMember(CompanyProfile)} />
<Route path="/perusahaan" component={staff(CompanyPage)} /> <Route path="/perusahaan" component={staff(CompanyPage)} />
<Route path="/rekap" component={supervisor(SupervisorPage)} /> <Route path="/rekap" component={supervisor(SupervisorPage)} />
<Route path="/transkrip/:id" component={facultyMember(CompanyProfile)} />
</Route> </Route>
<Route path="/home" onEnter={this.handleHome} /> <Route path="/home" onEnter={this.handleHome} />
<Route path="/admin-vacancy" component={VacancyPage} /> <Route path="/admin-vacancy" component={VacancyPage} />
......
...@@ -8,8 +8,6 @@ def validate_file(value, valid_extensions): ...@@ -8,8 +8,6 @@ def validate_file(value, valid_extensions):
if not ext.lower() in valid_extensions: if not ext.lower() in valid_extensions:
raise ValidationError(u'Unsupported file extension.') raise ValidationError(u'Unsupported file extension.')
print value._size
if value._size > MAX_UPLOAD_SIZE: if value._size > MAX_UPLOAD_SIZE:
raise ValidationError(u'File too large.') raise ValidationError(u'File too large.')
......
import requests import requests
from django.contrib.auth import authenticate, login from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from rest_framework import viewsets, status from rest_framework import viewsets, status
from rest_framework.decorators import list_route, detail_route from rest_framework.decorators import list_route, detail_route
from rest_framework.exceptions import PermissionDenied
from rest_framework.parsers import FormParser,MultiPartParser from rest_framework.parsers import FormParser,MultiPartParser
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.permissions import IsAdminUser, IsAuthenticated from rest_framework.permissions import IsAdminUser, IsAuthenticated
...@@ -13,6 +15,7 @@ from core.lib.permissions import IsAdminOrStudent, IsAdminOrSelfOrReadOnly, IsAd ...@@ -13,6 +15,7 @@ from core.lib.permissions import IsAdminOrStudent, IsAdminOrSelfOrReadOnly, IsAd
from core.models.accounts import Student, Company, Supervisor from core.models.accounts import Student, Company, Supervisor
from core.serializers.accounts import BasicUserSerializer, UserSerializer, StudentSerializer, CompanySerializer, \ from core.serializers.accounts import BasicUserSerializer, UserSerializer, StudentSerializer, CompanySerializer, \
SupervisorSerializer, RegisterSerializer, StudentUpdateSerializer, CompanyUpdateSerializer SupervisorSerializer, RegisterSerializer, StudentUpdateSerializer, CompanyUpdateSerializer
from kape import settings
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
...@@ -66,6 +69,31 @@ class StudentViewSet(viewsets.ModelViewSet): ...@@ -66,6 +69,31 @@ class StudentViewSet(viewsets.ModelViewSet):
else: else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@detail_route(methods=['get'], permission_classes=[IsAdminOrStudent])
def transcript(self, request, pk):
"""
Get student {student_id}'s academic transcript
---
"""
student = get_object_or_404(Student.objects.all(), pk=pk)
if hasattr(request.user, 'student') and request.user.student.pk != student.pk:
raise PermissionDenied("You are not allowed to see other student's transcript")
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']
resp = 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({'name': student.full_name, 'transcript': response.json()}, status=status.HTTP_200_OK)
else:
return Response({'name': student.full_name, 'error': 'student does not allow transcript to be shown'},
status=status.HTTP_200_OK)
class CompanyViewSet(viewsets.ModelViewSet): class CompanyViewSet(viewsets.ModelViewSet):
queryset = Company.objects.all() queryset = Company.objects.all()
......
...@@ -15,6 +15,7 @@ from core.models import Student, Company ...@@ -15,6 +15,7 @@ from core.models import Student, Company
from core.models.vacancies import Vacancy, Application from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer, ApplicationStatusSerializer, \ from core.serializers.vacancies import VacancySerializer, ApplicationSerializer, ApplicationStatusSerializer, \
PostVacancySerializer, VacancyVerifiedSerializer, SupervisorStudentApplicationSerializer PostVacancySerializer, VacancyVerifiedSerializer, SupervisorStudentApplicationSerializer
from core.views.accounts import StudentViewSet
class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
...@@ -83,7 +84,6 @@ class ApplicationViewSet(MultiSerializerViewSetMixin, viewsets.GenericViewSet): ...@@ -83,7 +84,6 @@ class ApplicationViewSet(MultiSerializerViewSetMixin, viewsets.GenericViewSet):
def partial_update(self, request, pk=None): def partial_update(self, request, pk=None):
application = self.get_object() application = self.get_object()
print self.action
serializer = self.get_serializer_class()(application, data=request.data, partial=True) serializer = self.get_serializer_class()(application, data=request.data, partial=True)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()
...@@ -94,24 +94,11 @@ class ApplicationViewSet(MultiSerializerViewSetMixin, viewsets.GenericViewSet): ...@@ -94,24 +94,11 @@ class ApplicationViewSet(MultiSerializerViewSetMixin, viewsets.GenericViewSet):
@detail_route(methods=['get'], permission_classes=[IsAdminOrVacancyOwner]) @detail_route(methods=['get'], permission_classes=[IsAdminOrVacancyOwner])
def transcript(self, request, pk): def transcript(self, request, pk):
""" """
Get student {student_id}'s academic transcript Get student's academic transcript on application {application_id}
--- ---
""" """
application = self.get_object() application = self.get_object()
student = application.student return StudentViewSet.transcript(StudentViewSet(), request, application.student.pk)
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']
resp = 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({'name': student.full_name, 'transcript': response.json()}, status=status.HTTP_200_OK)
else:
return Response({'name': student.full_name, 'error': 'student does not allow transcript to be shown'},
status=status.HTTP_200_OK)
def get_permissions(self): def get_permissions(self):
if self.action == "list": if self.action == "list":
......
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