Access custom_attributes' labels
0

5 posts in this topic

Hey everybody, 

 

we would like to use our custom_attributes' labels (that get setup when creating a custom_attribute-entry) when creating folders in the project. In javascript we access these via the projects' custom_properties

like so:

response.data[0].custom_attributes;

with response.data[0] being the project. And from here each attribute has a 'configuration' containing a 'config'. In here we found 'data' and finally 'menu' which contains a pretty printable name of the attribute. But via the python api we're not able to find an equivalent. 

Are we looking in the wrong place?

We would be greatfull for some insight.

Since all the attributes have a 'label' containing a well formatted string in the system-settings, we thought, this would be accessible somehow..

 

Tim

Share this post


Link to post
Share on other sites

Hi Tim,

you can reach the custom attribute configuration like this

 

    project = session.query(
        'select custom_attributes.configuration.label from Project'
    ).first()

    for custom_attribute in project.get('custom_attributes').collection:
        logging.info(
            custom_attribute.get('configuration').get('label')
        )

 

cheers

Eric

Share this post


Link to post
Share on other sites

Hi Eric, 

 

thanks for the very fast answer!

We found a solution to this right before I read it. It looks different, but doesn't seem to be slower/faster.. however your solution is shorter :) 

 

this was ours:

search_key = '2_Client_Meeting'
tmp = session.query('CustomAttributeConfiguration').all()
for entry in tmp:
	if 'data' in entry['config']:
		json_obj = json.loads(entry['config'])
		data_obj = json.loads(json_obj['data'])
		for subentry in data_obj:
			if search_key == subentry['value']:
				print 'found:"',subentry['menu'],'" for key:',search_key,'in',entry['key']

 

 

We decided to use the 'menu' entries of the attributes. we take these from config/data which is both json saved as plain text. Is there a better way to do this?

 

thanks again

Share this post


Link to post
Share on other sites

Not that I can think of, I suppose you could use projections and filter out a few entries like below to make it a bit quicker.

 

    search_key = '2_Client_Meeting'

    for custom_attribute_config in session.query(
        'select config from CustomAttributeConfiguration where config like "%\\"data\\"%"'
    ):
        try:
            data = json.loads(
                json.loads(custom_attribute_config.get('config'))['data']
            )

            for entry in [entry for entry in data if entry['value'] == search_key]:
                logging.info(
                    u'found: {0} for key in {1}'.format(
                        entry['menu'], custom_attribute_config['key']
                    )
                )

        except ValueError:
            raise

 

cheers

Eric

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
0