Skip to content
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

Conversation

inkhey
Copy link
Contributor

@inkhey inkhey commented Sep 7, 2018

related to tracim/tracim#806

@inkhey inkhey added the backend label Sep 7, 2018
@coveralls
Copy link

coveralls commented Sep 7, 2018

Pull Request Test Coverage Report for Build 775

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 100 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.003%) to 90.967%

Files with Coverage Reduction New Missed Lines %
tracim_backend/models/context_models.py 6 98.76%
tracim_backend/views/core_api/workspace_controller.py 12 95.6%
tracim_backend/lib/core/content.py 82 83.31%
Totals Coverage Status
Change from base Build 768: 0.003%
Covered Lines: 15046
Relevant Lines: 16540

💛 - Coveralls

Copy link
Collaborator

@lebouquetin lebouquetin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buxx @inkhey I suggest to implement a more genery way of sorting.

content_type: str=CONTENT_TYPES.Any_SLUG,
workspace: Workspace=None,
label: str=None,
order_by_label=False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using something like order_by_property with a default value to None and:

if order_by_property:
  resultset = resultset.order_by(order_by_property) ?

The usage would be get_all(..., order_by_property=Content.label)?

@buxx @inkhey what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@tracim tracim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last change request

backend/tracim_backend/lib/core/content.py Outdated Show resolved Hide resolved
workspace: Workspace = None
workspace: Workspace = None,
label:str = None,
order_by_properties: typing.List[str] = (),
Copy link
Collaborator

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?

Copy link
Contributor Author

@inkhey inkhey Sep 26, 2018

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.

Copy link
Collaborator

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ grep -r order_by *
backend/tracim_backend/lib/core/group.py:        return self._base_query().order_by(Group.group_id).all()
backend/tracim_backend/lib/core/workspace.py:            workspaces = self._base_query().order_by(Workspace.label).all()
backend/tracim_backend/lib/core/workspace.py:                .order_by(Workspace.label) \
backend/tracim_backend/lib/core/user.py:        return self._session.query(User).order_by(User.display_name)
backend/tracim_backend/lib/core/userworkspace.py:    # def get_all_for_user_order_by_workspace(
backend/tracim_backend/lib/core/userworkspace.py:    #         .join(UserRoleInWorkspace.workspace).order_by(Workspace.label).all()
backend/tracim_backend/lib/core/content.py:                    .order_by(ContentRevisionRO.revision_id.desc())
backend/tracim_backend/lib/core/content.py:            .order_by(
backend/tracim_backend/lib/core/content.py:                .order_by(Content.revision_id.desc()) \
backend/tracim_backend/lib/core/content.py:        resultset = resultset.order_by(desc(Content.updated))
backend/tracim_backend/lib/core/content.py:    #         .order_by(desc(Content.updated))
backend/tracim_backend/models/data.py:                             order_by="ContentRevisionRO.revision_id")
backend/tracim_backend/tests/models/test_content.py:            .order_by(ContentRevisionRO.revision_id.desc())\
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py:            .order_by(ContentRevisionRO.revision_id.desc()) \

Copy link
Contributor Author

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.

Copy link
Collaborator

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 :

  • improve typing (the best solution)
  • add docstring

Maybe both must be implemented.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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

content_type: str=CONTENT_TYPES.Any_SLUG,
workspace: Workspace=None,
label: str=None,
order_by_properties: typing.List[str] = ()
Copy link
Collaborator

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?

workspace: Workspace = None
workspace: Workspace = None,
label:str = None,
order_by_properties: typing.List[typing.Union[str, QueryableAttribute]] = (),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some problems here:

  • typing say List, default value is a tuple (it should be empty list)
  • we can't give an list instance here, example:
>>> def foo(a=[]):
...   a.append(1)
...   print(a)
... 
>>> foo()
[1]
>>> foo()
[1, 1]
>>> foo()
[1, 1, 1]
>>> foo()
[1, 1, 1, 1]

Prefer:

def foo(a=None):
  a = a or []  # FDV

FDV = Forced Default Value

@buxx buxx merged commit 4c11dcd into develop Sep 27, 2018
@inkhey inkhey deleted the feature/806_add_label_filter_and_sort_content_by_label_in_contents_endpoint branch October 3, 2018 10:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants