-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add num_annotations
to js-config
group context
#8939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
DeletedFilter, | ||
Limiter, | ||
Search, | ||
SharedAnnotationsFilter, | ||
TopLevelAnnotationsFilter, | ||
UserFilter, | ||
) | ||
|
@@ -48,6 +49,24 @@ def group_annotation_count(self, pubid): | |
params = MultiDict({"limit": 0, "group": pubid}) | ||
return self._search(params) | ||
|
||
def total_group_annotation_count(self, pubid, unshared=True): | ||
""" | ||
Return the count of all annotations for a group. | ||
|
||
This counts all of the group's annotations and replies from all users. | ||
|
||
If `unshared=True` then "Only Me" annotations and replies in the group | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had trouble passing this parameter meaning. It might be clearer with a more verbose name? |
||
(`Annotation.shared=False`) from *all* users (not just the | ||
authenticated user) will be counted. | ||
|
||
If `unshared=False` then no unshared annotations or replies will be | ||
counted, not even ones from the authenticated user. | ||
""" | ||
search = Search(self.request) | ||
if not unshared: | ||
search.append_modifier(SharedAnnotationsFilter()) | ||
return search.run(MultiDict({"limit": 0, "group": pubid})).total | ||
|
||
def _search(self, params): | ||
search = Search(self.request) | ||
search.append_modifier(TopLevelAnnotationsFilter()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ class GroupCreateEditController: | |
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
self.annotation_stats_service = request.find_service(name="annotation_stats") | ||
|
||
@view_config(route_name="group_create", request_method="GET") | ||
def create(self): | ||
|
@@ -58,6 +59,9 @@ def _js_config(self): | |
"link": self.request.route_url( | ||
"group_read", pubid=group.pubid, slug=group.slug | ||
), | ||
"num_annotations": self.annotation_stats_service.total_group_annotation_count( | ||
group.pubid, unshared=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is unshared always going to be False? Or are you thinking ahead of an immediate need for other type of group? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is unshared always going to be False? Or are you thinking ahead of an immediate need for other type of group? |
||
), | ||
} | ||
js_config["api"]["updateGroup"] = { | ||
"method": "PATCH", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always caught by surprise about how this API works, with these callable classes to represent different filters.
🤷 Anyway this fits in the overall current design.