JIRA Python Setting Cascading Select Values - python

I am using the jira-python library to create an issue in JIRA. However I cannot get the syntax right for setting Cascading Select values. The code below creates an issue and works for the first(parent) select in the cascading select but not the second (child). Can anyone tell me what I'm missing?
from jira import JIRA
jira = JIRA(options,basic_auth=('auth_email','auth_pw'))
issue_dict = {
'project': {'key': 'AT'}, #key for project
'summary': 'Summary Message',
'description': 'Not important',
'issuetype': {'name': 'Bug'},
'customfield_10207':{'value': 'test val2'}, #Updates first cascading select
'customfield_10207+1':{'value': 'test test2'}, #Fails
}
new_issue = jira.create_issue(fields=issue_dict)
(customfield_10207, customfield_10207+1 is the cascading select). Problem is with customfield_10207+1 which I expected to correspond to the second select list.

Looking at some atlassian forum docs you need to do the following:
{
"update" : {
"customfield_11272" : [{"set" : {"value" : "External Customer (Worst)","child": {"value":"Production"}}}]
}
}
Apparently the + and : syntax doesn't work :(
Update:
Adding the actual solution:
issue_dict = { 'project': {'key': 'AT'}, 'customfield_10207 : {"value" : "test val2","child": {"value":"test test2"}}, }

Related

Google AdWords API - AdGroupAdError CANNOT_CREATE_DEPRECATED_ADS

I'm using Google AdWords Python SDK to create ResponsiveDisplayAds. My code is like below.
adgroup_ad_service = adwords_client.GetService(
service_name = "AdGroupAdService",
version = "v201809"
)
operations = [{
'operator': 'ADD',
'operand': {
'xsi_type': 'AdGroupAd',
'adGroupId': '<AD_GROUP_ID>',
'ad': {
'xsi_type': 'ResponsiveDisplayAd',
'marketingImage': {
'mediaId': '<MEDIA_ID>'
},
'shortHeadline': 'Short Headline',
'longHeadline': 'This is a very long headline',
'description': 'This is a description',
'businessName': 'Test Business Name',
'finalUrls': ['https://www.google.com'],
'squareMarketingImage': {
'mediaId': '<MEDIA_ID>'
}
},
'status': 'PAUSED'
}
}]
ads_response = adgroup_ad_service.mutate(operations)
print("AD RESPONSE : {}".format(ads_response))
But It's giving me, AdGroupAdError.CANNOT_CREATE_DEPRECATED_ADS.
According to the documentation it describe this error as An ad of this type is deprecated and cannot be created. Only deletions are permitted..
But in documentation of the AdGroupAd ResponsiveDisplayAd, is one of the accepted Ad types.
So it would be great if someone can point me a direction to resolve this issue.
Use AddMultiAssetResponsiveDisplayAd instead.
Same result in a different way.
Hope you can make it like i did.

Getting snapshot cost based on tags

I am trying to use the cost explorer API using boto3. I am trying to get cost for EC2 snapshots. These snapshots have custom tags associated with them. What I am trying to retrieve is the cost of snapshots which have a particular tag.
I have written the following script:
import boto3
client = boto3.client('ce')
response = client.get_cost_and_usage(
TimePeriod={
'Start': '2019-01-20',
'End': '2019-01-24'
},
Metrics=['BLENDED_COST','USAGE_QUANTITY','UNBLENDED_COST'],
Granularity='MONTHLY',
Filter={
'Dimensions': {
'Key':'USAGE_TYPE_GROUP',
'Values': ['EC2: EBS - Snapshots']
}
}
)
This gives me the cost. But this is the total cost for the snapshot usage, i.e. for all the volumes. Is there any way to filter based on tags on the snapshot?
I tries adding the fallowing Filter:
Filter={
'And': [
{
'Dimensions': {
'Key':'USAGE_TYPE_GROUP',
'Values': ['EC2: EBS - Snapshots']
}
},
{
'Tags':{
'Key': 'test',
'Values': ['aj']
}
}
]
}
There is 1 snapshot where I have added that tag. I checked the date range and the snapshot was created within that time range and is still available. I tried changing granularity to DAILY too.
But this always shows 0 cost.
To query the snapshots or even other services using tags, you need to activate them in the billing menu.
Refer the link to activate the tags you need to query:
https://console.aws.amazon.com/billing/home?region=us-east-1#/preferences/tags
NOTE: Only master accounts in an organization and single accounts that are not members of an organization have access to the Cost Allocation Tags.
I hope that helps!
'Tags' can be added in your filter as follows:
response = client.get_cost_and_usage(
TimePeriod={
'Start': '2019-01-10',
'End': '2019-01-15'
},
Metrics=['BLENDED_COST','USAGE_QUANTITY','UNBLENDED_COST'],
Granularity='MONTHLY',
Filter={
'Dimensions': {
'Key':'USAGE_TYPE',
'Values': ['APN1-EBS:SnapshotUsage']
},
'Tags': {
'Key': 'keyName',
'Values': [
'keyValue',
]
}
}
)
You can find the exact usage in the boto3 cost explorer API reference.
You could also group by tag keys like this:
Filter={
'Dimensions': {
'Key':'USAGE_TYPE',
'Values': ['APN1-EBS:SnapshotUsage']
}
},
GroupBy=[
{
'Type': 'DIMENSION'|'TAG',
'Key': 'string'
},
],
It won't filter out tags, but it will group the returned data by tag key. This will return ALL tag values matching the tag key, so it may be too broad, but you can use it to troubleshoot any additional problems.
I'd confirm that your tag values and keys all match up.

Python Eve - Query Embedded Data Relation

I have the following resource defined:
item = {
'wrapper': {
'type': 'dict',
'schema': {
'element': {
'type': 'objectid',
'data_relation': {
'resource': 'code',
'field': '_id',
'embeddable': True,
},
},
},
},
}
When I try to query using the objectid, I get empty list.
http://127.0.0.1:5000/item?where={"wrapper.element":"5834987589b0dc353b72c27d"}
5834987589b0dc353b72c27d is the valid _id for the element.
If I move the data relation out of the embedded document I can query it as expected
Is there anyway to do this with an embedded data relation?
I have just tested with eve==0.7.1 and it works as expected by filtering with ?where={"wrapper.element" : "<your_objectid>"}, as you said.
I had a problem where the _id was being stored as a string rather than an ObjectId(), this broke the query

Adding a Source to Librato Data When Sending through Segment

I am trying to figure out how to add a source to a metric in Librato when sending the information via Segment. I am using the python library and have tried creating a property for source (below) but it doesn't seem to be working properly.
Here's what I've got:
userID = '12345'
analytics.track(userID, 'event', {
'value': 1,
'integrations.Librato.source': userID
})
I've also tried 'source' and 'Librato.source' as properties, which were referenced in Segment's documentation. Any suggestions?
Similarly for ruby, using the segment gem you can specify a source like so:
require 'analytics-ruby'
segment_token = 'asdfasdf' # The secret write key for my project
Analytics.init({
secret: segment_token,
#Optional error handler
on_error: Proc.necd giw { |status, msg| print msg } })
Analytics.track(
user_id: 123,
writeKey: segment_token,
event: 'segment.librato',
properties: { value: 42 }, context: { source:'my.source.name' })
You can't set the source of the Librato metric in the properties when sending from Segment, you need to send it as part of the context meta data. Librato does not accept any properties other than 'value' so nothing else you send as a property will be recorded. To set the source using the python library, the code needs to be as follows:
userID = '12345'
analytics.track(userID, 'event', {
'value': 1
}, {
'Librato': {
'source': userID
}
})
If you are are using javascript, it would be:
analytics.track({
userId: '12345',
event: 'event'
properties: {
value: 1
},
context: {
'Librato': {
'source': userID
}
}
});

how to set value in relational field in openerp

I have written code to migrate data from sql server 2008 to PostGreSQL using OpenERPLib in Python for OpenERP. I want to set the value of "categ_id" column of type "Many2one" of "crm.opportunity2phonecall" object. Here below is my existing code.
scheduleCall = {
'name': 'test',
'action': ['schedule'],
'phone': "123456",
'user_id': 1,
"categ_id": 10,
'note': mail['body']
}
SCHEDULECALL_MODEL.create(scheduleCall)
SCHEDULECALL_MODEL = OECONN.get_model("crm.opportunity2phonecall")
In the above code i have set the hard-coded value "10" for "categ_id" field as per my requirement. When i execute above code, it gives me an error -
TypeError: unhashable type: 'list'
Try assigning a list instead of an integer as follows:
categ_id: [10]
anyway, as Atul said in his comment, update OpenERP with xmlrpc, it is safe and stable, and suppports different versions of OpenERP
Okay, I got the solution.
What i had done is - define one method in python which returns categ_id and set its value in "scheduleCall" dict and surprisingly its work. Here is my code.
scheduleCall = {
'name': 'test',
'action': ['schedule'],
'phone': "123456",
'user_id': 1,
"categ_id": get_categid_by_name('Outbound'),
'note': mail['body']
}
SCHEDULECALL_MODEL.create(scheduleCall)
SCHEDULECALL_MODEL = OECONN.get_model("crm.opportunity2phonecall")
And here is the method that i had define.
def get_categid_by_name(name):
"""return category id"""
categ_id = False
ids = CATEG_MODEL.search([('name', '=', name)])
categ_id = ids[0]
return categ_id
CATEG_MODEL = OECONN.get_model("crm.case.categ")
Hope it'll help to others.

Categories