|
@@ -924,41 +924,6 @@ class ContentApi(object):
|
924
|
924
|
|
925
|
925
|
return resultset.all()
|
926
|
926
|
|
927
|
|
- def get_last_active(self, parent_id: int, content_type: str, workspace: Workspace=None, limit=10) -> typing.List[Content]:
|
928
|
|
- assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
|
929
|
|
- assert content_type is not None# DYN_REMOVE
|
930
|
|
- assert isinstance(content_type, str) # DYN_REMOVE
|
931
|
|
-
|
932
|
|
- resultset = self._base_query(workspace) \
|
933
|
|
- .filter(Content.workspace_id == Workspace.workspace_id) \
|
934
|
|
- .filter(Workspace.is_deleted.is_(False)) \
|
935
|
|
- .order_by(desc(Content.updated))
|
936
|
|
-
|
937
|
|
- if content_type!=ContentType.Any:
|
938
|
|
- resultset = resultset.filter(Content.type==content_type)
|
939
|
|
-
|
940
|
|
- if parent_id:
|
941
|
|
- resultset = resultset.filter(Content.parent_id==parent_id)
|
942
|
|
-
|
943
|
|
- result = []
|
944
|
|
- for item in resultset:
|
945
|
|
- new_item = None
|
946
|
|
- if ContentType.Comment == item.type:
|
947
|
|
- new_item = item.parent
|
948
|
|
- else:
|
949
|
|
- new_item = item
|
950
|
|
-
|
951
|
|
- # INFO - D.A. - 2015-05-20
|
952
|
|
- # We do not want to show only one item if the last 10 items are
|
953
|
|
- # comments about one thread for example
|
954
|
|
- if new_item not in result:
|
955
|
|
- result.append(new_item)
|
956
|
|
-
|
957
|
|
- if len(result) >= limit:
|
958
|
|
- break
|
959
|
|
-
|
960
|
|
- return result
|
961
|
|
-
|
962
|
927
|
def get_last_unread(self, parent_id: int, content_type: str,
|
963
|
928
|
workspace: Workspace=None, limit=10) -> typing.List[Content]:
|
964
|
929
|
assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
|
|
@@ -989,7 +954,7 @@ class ContentApi(object):
|
989
|
954
|
self,
|
990
|
955
|
workspace: Workspace=None,
|
991
|
956
|
limit: typing.Optional[int]=None,
|
992
|
|
- before_datetime: typing.Optional[datetime.datetime]= None,
|
|
957
|
+ before_content: typing.Optional[Content]= None,
|
993
|
958
|
content_ids: typing.Optional[typing.List[int]] = None,
|
994
|
959
|
) -> typing.List[Content]:
|
995
|
960
|
"""
|
|
@@ -997,7 +962,8 @@ class ContentApi(object):
|
997
|
962
|
(last modification of content itself or one of this comment)
|
998
|
963
|
:param workspace: Workspace to check
|
999
|
964
|
:param limit: maximum number of elements to return
|
1000
|
|
- :param before_datetime: date from where we check older content.
|
|
965
|
+ :param before_content: last_active content are only those updated
|
|
966
|
+ before this content given.
|
1001
|
967
|
:param content_ids: restrict selection to some content ids and
|
1002
|
968
|
related Comments
|
1003
|
969
|
:return: list of content
|
|
@@ -1021,6 +987,7 @@ class ContentApi(object):
|
1021
|
987
|
|
1022
|
988
|
active_contents = []
|
1023
|
989
|
too_recent_content = []
|
|
990
|
+ before_content_find = False
|
1024
|
991
|
for content in resultset:
|
1025
|
992
|
related_active_content = None
|
1026
|
993
|
if ContentType.Comment == content.type:
|
|
@@ -1028,18 +995,16 @@ class ContentApi(object):
|
1028
|
995
|
else:
|
1029
|
996
|
related_active_content = content
|
1030
|
997
|
|
1031
|
|
- if not before_datetime:
|
1032
|
|
- before_datetime = datetime.datetime.now()
|
1033
|
|
- # INFO - D.A. - 2015-05-20
|
1034
|
|
- # We do not want to show only one item if the last 10 items are
|
1035
|
|
- # comments about one thread for example
|
1036
|
998
|
if related_active_content not in active_contents and related_active_content not in too_recent_content: # nopep8
|
1037
|
|
- # we verify that content is old enough
|
1038
|
|
- if content.updated < before_datetime:
|
|
999
|
+
|
|
1000
|
+ if not before_content or before_content_find:
|
1039
|
1001
|
active_contents.append(related_active_content)
|
1040
|
1002
|
else:
|
1041
|
1003
|
too_recent_content.append(related_active_content)
|
1042
|
1004
|
|
|
1005
|
+ if before_content and related_active_content == before_content:
|
|
1006
|
+ before_content_find = True
|
|
1007
|
+
|
1043
|
1008
|
if limit and len(active_contents) >= limit:
|
1044
|
1009
|
break
|
1045
|
1010
|
|