def perform_create(self, serializer): user = UserUtils.get_user_from_request(self.request) instance = serializer.save(owner=user, created_by=user, modified_by=user) message = '%s added %s' % (user.username, str(instance)) self.log_addition(user, instance, message)
def current_user(request): """ API endpoint that fetch current login user. """ user = UserUtils.get_user_from_request(request) return Response( serializers.serialize('json', User.objects.filter(id=user.id)))
def perform_destroy(self, instance): instance.deleted = True user = UserUtils.get_user_from_request(self.request) instance.modified_by = user instance.modified_at = timezone.now() instance.save(force_update_deleted=True) message = '%s soft deleted %s' % (user.username, str(instance)) self.log_deletion(user, instance, message)
def perform_update(self, serializer): instance = serializer.save() user = UserUtils.get_user_from_request(self.request) instance.modified_by = user instance.modified_at = timezone.now() instance.save() message = '%s changed %s' % (user.username, str(instance)) self.log_change(user, instance, message)
def current(self, request): user = UserUtils.get_user_from_request(request) serializer = self.get_serializer(user, many=False) return Response(serializer.data)
def current(self, request): user = UserUtils.get_user_from_request(request) self.queryset = User.objects.filter(id=user.id)