Coder Social home page Coder Social logo

Comments (6)

maxtepkeev avatar maxtepkeev commented on July 27, 2024

Hi Shu!

What have you tried ?
Did you read the documentation for the version resource ?
Did you have any problems ?

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 project.versions relation.

from python-redmine.

tsengs avatar tsengs commented on July 27, 2024

HI Max,

I am using jinja2 template with your project. I've tried:

{% for i in data %}
{{ i.id }}
{{ i.description }}
{% if i.version %}{{ i.version.name }}{% endif %}
{% for v in i.versions %}
{{ v|showattrs }}
{{ v.description }}{% endfor %}
{% for f in i.version.custom_fields %}
{{ f|showattrs }}
{% if loop.index == 1 %} {{ f.value }} {{ f.name }} {% endif %} {% endfor %}
{% endfor %}

I am able to print these three
{{ i.id }}
{{ i.description }}
{{ i.version.name }}
but I got nothing for
{{ v.description }}
{{ f.value }}
{{ f.name }}

Shu

from python-redmine.

tsengs avatar tsengs commented on July 27, 2024

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 %}
{% for version in i.fixed_versions %}
{% for version in i.versions %}
{% for version in i.project_versions %}
{% for version in versions %}
{% for version in version_ids. %}
{% for version in fixed_versions %}
{% for version in fixed_version_ids %}

print
{{ version.description }}
{{ version.name }}
{{ version.value }}
{{ version.id }}

Thanks!
Shu

from python-redmine.

maxtepkeev avatar maxtepkeev commented on July 27, 2024

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 data in your cycle. You're using the variable i, so I believe that data is a resource set filled with issue resources. Issue resources only have a version attribute if a project contains versions in your Redmine and this version attribute represents a single resource, so I don't understand what you're trying to achieve when you're trying to iterate over them in a cycle.

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 dir function to see what attributes are available.

from python-redmine.

tsengs avatar tsengs commented on July 27, 2024

Hi Max,

The short question would be:
Within a Jinja2 template where you have an issue, how do you get that issue's version.description and it's custom fields?

A long explanation would be:
I understand the python can get it like below:

from redminereports import make_redmine
redmine = make_redmine()
print redmine.version.get(id).description
for cf in redmine.version.get(id).custom_fields:
print cf

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!
Shu

from python-redmine.

maxtepkeev avatar maxtepkeev commented on July 27, 2024

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.

from python-redmine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.