Search code examples
pythonredminepython-redmine

Can I get a list of users assigned to a project?


Using python-redmine module, is there a way to list all users assigned to a project through the Redmine API?

I've found that I'm able to request information about individual users, and that may API Key user is only assigned to a specific project and it can only see other users on the project. So I can do the following but it is hugely inefficient:

from redmine import Redmine
redmine = Redmine("https://myserver.net/", key="blahblah")

my_users = []
for x in range(1, 301):
    try:
        user = redmine.user.get(str(x))
        my_users.append(user.id)
    except:
        print "",

The above code gets me what I want, a list of the users on a project... but takes way too long to be practical. Plus there may be user IDs higher than any range I pick.

Update: Here is what I got to work, thnx @njzk2

my_users = []
project = redmine.project.get('myproject')
for membership in project.memberships:
    my_users.append(membership.user.id)

Solution

  • Probably something like:

    for membership in redmine.project.get('my_project').memberships:
        print membership.user_id
    

    see http://python-redmine.readthedocs.org/resources/project_membership.html and http://python-redmine.readthedocs.org/resources/project.html