def post(self, request): if hasattr(request.user, 'profile'): form = ProfileForm(data=request.data, files=request.FILES, instance=request.user.profile, cv_required=False) else: form = ProfileForm(data=request.data, files=request.FILES, cv_required=False) if form.is_valid(): profile = form.save(request.user) # if not object student, create student if not profile.user.get_student(): training = Training.get_or_create_initial() form_student = StudentForm(data={ 'user': profile.user.id, 'training': training.id }) if form_student.is_valid(): form_student.save() return Response(user_profile(request.user)) return ErrorResponse(form)
def post(self, request): form = APIRegisterForm(request.data) if form.is_valid(): user = form.save() return Response({'message': f'Mohon cek kotak masuk / spam {user.email} untuk mengaktifkan akun Anda'}) return ErrorResponse(form)
def post(self, request): survey = getattr(request.user, 'survey', None) form = SurveyForm(data=request.data, instance=survey) if form.is_valid(): form.save(request.user) return Response(self.build_response(request.user)) return ErrorResponse(form)
def post(self, request): form = PasswordChangeForm(user=request.user, data=request.data or None) if form.is_valid(): form.save() return Response({'message': 'Password berhasil diubah'}) return ErrorResponse(form)
def get(self, request, user_id): certificates = Certificate.objects.filter(user=user_id) if certificates: for cert in certificates: cert.generate() return Response({'message': 'Berhasil generate ulang sertifikat'}) return ErrorResponse(error_message='Gagal generate ulang sertifikat')
def post(self, request): serializer = AddInboxSerializer(data=request.data) if serializer.is_valid(): inbox = serializer.save() inbox.send_notification() return Response({'message': 'Pesan berhasil disimpan'}) return ErrorResponse(serializer=serializer)
def post(self, request): form = CertificateVerifyForm(request.data or None) if form.is_valid(): student = form.verification() if student: context = { 'full_name': student['user']['full_name'], 'certificate_number': student['certificate_number'], 'issued_at': student['created'].strftime('%d %b %Y'), 'valid_until': student['valid_until'].strftime('%d %b %Y') } return Response(context) return ErrorResponse(error_message='Maaf, kami tidak dapat menemukan sertifikat dengan ' 'nomor sertifikat dan nama belakang tersebut.') return ErrorResponse(form)
def post(self, request): if hasattr(request.user, 'profile'): form = UploadAvatarForm(files=request.FILES, instance=request.user.profile) else: form = UploadAvatarForm(files=request.FILES) if form.is_valid(): form.save() return Response(user_profile(request.user)) return ErrorResponse(form)
def post(self, request): form = CustomAuthenticationForm(request, data=request.data) if form.is_valid(): user = form.get_user() refresh = RefreshToken.for_user(user) data = { 'refresh': str(refresh), 'access': str(refresh.access_token), 'user': user_profile(user) } return Response(data) return ErrorResponse(form)
def post(self, request): bulk_delete = BulkDeleteSerializer(data=request.data) if bulk_delete.is_valid(): bulk_ids = bulk_delete.data["inbox_ids"] if len(bulk_ids) == 1 and bulk_ids[0] == -1: inboxs = Inbox.objects.filter(user=request.user) inboxs.delete() return Response({'message': 'Berhasil hapus pesan yang dipilih'}) else: inboxs = Inbox.objects.filter(id__in=bulk_ids, user=request.user) inboxs.delete() return Response({'message': 'Berhasil hapus pesan yang dipilih'}) else: return ErrorResponse(error_message='Pesan tidak ditemukan')
def post(self, request): bulk_read = BulkReadUnreadSerializer(data=request.data) if bulk_read.is_valid(): bulk_filter = bulk_read.data['filter'] read_state = bulk_read.data['read_state'] if len(bulk_filter) == 1 and bulk_filter[0] == -1: # all filter inboxs = Inbox.objects.filter(user=request.user) inboxs.update(is_read=read_state) return Response(InboxSerializer(inboxs, many=True).data) else: # partial filter inboxs = Inbox.objects.filter(user=request.user, id__in=bulk_filter) inboxs.update(is_read=read_state) return Response(InboxSerializer(inboxs, many=True).data) else: return ErrorResponse(serializer=bulk_read)
def post(self, request, *args, **kwargs): form = GenerateCertificateForm(data=request.data) if form.is_valid(): certificate = form.save() return Response(CertificateSerializer(certificate).data) return ErrorResponse(form)