def get_or_create_fileuuidmap(self, repo_id, parent_path, filename, is_dir): """ create filemap by repo_id、 parent_path、filename、id_dir args: - `repo_id`: - `parent_path`: - `filename`: input a dirname if it's dir - `id_dir`: input True or False return: uuid of filemap """ uuid = self.get_fileuuidmap_by_path(repo_id, parent_path, filename, is_dir) if not uuid: uuid = self.model(repo_id=repo_id, parent_path=parent_path, filename=filename, is_dir=is_dir) uuid.save(using=self._db) return uuid
def get_or_create_fileuuidmap(self, repo_id, parent_path, filename, is_dir): """ create filemap by repo_id、 parent_path、filename、id_dir args: - `repo_id`: - `parent_path`: - `filename`: input a dirname if it's dir - `id_dir`: input True or False return: uuid of filemap """ uuid = self.get_fileuuidmap_by_path(repo_id, parent_path, filename, is_dir) if not uuid: uuid = self.model(repo_id=repo_id, parent_path=parent_path, filename=filename, is_dir=is_dir) uuid.save(using=self._db) return uuid
def create(self, request, *args, **kwargs): if "uuid" not in request.data or request.data["uuid"] == "": return Response(status=status.HTTP_400_BAD_REQUEST) uuid = Uuid.objects.filter(value=request.data["uuid"]).first() if uuid is None: uuid = Uuid.objects.create(value=request.data["uuid"]) if request.user.is_authenticated: uuid.user = request.user uuid.save() serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save(uuid=uuid) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def _generate_uuid(self): uuid = UUID() uuid.save() self.uuid = uuid
def _generate_uuid(self): uuid = UUID() uuid.save() self.uuid = uuid