-
Notifications
You must be signed in to change notification settings - Fork 119
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
values in the version--jinja2 can't get it. #51
Comments
Hi Shu! What have you tried ? Basically it's the same as with all resources: version = redmine.version.get(12345) # 12345 is your version id
version.description
'I am description of the version 12345'
version.custom_fields
<redmine.resultsets.ResourceSet object with CustomField resources> OR versions = redmine.version.filter(project_id=12345) # 12345 is your project id with versions
for version in versions:
print(version.description)
for field in version.custom_fields:
print(field) You can also get versions from the project resource via |
HI Max, I am using jinja2 template with your project. I've tried: {% for i in data %} I am able to print these three Shu |
Hi Max, I did read the documentation and I tried a couple of other possibilities to get the fields, but in vain. Can you maybe tell what I've missed? {% for i in data %} print Thanks! |
Hi, Shu! Python-Redmine works absolutely fine with jinja2, django templates or any other template engine. When you're trying to print something and get nothing, means that you're trying to get an attribute that doesn't exist but you get nothing because template engines usually suppress some common exceptions. Try to run the same cycle in Python and you'll get an exception. Also I don't understand what is As I said there are no problems with python-redmine and any template engine. What I can recommend you to do is to recreate this same cycle in pure Python and examine existing attributes via |
Hi Max, The short question would be: A long explanation would be: from redminereports import make_redmine But is there a way to access the Fixed_Version object associated with an Issue directory from a Redmine() object? The only method I know for accessing the fixed_version object associated with an Issue is via a call to Redmine().version.get(id).custom_fields(). I need to access to each Issue's fixed_version in a Jinja2 template and I can't call python code within Jinja2. I don't have access to the database and I don't control the data source, so I can't have Redmine().version.get() called externally. Is there an alternative? Thanks! |
Hi Shu, Your python code is invalid, here's the right one: from redmine.exceptions import ResourceAttrError
from redminereports import make_redmine
redmine = make_redmine()
# let's get all issues from a project where we have some versions defined
issues = redmine.issue.filter(project_id='foobar')
for issue in issues:
try:
# we need to load all the available info for this version resource,
# because by default Redmine gives us only id and name
version = issue.version.refresh()
except ResourceAttrError:
version = None
if version is not None:
for custom_field in version.custom_fields:
print(
custom_field.id, # id
custom_field.name, # name
dir(custom_field) # all the available attributes
) This code will do exactly what you asked for, i.e. you'll have an access to each issues version custom fields. I can't help you with porting this to jinja2, because I don't use it, you'll have to figure out this yourself, or ask someone who knows jinja2. This has nothing to do with python-redmine, this is about how you can call python object methods within a template engine. |
Hi Max,
Here I come again. This time I am trying to get 'description' of the version, and the custom fields I made in the version. Can you tell me how to retrieve them?
Thanks,
Shu
The text was updated successfully, but these errors were encountered: