jira python customfield - python

How do you determine the name of a custom field in jira-python?
When I retrieve an issue, my custom fields show up as customfield_xxx
The names on my screen are 'project', 'name', 'due date', etc.
Short of putting a value in each field, then seeing where it appears
when I re-read the issue.
That is I can put 'a' in one of my fields, then read the issue, and find that
customfield_10801 (or whatever) has the value 'a'. But is there a general
way to find, for example, if my custom field is 'due date', which customfield_xxx
does it get mapped to?
Or, in the JIRA GUI, how would I look up these customfield #'s.

From the GUI you can see the custom field id in the html code or url:
On the admin page where all the custom fields are listed on the row of the custom field you are interested to the right click the gear and click/hover over "Configure". You should see the custom field ID in the URL.
Another way is via the REST API:
{jira-base-url}/rest/api/2/field
It's a GET request so just put that url in your browser.
Update:
Based on the comments it can be done something like this:
# Fetch all fields
allfields=jira.fields()
# Make a map from field name -> field id
nameMap = {field['name']:field['id'] for field in allfields}
# Fetch an issue
issue = jira.issue('ABC-1')
# You can now look up custom fields by name using the map
getattr(issue.fields, nameMap[custom_name])

Related

Automated action to add multiple users as followers in Odoo 15

I created a custom module where you can link multiple contacts in a many2many field and I want to automatically add them all as a follower. I've read this article:
Automated Action to Add Users as Followers Odoo 12
Adding followers works fine, but only when the fields have ONE user or partner in it. In my installation these are many2many fields. When I add more then one user or partner in one of the fields, the code crashes.
Do I need to change something in this code when I want to add more then 1 contact or user in one of the fields?
I have this python code in my automated action:
record.message_subscribe(partner_ids=[record.field1.id, record.field2.partner_id.id, record.field3.partner_id.id])
field1 = partner
field2 & field3 = user
Thanks for your help!
You can not use .id to get id of records when there is multiple record, you have to use .ids which returns a list of record ids. So you code will have to changed into:
field1_ids = record.field1.ids
field2_ids = record.field2.mapped('partner_id').ids
field3_ids = record.field3.mapped('partner_id').ids
record.message_subscribe(partner_ids=field1_ids+field2_ids+field3_ids)
So the main issue with your code was, you were trying to access field where the record could be multiple (as many2many), but in Odoo ORM you can not do that, it will always give Expected Singletone error for multiple records.

Ignore one field in a django model

I have a django model that has the following four fields:
class File:
id = models.PrimaryKey()
name = models.CharField()
is_active = models.BooleanField()
data = models.JSONField()
The data field is massive, perhaps 5MB per entry. Is there a way I can hide that field when I do an ORM query without having to specify all the fields I want to view each time? Something like:
File.objects.all() # exclude data field
File.objects.values('id', 'data') # include the data field
In some complex data-modeling situations, your models might contain a lot of fields, some of which could contain a lot of data (for example, text fields), or require expensive processing to convert them to Python objects. If you are using the results of a queryset in some situation where you don’t know if you need those particular fields when you initially fetch the data, you can tell Django not to retrieve them from the database.
This is done by passing the names of the fields to not load to defer():
Entry.objects.defer("headline", "body")
Also mention that, Whenever you call only() it replaces the set of fields to load immediately. The method’s name is mnemonic: only those fields are loaded immediately; the remainder are deferred.
You can use only() to specify the fields you want
File.objects.only('id', 'data')

How to set domain with a many2one

I have a many2one that links to event.event called xx_event_id. In event.event I made a link to xx_weeks that is a separate model that keeps a list of weeks. Then the name of those weeks also links to a model called xx_week_name.
I'm trying to make a domain on xx_week_name. When I select an event I only want it to show the week names that are in the event.
So my xml looks like this:
<field name="xx_week_name" domain="[('id', 'in', xx_event_id.xx_weeks.name)]"/>
Yet it gives an error:
Uncaught Error: AttributeError: object has no attribute 'xx_weeks'
The domain is implemented in the javascript side and over there you cannot use Odoo's smart records (the 'dot' notation).
What you can do if you want to set a domain using a relational field is the following:
1) Declare a related field that will "pull" the name as a string from your relational field
week_name = fields.Char(related='xx_event_id.xx_weeks.name')
2) Insert that field in your view as invisible. In that way it will not change our view and we can still have access to it.
3) Change the filter in your relational field
That should work, but there is a chance that you have made a logical error in your domain. You check for [('id', 'in', xx_event_id.xx_weeks.name)] possibly you want something different there such as [('id', 'in', xx_event_id.xx_weeks.name)] If so modify the example above accordingly.

HP Quality Center field names

I am interacting with HP QC using python and referring to HP ALM OTA documentation.
What I need is to access fields in different places (particularly now I am trying to access Test Set description field). As far as I know it is done by following: TestSet['description field name'] = 'I am description' The problem is - I don't know this field name and I can't find it in documentation mentioned.Up until now I was wondering around examples in hope to find these names (the way I found that Actual field in test step is named 'ST_ACTUAL').
Could you please help me find some kind of list of these field names. Or the way to retrieve them.. (Or at least give me the name of this Test Set description field)
When you get an entity field value, the field must be the underlying database column name for that entity. You can discover this using the project customization UI in HP ALM: select project entities then explore the system or user fields. Beware that the Design Step says the column name begins ST_... it doesn't. It's actually DS_...
You can also get this information programmatically. Given a factory instance use the equivalent of:
private void ExploreFactoryFieldDefinitions(IBaseFactory factory)
{
List fields = factory.Fields;
foreach (TDField field in fields)
{
FieldProperty field_property = (FieldProperty)field.Property;
if (field_property.IsRequired)
{
Log(String.Format("User Label: {0}\n", field_property.UserLabel));
Log(String.Format("User Column Type: {0}\n", field_property.UserColumnType));
Log(String.Format("DB Column Name: {0}\n", field_property.DBColumnName));
Log(String.Format("DB Column Type: {0}\n", field_property.DBColumnType));
Log(String.Format("DB Table Name: {0}\n", field_property.DBTableName));
}
}
}
field_property.UserLabel gives you the user friendly field name. field_property.DBColumn name gives you the database column name that should be used with entity[field_name].
BTW - don't forget to call entity.Post() to have your changes saved. When working with a versioned project you have a few more hoops to jump through too. Good luck!
I think, the field you are looking for is CY_COMMENT (hint). Maybe there is a better way—but you can find the names of the fields in the Query Builder. If you create an Excel Report and open the Query Builder, there is an Entities View which shows all the fields of the tables (even the user-defined fields). Maybe there is some kind of database documentation which gives you the same thing.

unique python/django issue with variable column/field name in form

I have quite unique problem with django.
Im providing website users interface for editing large data. Each row on this data represents a row in database. Or one object of certain Type.
Users click on cells in the table and form opens where they can edit this fields/column value.
In essence it works like this:
1) based on where user clicks, query is sent to server containting object id and the field that he is editing.
2) based on this information form is created on the fly:
class FieldEditorForm(forms.ModelForm):
class Meta:
model = MyObject
fields = ['id', field ]
Notice the field there is Variable not name of the field.
3) this field passes its own modelform validation and all is fine. in save method Model.save() is enough to update the value.
But now to the problem. Sometimes empty value is sent to server in this form. Empy value such as u'' or almost emtpty like u' '. I want to repace this with None so NULL would be saved to database.
There are two places where i could do that. In field validation modifying the cleaned_data or in form save method.
Both approaches raise unique problem as i dont know how to create variable function names.
def clean_%(field)s():
or in case of form save method
r.%(field)s = None
is what i need, but those methods dont work. So how can i create method name which is variable or set objects variable parameter to something. Is it even possible or do i have to rethink my approach there?
Alan
In the latter case, setattr(r, field + 's', None).

Categories