def post(self, request): data = request.data serializer = EmployeeSimpleSerializer(data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=201) return Response(serializer.errors, status=400)
def ScheduleCheckInOutDetail(request, pk): try: schedule = get_object_or_404(Schedule, id=pk) # jobapplyidinoutarr = dateinout = DateInOut.objects.filter(ScheduleIDDateInOut=schedule) checkinout = CheckInOut.objects.filter( ScheduleIDCheckInOut=schedule).first() if checkinout is None: return Response({"error": "Given question object not found."}, status=404) location = Location.objects.filter( JobApplyIDLocation=checkinout.JobApplyIDInOutArr) except Schedule.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': scheduledateinout = ScheduleViewSerializer(schedule) dateinoutschedule = DateInOutSerialzier(dateinout, many=True) locationserializer = LocationSerializer(location, many=True) s = [scheduledateinout.data] d = dateinoutschedule.data l = locationserializer.data # schedulecheckinout = s.update(d) schedulecheckinout = s + d + l return Response(schedulecheckinout)
def put(self, request, id=None): data = request.data instance = self.get_object(id) serializer = EmployeeSimpleSerializer(instance, data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=200) return Response(serializer.errors, status=400)
def get_object(self, id): try: queryset = self.get_queryset() if queryset is None: return Response({"error": "Not Authentications."}, status=404) return Employee.objects.get(id=id) except Employee.DoesNotExist as e: return Response({"error": "Given question object not found."}, status=404)
def get(self, request): # idCurriculumVitae = CurriculumVitae.objects.filter(isFinishCV=True).last() idCurriculumVitae = CurriculumVitae.objects.get(isFinishCV=False) pk = idCurriculumVitae.id try: curriculumvitae = CurriculumVitae.objects.get(id=pk) except: return Response(status=404) serializers = isFinishCVSerializer(curriculumvitae) return Response(serializers.data)
def send_message_with_response( self, operation, set_slave_okay, all_credentials, exhaust=False): """Send a message to MongoDB and return a Response object. Can raise ConnectionFailure. :Parameters: - `operation`: A _Query or _GetMore object. - `set_slave_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `exhaust` (optional): If True, the socket used stays checked out. It is returned along with its Pool in the Response. """ with self.get_socket(all_credentials, exhaust) as sock_info: message = operation.get_message( set_slave_okay, sock_info.is_mongos) request_id, data, max_doc_size = self._split_message(message) sock_info.send_message(data, max_doc_size) response_data = sock_info.receive_message(1, request_id) if exhaust: return ExhaustResponse( data=response_data, address=self._description.address, socket_info=sock_info, pool=self._pool) else: return Response( data=response_data, address=self._description.address)
def ScheduleCheckInOut(request): permission_classes = (AllowAny, ) schedule = Schedule.objects.all() scheduledateinout = ScheduleViewSerializer(schedule, many=True) checkinout = Location.objects.all() location = LocationViewSerializer(checkinout, many=True) schedulecheckinout = scheduledateinout.data + location.data return Response(schedulecheckinout)
def send_message_with_response(self, operation, set_slave_okay, all_credentials, exhaust=False): """Send a message to MongoDB and return a Response object. Can raise ConnectionFailure. :Parameters: - `operation`: A _Query or _GetMore object. - `set_slave_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `exhaust` (optional): If True, the socket used stays checked out. It is returned along with its Pool in the Response. """ with self.get_socket(all_credentials, exhaust) as sock_info: duration = None publish = monitoring.enabled() if publish: start = datetime.now() message = operation.get_message(set_slave_okay, sock_info.is_mongos) request_id, data, max_doc_size = self._split_message(message) if publish: encoding_duration = datetime.now() - start cmd, dbn = operation.as_command() monitoring.publish_command_start(cmd, dbn, request_id, sock_info.address) start = datetime.now() sock_info.send_message(data, max_doc_size) response_data = sock_info.receive_message(1, request_id) if publish: duration = (datetime.now() - start) + encoding_duration if exhaust: return ExhaustResponse(data=response_data, address=self._description.address, socket_info=sock_info, pool=self._pool, duration=duration, request_id=request_id) else: return Response(data=response_data, address=self._description.address, duration=duration, request_id=request_id)
def put(self, request, pk, format=None): id_CVEdu_list = [] education = self.get_object(pk) for cvedu in education.CurriculumVitaeIDEducation.all(): id_CVEdu_list.append(cvedu.id) for cvedu in request.data["CurriculumVitaeIDEducation"]: if cvedu not in id_CVEdu_list: id_CVEdu_list.append(cvedu) else: id_CVEdu_list.pop(id_CVEdu_list.index(cvedu)) request.data["CurriculumVitaeIDEducation"] = id_CVEdu_list serializer = EducationIDCurriculumVitaeSerializer(education, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def send_message_with_response(self, operation, set_slave_okay, all_credentials, listeners, exhaust=False): """Send a message to MongoDB and return a Response object. Can raise ConnectionFailure. :Parameters: - `operation`: A _Query or _GetMore object. - `set_slave_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `listeners`: Instance of _EventListeners or None. - `exhaust` (optional): If True, the socket used stays checked out. It is returned along with its Pool in the Response. """ with self.get_socket(all_credentials, exhaust) as sock_info: duration = None publish = listeners.enabled_for_commands if publish: start = datetime.now() use_find_cmd = operation.use_command(sock_info, exhaust) message = operation.get_message(set_slave_okay, sock_info, use_find_cmd) request_id, data, max_doc_size = self._split_message(message) if publish: encoding_duration = datetime.now() - start cmd, dbn = operation.as_command(sock_info) listeners.publish_command_start(cmd, dbn, request_id, sock_info.address) start = datetime.now() try: sock_info.send_message(data, max_doc_size) reply = sock_info.receive_message(request_id) except Exception as exc: if publish: duration = (datetime.now() - start) + encoding_duration failure = _convert_exception(exc) listeners.publish_command_failure(duration, failure, next(iter(cmd)), request_id, sock_info.address) raise if publish: duration = (datetime.now() - start) + encoding_duration if exhaust: return ExhaustResponse(data=reply, address=self._description.address, socket_info=sock_info, pool=self._pool, duration=duration, request_id=request_id, from_command=use_find_cmd) else: return Response(data=reply, address=self._description.address, duration=duration, request_id=request_id, from_command=use_find_cmd)
def run_operation(self, sock_info, operation, set_secondary_okay, listeners, unpack_res): """Run a _Query or _GetMore operation and return a Response object. This method is used only to run _Query/_GetMore operations from cursors. Can raise ConnectionFailure, OperationFailure, etc. :Parameters: - `operation`: A _Query or _GetMore object. - `set_secondary_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `listeners`: Instance of _EventListeners or None. - `unpack_res`: A callable that decodes the wire protocol response. """ duration = None publish = listeners.enabled_for_commands if publish: start = datetime.now() use_cmd = operation.use_command(sock_info) more_to_come = (operation.sock_mgr and operation.sock_mgr.more_to_come) if more_to_come: request_id = 0 else: message = operation.get_message(set_secondary_okay, sock_info, use_cmd) request_id, data, max_doc_size = self._split_message(message) if publish: cmd, dbn = operation.as_command(sock_info) listeners.publish_command_start(cmd, dbn, request_id, sock_info.address, service_id=sock_info.service_id) start = datetime.now() try: if more_to_come: reply = sock_info.receive_message(None) else: sock_info.send_message(data, max_doc_size) reply = sock_info.receive_message(request_id) # Unpack and check for command errors. if use_cmd: user_fields = _CURSOR_DOC_FIELDS legacy_response = False else: user_fields = None legacy_response = True docs = unpack_res(reply, operation.cursor_id, operation.codec_options, legacy_response=legacy_response, user_fields=user_fields) if use_cmd: first = docs[0] operation.client._process_response(first, operation.session) _check_command_response(first, sock_info.max_wire_version) except Exception as exc: if publish: duration = datetime.now() - start if isinstance(exc, (NotPrimaryError, OperationFailure)): failure = exc.details else: failure = _convert_exception(exc) listeners.publish_command_failure( duration, failure, operation.name, request_id, sock_info.address, service_id=sock_info.service_id) raise if publish: duration = datetime.now() - start # Must publish in find / getMore / explain command response # format. if use_cmd: res = docs[0] elif operation.name == "explain": res = docs[0] if docs else {} else: res = { "cursor": { "id": reply.cursor_id, "ns": operation.namespace() }, "ok": 1 } if operation.name == "find": res["cursor"]["firstBatch"] = docs else: res["cursor"]["nextBatch"] = docs listeners.publish_command_success(duration, res, operation.name, request_id, sock_info.address, service_id=sock_info.service_id) # Decrypt response. client = operation.client if client and client._encrypter: if use_cmd: decrypted = client._encrypter.decrypt( reply.raw_command_response()) docs = _decode_all_selective(decrypted, operation.codec_options, user_fields) if client._should_pin_cursor(operation.session) or operation.exhaust: sock_info.pin_cursor() if isinstance(reply, _OpMsg): # In OP_MSG, the server keeps sending only if the # more_to_come flag is set. more_to_come = reply.more_to_come else: # In OP_REPLY, the server keeps sending until cursor_id is 0. more_to_come = bool(operation.exhaust and reply.cursor_id) if operation.sock_mgr: operation.sock_mgr.update_exhaust(more_to_come) response = PinnedResponse(data=reply, address=self._description.address, socket_info=sock_info, duration=duration, request_id=request_id, from_command=use_cmd, docs=docs, more_to_come=more_to_come) else: response = Response(data=reply, address=self._description.address, duration=duration, request_id=request_id, from_command=use_cmd, docs=docs) return response
def run_operation_with_response(self, sock_info, operation, set_slave_okay, listeners, exhaust, unpack_res): """Run a _Query or _GetMore operation and return a Response object. This method is used only to run _Query/_GetMore operations from cursors. Can raise ConnectionFailure, OperationFailure, etc. :Parameters: - `operation`: A _Query or _GetMore object. - `set_slave_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `listeners`: Instance of _EventListeners or None. - `exhaust`: If True, then this is an exhaust cursor operation. - `unpack_res`: A callable that decodes the wire protocol response. """ duration = None publish = listeners.enabled_for_commands if publish: start = datetime.now() send_message = not operation.exhaust_mgr if send_message: use_cmd = operation.use_command(sock_info, exhaust) message = operation.get_message(set_slave_okay, sock_info, use_cmd) request_id, data, max_doc_size = self._split_message(message) else: use_cmd = False request_id = 0 if publish: cmd, dbn = operation.as_command(sock_info) listeners.publish_command_start(cmd, dbn, request_id, sock_info.address) start = datetime.now() try: if send_message: sock_info.send_message(data, max_doc_size) reply = sock_info.receive_message(request_id) else: reply = sock_info.receive_message(None) # Unpack and check for command errors. if use_cmd: user_fields = _CURSOR_DOC_FIELDS legacy_response = False else: user_fields = None legacy_response = True docs = unpack_res(reply, operation.cursor_id, operation.codec_options, legacy_response=legacy_response, user_fields=user_fields) if use_cmd: first = docs[0] operation.client._process_response(first, operation.session) _check_command_response(first) except Exception as exc: if publish: duration = datetime.now() - start if isinstance(exc, (NotMasterError, OperationFailure)): failure = exc.details else: failure = _convert_exception(exc) listeners.publish_command_failure(duration, failure, operation.name, request_id, sock_info.address) raise if publish: duration = datetime.now() - start # Must publish in find / getMore / explain command response # format. if use_cmd: res = docs[0] elif operation.name == "explain": res = docs[0] if docs else {} else: res = { "cursor": { "id": reply.cursor_id, "ns": operation.namespace() }, "ok": 1 } if operation.name == "find": res["cursor"]["firstBatch"] = docs else: res["cursor"]["nextBatch"] = docs listeners.publish_command_success(duration, res, operation.name, request_id, sock_info.address) # Decrypt response. client = operation.client if client and client._encrypter: if use_cmd: decrypted = client._encrypter.decrypt( reply.raw_command_response()) docs = _decode_all_selective(decrypted, operation.codec_options, user_fields) if exhaust: response = ExhaustResponse(data=reply, address=self._description.address, socket_info=sock_info, pool=self._pool, duration=duration, request_id=request_id, from_command=use_cmd, docs=docs) else: response = Response(data=reply, address=self._description.address, duration=duration, request_id=request_id, from_command=use_cmd, docs=docs) return response
def send_message_with_response(self, operation, set_slave_okay, all_credentials, listeners, exhaust=False): """Send a message to MongoDB and return a Response object. Can raise ConnectionFailure. :Parameters: - `operation`: A _Query or _GetMore object. - `set_slave_okay`: Pass to operation.get_message. - `all_credentials`: dict, maps auth source to MongoCredential. - `exhaust` (optional): If True, the socket used stays checked out. It is returned along with its Pool in the Response. """ with self.get_socket(all_credentials, exhaust) as sock_info: duration = None publish = listeners.enabled_for_commands if publish: start = datetime.now() use_find_cmd = False if sock_info.max_wire_version >= 4: if not exhaust: use_find_cmd = True elif (isinstance(operation, _Query) and not operation.read_concern.ok_for_legacy): raise ConfigurationError( 'read concern level of %s is not valid ' 'with a max wire version of %d.' % (operation.read_concern.level, sock_info.max_wire_version)) message = operation.get_message(set_slave_okay, sock_info.is_mongos, use_find_cmd) request_id, data, max_doc_size = self._split_message(message) if publish: encoding_duration = datetime.now() - start cmd, dbn = operation.as_command() listeners.publish_command_start(cmd, dbn, request_id, sock_info.address) start = datetime.now() try: sock_info.send_message(data, max_doc_size) response_data = sock_info.receive_message(1, request_id) except Exception as exc: if publish: duration = (datetime.now() - start) + encoding_duration failure = _convert_exception(exc) listeners.publish_command_failure(duration, failure, next(iter(cmd)), request_id, sock_info.address) raise if publish: duration = (datetime.now() - start) + encoding_duration if exhaust: return ExhaustResponse(data=response_data, address=self._description.address, socket_info=sock_info, pool=self._pool, duration=duration, request_id=request_id, from_command=use_find_cmd) else: return Response(data=response_data, address=self._description.address, duration=duration, request_id=request_id, from_command=use_find_cmd)
def get(self, request): queryset = self.get_queryset() serializer = EmployeeSimpleSerializer(queryset, many=True) return Response(serializer.data)
def get(self, request, id=None): instance = self.get_object(id) serailizer = EmployeeCurriculumVitaeDetailSerializer(instance) return Response(serailizer.data)
def delete(self, request, pk, format=None): education = self.get_object(pk) education.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def get(self, request, pk, format=None): education = self.get_object(pk) serializer = EducationIDCurriculumVitaeSerializer(education) return Response(serializer.data)
def get(self, request): queryset = self.get_queryset() # qr = profile.objects.all() serializer = EmployeeExperiencesDetailSerializer(queryset, many=True) return Response(serializer.data)
def get_object(self): try: return CurriculumVitae.objects.get(isFinishCV=False) except CurriculumVitae.DoesNotExist as e: return Response({"error": "Given question object not found."}, status=404)
def get(self, request, id=None): instance = self.get_object(id) serailizer = EmployeeExperiencesDetailSerializer(instance) return Response(serailizer.data)