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