This repository has been archived by the owner on Feb 21, 2019. It is now read-only.
Feature/806 add label filter and sort content by label in contents endpoint #45
Merged
buxx
merged 15 commits into
develop
from
feature/806_add_label_filter_and_sort_content_by_label_in_contents_endpoint
Sep 27, 2018
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
94bd1b5
add filter by label in workspace_content endpoint
inkhey 4b3c97c
sort content by label in content endpoint
inkhey 3a0c516
Do not allow empty label value directly from schema
inkhey 6db446b
order_by_property refactor
inkhey 845f8ba
allow sort by list of properties instead of only one property
inkhey 5a0f42b
Merge branch 'develop' of github.com:tracim/tracim_v2 into feature/80…
inkhey abfe0ca
better typing
inkhey 3f3f498
Merge branch 'develop' of github.com:tracim/tracim_v2 into feature/80…
inkhey 14bc527
better typing
inkhey 6d869f8
better docstring
inkhey f520524
better docstring, more explicit about order_by_properties + get_all h…
inkhey a2d0bf5
better default value for order by properties
inkhey 64ea79f
Merge branch 'develop' into feature/806_add_label_filter_and_sort_con…
inkhey ab228b3
fix broken schema
inkhey 21b5bc8
fix broken schema
inkhey File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1002,7 +1002,9 @@ def _get_all_query( | |
self, | ||
parent_id: int = None, | ||
content_type_slug: str = CONTENT_TYPES.Any_SLUG, | ||
workspace: Workspace = None | ||
workspace: Workspace = None, | ||
label:str = None, | ||
order_by_properties: typing.List[str] = (), | ||
) -> Query: | ||
""" | ||
Extended filter for better "get all data" query | ||
|
@@ -1028,11 +1030,23 @@ def _get_all_query( | |
resultset = resultset.filter(Content.parent_id==parent_id) | ||
if parent_id == 0 or parent_id is False: | ||
resultset = resultset.filter(Content.parent_id == None) | ||
if label: | ||
resultset = resultset.filter(Content.label.ilike('%{}%'.format(label))) # nopep8 | ||
|
||
for _property in order_by_properties: | ||
resultset = resultset.order_by(_property) | ||
|
||
return resultset | ||
|
||
def get_all(self, parent_id: int=None, content_type: str=CONTENT_TYPES.Any_SLUG, workspace: Workspace=None) -> typing.List[Content]: | ||
return self._get_all_query(parent_id, content_type, workspace).all() | ||
def get_all( | ||
self, | ||
parent_id: int=None, | ||
content_type: str=CONTENT_TYPES.Any_SLUG, | ||
workspace: Workspace=None, | ||
label: str=None, | ||
order_by_properties: typing.List[str] = () | ||
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. Type hint is wrong. It should by typing.List[Column], doesnt it? |
||
) -> typing.List[Content]: | ||
return self._get_all_query(parent_id, content_type, workspace, label, order_by_properties).all() | ||
|
||
# TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded | ||
# def get_children(self, parent_id: int, content_types: list, workspace: Workspace=None) -> typing.List[Content]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Type hint is wrong. It should by typing.List[Column], doesnt it?
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.
Currently no, we currently pass strings to "order_by" function of sqlalchemy.
We can also pass Column, complex sql subquery and probably others thing to this function, but as we have string in entry from endpoint and that string work for ordering, i do not think about casting this to Column.
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.
@inkhey the part of code I looked at was something like
.order_by(Content.label)
. Do you really pass strings? If so, what is the string content?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.
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.
You're right, in fact, i pass "Content.label" which is "'hybrid_propertyProxy" .... i just tried with passing "label" and it work also.
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.
Actually, the problem is that typing must help developer to understand the code. If the typing is defined as "string", the developer has no information about what to give as a parameter. I see 2 possibilities :
Maybe both must be implemented.
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.
problem i see is that typing who should allowed here is clearly unclear.
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.
ok. so I suggest you set the typing to "str or hybrid_propertyProxy", and you add docstring explaining that the recommanded way to use it is to pass
Model.attribute
.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.
as soos as you fix this, tell me (or @buxx) to merge the MR