Skip to content

Conversation

necrolyte2
Copy link

Maybe I am doing it wrong, but there are a lot of cases that I want to get say a tracker or custom_field by name. Since the Redmine API does not support this it makes it difficult and you have to essentially fetch all records and then filter them down manually.

This should essentially do that process instead of having the api user write their own function

Does it make sense to support a non-lazy operation though?

@rconradharris
Copy link
Contributor

@necrolyte2 Couldn't we have duplicates, for example two records with name as foo?

If thats the case, it feels like this should return a list, and maybe be called 'get_all_by_attribute`.

@necrolyte2
Copy link
Author

Good point. I'll change it and fix the build error too.
I was so focused on that I'm always trying to get a custom field id for filtering and our custom fields never have duplicate names, that I never really thought about all the cases.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f82743c on necrolyte2:master into * on maxtepkeev:master*.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably just return an empty list rather than raise an exception.

Copy link
Author

Choose a reason for hiding this comment

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

So just let the caller decide if it is an exception if the attribute does not exist?

Copy link
Author

Choose a reason for hiding this comment

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

N/m I see what you mean

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that makes sense; if no items are found that match the criteria, just return an empty record set.

…t return an Exception if the result set is empty
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 584b524 on necrolyte2:master into * on maxtepkeev:master*.

@maxtepkeev maxtepkeev self-assigned this Nov 4, 2014
@maxtepkeev
Copy link
Owner

I don't think that it should live in a ResourceManager. I believe that ResourceSet is the correct place for this method, otherwise you're hardcoding it to only work with all() method, but it can also be convenient to use it with any other method that returns a ResourceSet, e.g. filter().

@necrolyte2
Copy link
Author

Makes sense. I won't be able to get to changing that until next week, so if you get time and want to do it go for it.

@maxtepkeev
Copy link
Owner

I'm closing this pull request, because I've implemented a little bit more powerful Django-like lookup system for ResourceSet's get() and filter() methods. It allows you to do things like:

issues = redmine.issue.filter(project_id='foobar').filter(status__id=(2, 7), tracker__id=5, done_ratio=50)

i.e. the first call to filter(project_id='foobar') is the ResourceManager's filter method which just works as usual and makes the request to Redmine and returns the ResourceSet object with all issues of the foobar project. The second call to filter(status__id=(2, 7), tracker__id=5, done_ratio=50) is a new thing. It calls the filter() method on the ResourceSet object which will return a new ResourceSet with resource objects that have status_id either 2 or 7, tracker_id 5 and done_ration 50. The __ notation allows you to go as deep as you need to make filtering on the nested resource object's attributes.

I'll push the commits with this functionality a little bit later, because I want to rewrite a documentation a little bit and write some more tests for this.

@maxtepkeev maxtepkeev closed this Nov 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants