Esempio n. 1
0
 def update(self, request, pk=None):
     """
     update a
     :param request:
     :param pk:
     :return:
     """
     if not pk:
         raise ParamNotEnoughException('id')
     try:
         instance = VerModules.view(pk=pk)
     except ObjectDoesNotExist:
         raise ObjectNotExistException(pk)
     serializer = VersionModuleSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         instance.name = serializer.validated_data['name']
         instance.verID = serializer.validated_data['verID']
         instance.moduleID = serializer.validated_data['moduleID']
         instance.config = serializer.validated_data.get(
             'config', instance.config)
         try:
             instance.save()
         except IntegrityError:
             raise DBIntegrityException(instance.name)
         return Response(serializer.data)
Esempio n. 2
0
    def create(self, request):
        """
        create new entry

        :param request: rest framework request
        :return: new entry
        """
        serializer = VersionSerializer(data=request.data)
        if serializer.is_valid(raise_exception=True):
            # check if exists
            exists = Versions.objects.filter(
                name=serializer.validated_data['name']).exists()
            # raise exception when name in use
            if exists:
                raise DBIntegrityException(serializer.validated_data['name'])
            instance = Versions.objects.create(**serializer.validated_data)
            instance.save()
            return Response(serializer.data)
Esempio n. 3
0
 def update(self, request, pk=None):
     """
     update a
     :param request:
     :param pk:
     :return:
     """
     if not pk:
         raise ParamNotEnoughException('id')
     try:
         instance = Environments.view(pk=pk)
     except ObjectDoesNotExist:
         raise ObjectNotExistException(pk)
     serializer = EnvironmentSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         instance.name = serializer.validated_data['name']
         instance.description = serializer.validated_data.get(
             'description', instance.description)
         try:
             instance.save()
         except IntegrityError:
             raise DBIntegrityException(instance.name)
         return Response(EnvironmentSerializer(instance).data)