Beispiel #1
0
    def create(self, validated_data):
        """create.

        :param validated_data:
        :return compute_request:
        """
        compute_product = validated_data.pop('compute_product', None)
        if not compute_product or 'id' not in compute_product:
            raise ParseError('Compute product is required')

        compute_product_id = compute_product['id']
        compute_question_responses = validated_data.pop(
            'compute_question_responses', None)

        provision_details = validated_data.pop('provision_details', None)
        if provision_details:
            pSerializer = ProvisionDetailsSerializer(data=provision_details,
                                                     context=self.context)
            pSerializer.is_valid(raise_exception=True)
            validated_data['provision_details'] = pSerializer.save()

        validated_data['compute_product'] = get_compute_product_obj(
            {'pk': compute_product_id})

        compute_request = ComputeRequest.objects.create(**validated_data)
        if compute_question_responses:
            for cqr in compute_question_responses:
                cqrSerializer = ComputeQuestionResponseSerializer(data=cqr)
                cqrSerializer.is_valid(raise_exception=True)
                cqrSerializer.save(compute_request=compute_request)

        return compute_request
Beispiel #2
0
    def create(self, validated_data):
        """create.

        :param validated_data:
        :return storage_request:
        """
        # not used, use initial_data instead
        validated_data.pop('storage_product', None)
        storage_product = self.initial_data.pop('storage_product', None)
        if not storage_product or 'id' not in storage_product:
            raise ParseError('Storage product is required')

        storage_product_id = storage_product['id']
        storage_question_responses = validated_data.pop(
            'storage_question_responses', None)

        provision_details = validated_data.pop('provision_details', None)
        if provision_details:
            pSerializer = ProvisionDetailsSerializer(data=provision_details,
                                                     context=self.context)
            pSerializer.is_valid(raise_exception=True)
            validated_data['provision_details'] = pSerializer.save()

        validated_data['storage_product'] = get_storage_product_obj(
            {'pk': storage_product_id})

        storage_request = StorageRequest.objects.create(**validated_data)

        if storage_question_responses:
            for sqr in storage_question_responses:
                sqrSerializer = StorageQuestionResponseSerializer(data=sqr)
                sqrSerializer.is_valid(raise_exception=True)
                sqrSerializer.save(storage_request=storage_request)

        return storage_request
    def create(self, validated_data):
        """create.

        :param validated_data:
        :return storage_request:
        """
        # not used, use initial_data instead
        validated_data.pop('storage_product', None)
        storage_product = self.initial_data.pop('storage_product', None)
        if not storage_product or 'id' not in storage_product:
            raise ParseError('Storage product is required')

        storage_product_id = storage_product['id']
        storage_question_responses = validated_data.pop(
            'storage_question_responses', None)

        provision_details = validated_data.pop('provision_details', None)
        if provision_details:
            pSerializer = ProvisionDetailsSerializer(
                data=provision_details, context=self.context)
            pSerializer.is_valid(raise_exception=True)
            validated_data['provision_details'] = pSerializer.save()

        validated_data['storage_product'] = \
            lookupData.get_storage_product_obj({'pk': storage_product_id})

        storage_request = StorageRequest.objects.create(**validated_data)

        if storage_question_responses:
            for sqr in storage_question_responses:
                sqrSerializer = StorageQuestionResponseSerializer(data=sqr)
                sqrSerializer.is_valid(raise_exception=True)
                sqrSerializer.save(storage_request=storage_request)

        return storage_request
    def create(self, validated_data):
        """create.

        :param validated_data:
        :return compute_request:
        """
        compute_product = validated_data.pop('compute_product', None)
        if not compute_product or 'id' not in compute_product:
            raise ParseError('Compute product is required')

        compute_product_id = compute_product['id']
        compute_question_responses = validated_data.pop(
            'compute_question_responses', None)

        provision_details = validated_data.pop('provision_details', None)
        if provision_details:
            pSerializer = ProvisionDetailsSerializer(
                data=provision_details, context=self.context)
            pSerializer.is_valid(raise_exception=True)
            validated_data['provision_details'] = pSerializer.save()

        validated_data['compute_product'] = \
            lookupData.get_compute_product_obj({'pk': compute_product_id})

        compute_request = ComputeRequest.objects.create(**validated_data)
        if compute_question_responses:
            for cqr in compute_question_responses:
                cqrSerializer = ComputeQuestionResponseSerializer(data=cqr)
                cqrSerializer.is_valid(raise_exception=True)
                cqrSerializer.save(compute_request=compute_request)

        return compute_request
Beispiel #5
0
    def sanitize_provision_details(self, product_request_obj):
        default_pd = ProvisionDetailsSerializer.hide_error_msg_context()
        if self.context:
            pd_context = self.context.get(self.PR_CONTEXT, default_pd)
        else:
            pd_context = default_pd

        pd_serializer = ProvisionDetailsSerializer(
            product_request_obj.provision_details, context=pd_context)

        return pd_serializer.data
    def filter_provision_project(self, project_obj):
        """

        :param project_obj:
        :return:
        """
        self._setActionState()
        context_request = self.cramsActionState.rest_request
        current_user = context_request.user
        pd_context = ProvisionDetailsSerializer.show_error_msg_context()

        ret_list = []
        if not Provider.is_provider(current_user):
            return ret_list

        status_filter_set = ProvisionDetails.READY_TO_SEND_SET

        new_only = context_request.query_params.get('new_request', None)
        if not new_only:
            status_filter_set = \
                status_filter_set.union(ProvisionDetails.SET_OF_SENT)

        provider_provision_details = fetch_project_provision_list_for_provider(
            project_obj, current_user.provider)
        if not provider_provision_details.exists():  # new Project
            project_provision = ProjectProvisionDetails(project=project_obj)
            new_project_pd = new_provision_detail(current_user,
                                                  status=ProvisionDetails.SENT)
            project_provision.provision_details = new_project_pd
            project_provision.save()
            status_filter_set.union(ProvisionDetails.SENT)

        query_set = provider_provision_details.filter(
            provision_details__status__in=status_filter_set)
        for pp in query_set.all():
            pd = pp.provision_details
            if pd.status == ProvisionDetails.POST_PROVISION_UPDATE:
                pd.status = ProvisionDetails.POST_PROVISION_UPDATE_SENT
                pd.save()
            pd_serializer = ProvisionDetailsSerializer(pd, context=pd_context)
            ret_list.append(pd_serializer.data)
        return ret_list
    def sanitize_provision_details(self, product_request_obj):
        default_pd = ProvisionDetailsSerializer.hide_error_msg_context()
        if self.context:
            pd_context = self.context.get(self.PR_CONTEXT, default_pd)
        else:
            pd_context = default_pd

        pd_serializer = ProvisionDetailsSerializer(
            product_request_obj.provision_details,
            context=pd_context)

        return pd_serializer.data
Beispiel #8
0
def _populate_projects_response(
        rest_request, projects_dict, include_request_flag):
    ret_dict = {}
    user_obj = rest_request.user
    ret_dict['user'] = UserSerializer(user_obj).data

    project_list = []
    ret_dict['projects'] = project_list

    pd_context = ProvisionDetailsSerializer.build_context_obj(user_obj)

    for key in projects_dict.keys():

        proj_dict = projects_dict.get(key)
        proj = proj_dict['project']
        reqs = proj_dict['requests']

        pd_list = []
        for ppd in proj.linked_provisiondetails.all():
            pd_serializer = ProvisionDetailsSerializer(ppd.provision_details,
                                                       context=pd_context)
            pd_list.append(pd_serializer.data)

        project_dict = {}
        project_list.append(project_dict)
        project_dict['title'] = proj.title
        project_dict['id'] = proj.id
        project_dict['provision_details'] = pd_list

        if include_request_flag:
            request_list = []
            project_dict['requests'] = request_list
            for crams_req in reqs:
                request_list.append(populate_request_data(crams_req, user_obj))

    return Response(ret_dict)
    def filter_provision_project(self, project_obj):
        """

        :param project_obj:
        :return:
        """
        self._setActionState()
        context_request = self.cramsActionState.rest_request
        current_user = context_request.user
        pd_context = ProvisionDetailsSerializer.show_error_msg_context()

        ret_list = []
        if not Provider.is_provider(current_user):
            return ret_list

        status_filter_set = ProvisionDetails.READY_TO_SEND_SET

        new_only = context_request.query_params.get('new_request', None)
        if not new_only:
            status_filter_set = \
                status_filter_set.union(ProvisionDetails.SET_OF_SENT)

        provider_provision_details = fetch_project_provision_list_for_provider(
            project_obj, current_user.provider)
        if not provider_provision_details.exists():  # new Project
            project_provision = ProjectProvisionDetails(project=project_obj)
            new_project_pd = new_provision_detail(
                current_user, status=ProvisionDetails.SENT)
            project_provision.provision_details = new_project_pd
            project_provision.save()
            status_filter_set.union(ProvisionDetails.SENT)

        query_set = provider_provision_details.filter(
            provision_details__status__in=status_filter_set)
        for pp in query_set.all():
            pd = pp.provision_details
            if pd.status == ProvisionDetails.POST_PROVISION_UPDATE:
                pd.status = ProvisionDetails.POST_PROVISION_UPDATE_SENT
                pd.save()
            pd_serializer = ProvisionDetailsSerializer(pd, context=pd_context)
            ret_list.append(pd_serializer.data)
        return ret_list
def _populate_projects_response(
        rest_request, projects_dict, include_request_flag):
    ret_dict = {}
    user_obj = rest_request.user
    ret_dict['user'] = UserSerializer(user_obj).data

    project_list = []
    ret_dict['projects'] = project_list

    pd_context = ProvisionDetailsSerializer.build_context_obj(user_obj)

    for key in projects_dict.keys():

        proj_dict = projects_dict.get(key)
        proj = proj_dict['project']
        reqs = proj_dict['requests']

        pd_list = []
        for ppd in proj.linked_provisiondetails.all():
            pd_serializer = ProvisionDetailsSerializer(ppd.provision_details,
                                                       context=pd_context)
            pd_list.append(pd_serializer.data)

        project_dict = {}
        project_list.append(project_dict)
        project_dict['title'] = proj.title
        project_dict['id'] = proj.id
        project_dict['provision_details'] = pd_list

        if include_request_flag:
            request_list = []
            project_dict['requests'] = request_list
            for crams_req in reqs:
                request_list.append(populate_request_data(crams_req, user_obj))

    return Response(ret_dict)
Beispiel #11
0
 def build_context_obj(cls, user_obj, funding_body_obj):
     return {
         cls.PR_CONTEXT:
         ProvisionDetailsSerializer.build_context_obj(
             user_obj, funding_body_obj)
     }
Beispiel #12
0
 def hide_error_msg_context(cls):
     return {
         cls.PR_CONTEXT:
         ProvisionDetailsSerializer.hide_error_msg_context()
     }
 def build_context_obj(cls, user_obj, funding_body_obj):
     return {
         cls.PR_CONTEXT: ProvisionDetailsSerializer.build_context_obj(
             user_obj, funding_body_obj)
     }
 def hide_error_msg_context(cls):
     return {
         cls.PR_CONTEXT: ProvisionDetailsSerializer.hide_error_msg_context()
     }