def patch(self, request, *args, **kwargs): rv = { "username": request.data['username'], "query": self.get_object().query.hash_code } if QueryFilter.objects.filter( query__hash_code=self.kwargs['hash']).exists(): commit_status = self.get_object().status commit_start = self.get_object().start_time commit_end = self.get_object().end_time if 'username' not in request.data: return Response( { 'message': 'Fill the form completely', 'error': 1 }, status=status.HTTP_400_BAD_REQUEST) data = super(QueryFilterView, self).patch(request, *args, **kwargs).data if data['status'] != commit_status: if commit_start != datetime.strptime(data['start_time'], "%Y-%m-%d").date()\ or commit_end != datetime.strptime(data['end_time'], "%Y-%m-%d").date(): return UserUpdateTimeStamp(rv) else: return UserUpdateStatus(rv) else: # User has changed the timestamp, perform the request again. return UserUpdateTimeStamp(rv) else: kwargs = request.data.copy() kwargs['query'] = get_object_or_404(Query, hash_code=self.kwargs['hash']) QueryFilter.objects.create(**kwargs) return UserUpdateTimeStamp(rv)
def patch(self, request, *args, **kwargs): """ :Summary: PATCH request to Update the query filters. :param request: request Object. :param args: arguments passed to the function. :param kwargs: Key, values passed to the function. :return: response of UserUpdateStatus() (or) UserUpdateTimeStamp() function depending upon the filters user updated. """ rv = { "username": request.data['username'], "query": self.get_object().query.hash_code } if QueryFilter.objects.filter( query__hash_code=self.kwargs['hash']).exists(): commit_status = self.get_object().status commit_start = self.get_object().start_time commit_end = self.get_object().end_time if 'username' not in request.data: return Response( { 'message': 'Fill the form completely', 'error': 1 }, status=status.HTTP_400_BAD_REQUEST) """ <---------------------------------------------------------------------- format the recieved datetime string to a timezone-aware datetime object before saving to db """ if "start_time" in request.data: request.data['start_time'] = utc.localize( datetime.strptime(request.data["start_time"].split(".")[0], "%Y-%m-%dT%H:%M:%S")) if "end_time" in request.data: request.data['end_time'] = utc.localize( datetime.strptime(request.data["end_time"].split(".")[0], "%Y-%m-%dT%H:%M:%S")) """-----------------------------------------------------------------/>""" data = super(QueryFilterView, self).patch(request, *args, **kwargs).data if data['status'] != commit_status: if commit_start != data['start_time']\ or commit_end != data['end_time']: return UserUpdateTimeStamp(rv) else: return UserUpdateStatus(rv) else: # User has changed the timestamp, perform the request again. return UserUpdateTimeStamp(rv) else: kwargs = request.data.copy() kwargs['query'] = get_object_or_404(Query, hash_code=self.kwargs['hash']) QueryFilter.objects.create(**kwargs) return UserUpdateTimeStamp(rv)