示例#1
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 _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)
示例#3
0
 def build_context_obj(cls, user_obj, funding_body_obj):
     return {
         cls.PR_CONTEXT:
         ProvisionDetailsSerializer.build_context_obj(
             user_obj, funding_body_obj)
     }
示例#4
0
 def build_context_obj(cls, user_obj, funding_body_obj):
     return {
         cls.PR_CONTEXT: ProvisionDetailsSerializer.build_context_obj(
             user_obj, funding_body_obj)
     }