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
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
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
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
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
def alter_list_data_to_serialize(self, request, data): """ Modify content just before serialized to output """ # Tag-based filtering if request.method == "GET": if 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["created"] for obj in data["objects"]] # In the case where a call returns no likes if len(object_modified_dts) > 0: data["meta"]["modified"] = max(object_modified_dts) else: data["meta"]["modified"] = datetime.datetime(1970, 1, 1) # Nothing classified about likes/dislikes - they have no content other than user max_pm = documents.ProtectiveMarking( classification="NOT CLASSIFIED", classification_short="NC", classification_rank=-1, national_caveats_primary_name="", national_caveats_members=[], national_caveats_rank=-1, codewords=[], codewords_short=[], descriptor="", ) data["meta"]["max_pm"] = json.loads(max_pm.to_json()) # Metadata only requests if request.GET.get("data_level") == "meta": del data["objects"] return data return data
def alter_list_data_to_serialize(self, request, data): """ Modify content just before serialized to output """ # Tag-based filtering if request.method == 'GET': if 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['created'] for obj in data['objects'] ] # In the case where a call returns no likes if len(object_modified_dts) > 0: data['meta']['modified'] = max(object_modified_dts) else: data['meta']['modified'] = datetime.datetime(1970, 1, 1) # Nothing classified about likes/dislikes - they have no content other than user max_pm = documents.ProtectiveMarking( classification='NOT CLASSIFIED', classification_short='NC', classification_rank=-1, national_caveats_primary_name='', national_caveats_members=[], national_caveats_rank=-1, codewords=[], codewords_short=[], descriptor='') data['meta']['max_pm'] = json.loads(max_pm.to_json()) # Metadata only requests if request.GET.get('data_level') == 'meta': del data['objects'] return data return data
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
def alter_list_data_to_serialize(self, request, data): ''' Modify content just before serialized to output ''' # Tag-based filtering if request.method == 'GET': if 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['created'] for obj in data['objects']] # In the case where a call returns no backs if len(object_modified_dts) > 0: data['meta']['modified'] = max(object_modified_dts) else: data['meta']['modified'] = datetime.datetime(1970,1,1) # Nothing classified about backs - they have no content other than user max_pm = documents.ProtectiveMarking(classification = 'NOT CLASSIFIED', classification_short = 'NC', classification_rank = -1, national_caveats_primary_name = '', national_caveats_members = [], national_caveats_rank = -1, codewords = [], codewords_short = [], descriptor = '') data['meta']['max_pm'] = json.loads(max_pm.to_json()) # Metadata only requests if request.GET.get('data_level') == 'meta': del data['objects'] return data return data