Exemplo n.º 1
0
    def alter_detail_data_to_serialize(self, request, data):
        """ Modify the content just before serializing data for a specific item """

        # Don't apply the meta object if it's anything but GET
        if request.method == 'GET':

            # Add a meta element for the single item response
            response_data = {'meta': {}, 'objects': [data]}

            # Add max PM into a newly created meta object
            pms = get_all_pms(response_data['objects'],
                              subdocs_to_check=[],
                              pm_name='protective_marking')
            response_data['meta']['max_pm'] = get_max_pm(pms)

            # Get the modified time for this 1 object
            response_data['meta']['modified'] = data.data['modified']

            # Filter out the meta and objects content based on the data_level
            response_data = filter_by_data_level(request, response_data)

        else:
            response_data = data

        return response_data
Exemplo n.º 2
0
    def alter_list_data_to_serialize(self, request, data):
        """ Modify content just before serialized to output """

        # Try to get the modified timestamp. Except catches instance where no data
        try:
            idea_mod = documents.Idea.objects.order_by(
                '-modified')[0]['modified']
        except:
            return data

        # Retrieve all comment modified timestamps (idea, comments)
        res = documents.Idea._get_collection().aggregate([{
            "$project": {
                "_id": 0,
                "comments": 1
            }
        }, {
            "$unwind":
            "$comments"
        }, {
            "$project": {
                "modified": "$comments.modified"
            }
        }, {
            "$sort": {
                "modified": -1
            }
        }, {
            "$limit": 1
        }])['result']

        # In the event that there are no comments, chuck in an old date to guarantee the idea mod date wins
        if res:
            comments_mod = res[0]['modified']
        else:
            comments_mod = datetime.datetime(1970, 1, 1)

        # Assign the meta-level modified datetime to the most recent comment/idea modified datetime
        data['meta']['modified'] = max([idea_mod, comments_mod])

        # Tag-based filtering
        if request.method == 'GET' and request.GET.get('tags__in'):
            data = tag_based_filtering(request, data)

        # Find the highest protective marking in the dataset
        pms = get_all_pms(data['objects'],
                          subdocs_to_check=['comments'],
                          pm_name='protective_marking')
        data['meta']['max_pm'] = get_max_pm(pms)

        # Filter out the meta and objects content based on the data_level
        if request.method == 'GET':
            data = filter_by_data_level(request, data)

        return data
Exemplo n.º 3
0
    def alter_list_data_to_serialize(self, request, data):

        """ Modify content just before serialized to output """

        # Try to get the modified timestamp. Except catches instance where no data
        try:
            idea_mod = documents.Idea.objects.order_by("-modified")[0]["modified"]
        except:
            return data

        # Retrieve all comment modified timestamps (idea, comments)
        res = documents.Idea._get_collection().aggregate(
            [
                {"$project": {"_id": 0, "comments": 1}},
                {"$unwind": "$comments"},
                {"$project": {"modified": "$comments.modified"}},
                {"$sort": {"modified": -1}},
                {"$limit": 1},
            ]
        )["result"]

        # In the event that there are no comments, chuck in an old date to guarantee the idea mod date wins
        if res:
            comments_mod = res[0]["modified"]
        else:
            comments_mod = datetime.datetime(1970, 1, 1)

        # Assign the meta-level modified datetime to the most recent comment/idea modified datetime
        data["meta"]["modified"] = max([idea_mod, comments_mod])

        # Tag-based filtering
        if request.method == "GET" and request.GET.get("tags__in"):
            data = tag_based_filtering(request, data)

        # Find the highest protective marking in the dataset
        pms = get_all_pms(data["objects"], subdocs_to_check=["comments"], pm_name="protective_marking")
        data["meta"]["max_pm"] = get_max_pm(pms)

        # Filter out the meta and objects content based on the data_level
        if request.method == "GET":
            data = filter_by_data_level(request, data)

        return data
Exemplo n.º 4
0
    def alter_list_data_to_serialize(self, request, data):
        
        ''' Modify content just before serialized to output '''             

        # Try to get the modified timestamp. Except catches instance where no data
        try:
            proj_mod = documents.Project.objects.order_by('-modified')[0]['modified']
        except:
            return data
        
        # Retrieve all comment modified timestamps (idea, comments)
        res = documents.Project._get_collection().aggregate([
            { "$project" : {"_id" : 0, "comments" : 1}},
            { "$unwind" : "$comments" },
            { "$project" : {"modified" : "$comments.modified"}},
            { "$sort" : {"modified" : -1}},
            { "$limit" : 1}
        ])['result']
        
        # In the event that there are no comments, chuck in an old date to guarantee the Project mod date wins
        if res:
            comments_mod = res[0]['modified']
        else:
            comments_mod = datetime.datetime(1970,1,1)
            
        # Assign the meta-level modified datetime to the most recent comment/Project modified datetime
        data['meta']['modified'] = max([proj_mod, comments_mod])
        
        # Tag-based filtering
        if request.method == 'GET' and request.GET.get('tags__in'):
            data = tag_based_filtering(request, data)
        
        # Find the highest protective marking in the dataset
        pms = get_all_pms(data['objects'], subdocs_to_check=['comments'], pm_name='protective_marking')
        data['meta']['max_pm'] = get_max_pm(pms)    

        # Filter out the meta and objects content based on the data_level
        if request.method == 'GET':
            data = filter_by_data_level(request, data)
        
        return data
Exemplo n.º 5
0
    def alter_detail_data_to_serialize(self, request, data):
        """ Modify the content just before serializing data for a specific item """

        # Don't apply the meta object if it's anything but GET
        if request.method == "GET":
            # Add a meta element for the single item response
            response_data = {"meta": {}, "objects": [data]}

            # Add max PM into a newly created meta object
            pms = get_all_pms(response_data["objects"], subdocs_to_check=["comments"], pm_name="protective_marking")
            response_data["meta"]["max_pm"] = get_max_pm(pms)

            # Get the modified time for this 1 object
            response_data["meta"]["modified"] = data.data["modified"]

            # Filter out the meta and objects content based on the data_level
            response_data = filter_by_data_level(request, response_data)

        else:
            response_data = data

        return response_data
Exemplo n.º 6
0
    def alter_list_data_to_serialize(self, request, data):

        """ Modify content just before serialized to output """

        # Tag-based filtering
        if request.method == "GET" and request.GET.get("tags__in"):
            data = tag_based_filtering(request, data)

        # Assign the meta-level modified datetime to the most recent comment/idea modified datetime
        object_modified_dts = [obj.data["modified"] for obj in data["objects"]]
        if len(object_modified_dts) > 0:
            data["meta"]["modified"] = max(object_modified_dts)

        # Find the highest protective marking in the dataset
        pms = get_all_pms(data["objects"], subdocs_to_check=[], pm_name="protective_marking")
        data["meta"]["max_pm"] = get_max_pm(pms)

        # Filter out the meta and objects content based on the data_level
        if request.method == "GET":
            data = filter_by_data_level(request, data)

        return data
Exemplo n.º 7
0
    def alter_list_data_to_serialize(self, request, data):
        
        ''' Modify content just before serialized to output '''             
        
        # Tag-based filtering
        if request.method == 'GET' and request.GET.get('tags__in'):
            data = tag_based_filtering(request, data)
        
        # Assign the meta-level modified datetime to the most recent comment/project modified datetime
        object_modified_dts = [obj.data['modified'] for obj in data['objects']]
        if len(object_modified_dts) > 0:
            data['meta']['modified'] = max(object_modified_dts)
        
        # Find the highest protective marking in the dataset
        pms = get_all_pms(data['objects'],subdocs_to_check=[], pm_name='protective_marking')
        data['meta']['max_pm'] = get_max_pm(pms)    

        # Filter out the meta and objects content based on the data_level
        if request.method == 'GET':
            data = filter_by_data_level(request, data)
        
        return data
Exemplo n.º 8
0
    def alter_list_data_to_serialize(self, request, data):
        """ Modify content just before serialized to output """

        # Tag-based filtering
        if request.method == 'GET' and request.GET.get('tags__in'):
            data = tag_based_filtering(request, data)

        # Assign the meta-level modified datetime to the most recent comment/idea modified datetime
        object_modified_dts = [obj.data['modified'] for obj in data['objects']]
        if len(object_modified_dts) > 0:
            data['meta']['modified'] = max(object_modified_dts)

        # Find the highest protective marking in the dataset
        pms = get_all_pms(data['objects'],
                          subdocs_to_check=[],
                          pm_name='protective_marking')
        data['meta']['max_pm'] = get_max_pm(pms)

        # Filter out the meta and objects content based on the data_level
        if request.method == 'GET':
            data = filter_by_data_level(request, data)

        return data
Exemplo n.º 9
0
    def alter_detail_data_to_serialize(self, request, data):
        ''' Modify the content just before serializing data for a specific item '''
        
        # Don't apply the meta object if it's anything but GET
        if request.method == 'GET':
            
            # Add a meta element for the single item response
            response_data = {'meta':{},'objects':[data]}
    
            # Add max PM into a newly created meta object
            pms = get_all_pms(response_data['objects'],subdocs_to_check=['comments'],pm_name='protective_marking')
            response_data['meta']['max_pm'] = get_max_pm(pms)    
    
            # Get the modified time for this 1 object
            response_data['meta']['modified'] = data.data['modified'] 
    
            # Filter out the meta and objects content based on the data_level
            response_data = filter_by_data_level(request, response_data)
    
        else:
            response_data = data

        return response_data