Jump to content

Access custom_attributes' labels


Tim Edelmann

Recommended Posts

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

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...