Docusign API Ruby: How to set predefined Custom Fields for an Envelope creation? - ruby-on-rails

I created some enveloppe custom fields in the admin of Docusign.
So I'd to know how to set their value when I create an enveloppe from the docusign Ruby API.
I've tried to set there like this, but it doesn't work. When I send the envelope the custom fields are not filled.
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
custom_fields = DocuSign_eSign::CustomFieldsEnvelope.new(
{"name":"enveloppe_annee","value":"2019"}
)
envelope_definition.custom_fields = [custom_fields]

The envelope_definition.custom_fields attribute takes a single instance of custom_fields. (Not an array)
custom_fields is an object that has two attributes:
list_custom_fields wants an array of ListCustomField
text_custom_fields wants an array of TextCustomField
Based on the above, can you redo your request?

envelope_definition = DocuSign_eSign::EnvelopeDefinition.new({status: 'sent', templateId:'a19dXXXX-XXXX-4ce7-XXXX-56cXXXX83364', emailSubject: 'Example Document Signing'})
signer = DocuSign_eSign::TemplateRole.new({email: 'email#eample.com', name: 'Johny Walker', roleName: 'signer'})
text = DocuSign_eSign::Text.new
text.tab_label = 'label_id of the custom field'
text.value = 'value for the custom field'
tabs = DocuSign_eSign::Tabs.new
tabs.text_tabs = [text]
signer.tabs = tabs
envelope_definition.template_roles = [signer]
This should work for you

Related

slim4 use response mutiple times

I created a slim4 action to send more than one email.
The two emails get their output from views and sends two separate emails.
The first email is sent ok, But the second one is sent with the body of the first (The recipient and subject is correct.)
I have excluded the email library by debuging and tracing the values being received. I can confirm the same response body is being set,
I tried making a copy of $response. That did not change things.
The code below is a summary
public function actionContact(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
$form_data = (array)$request->getParsedBody();
$notify_view_ = $this->renderer->render(
$response,
'emails/contactus_notify.php',
['form_data' => $form_data]
);
$notify_message = $response->getBody();
$notify_mail = new Email('user1#domain.com, 'Subject 1', $notify_message)->send();
// Send second email
$thankyou_view_ = $this->renderer->render(
$response,
'emails/contactus_thankyou.php',
['form_data' => $form_data]
);
$thankyou_message = $response->getBody();
$thankyou_mail = new Email('user2#domain.com, 'Subject 2', $thankyou_message)->send();
}
I figured after further debugging that the second getBody() was actually concatenating the results of the two render()s.
I tried resetting the body
$response->getBody()->write('');
but this had no effect. The second email is the concatenation of the two writes by render.
The issues was fixed by using the fetch() method, which renders the template and returns the result instead of writing it to the response. (Unfortunate name for the method, I think.)
Replace
$notify_view_ = $this->renderer->render(
$response,
'emails/contactus_notify.php',
['form_data' => $form_data]
);
$notify_message = $response->getBody();
by
$notify_message = $this->renderer->fetch(
'emails/contactus_notify.php',
['form_data' => $form_data]
);

How to display list_filter with count of related objects in django admin?

How can I display the count of related objects after each filter in list_filter in django admin?
class Application(TimeStampModel):
name = models.CharField(verbose_name='CI Name', max_length=100, unique=True)
description = models.TextField(blank=True, help_text="Business application")
class Server(TimeStampModel):
name = models.CharField(max_length=100, verbose_name='Server Name', unique=True)
company = models.CharField(max_length=3, choices=constants.COMPANIES.items())
online = models.BooleanField(default=True, blank=True, verbose_name='OnLine')
application_members = models.ManyToManyField('Application',through='Rolemembership',
through_fields = ('server', 'application'),
)
class Rolemembership(TimeStampModel):
server = models.ForeignKey(Server, on_delete = models.CASCADE)
application = models.ForeignKey(Application, on_delete = models.CASCADE)
name = models.CharField(verbose_name='Server Role', max_length=50, choices=constants.SERVER_ROLE.items())
roleversion = models.CharField(max_length=100, verbose_name='Version', blank=True)
Admin.py
#admin.register(Server)
class ServerAdmin(admin.ModelAdmin):
save_on_top = True
list_per_page = 30
list_max_show_all = 500
inlines = [ServerInLine]
list_filter = (
'region',
'rolemembership__name',
'online',
'company',
'location',
'updated_on',
)
i.e After each filter in list filter, I want to show the count of related objects.
Now it only shows the list of filter
i.e location filter list
Toronto
NY
Chicago
I want the filter to show the count like below:
Toronto(5)
NY(3)
Chicago(2)
And if the filter has 0 related objects, don't display the filter.
This is possible with a custom list filter by combining two ideas.
One: the lookups method lets you control the value used in the query string and the text displayed as filter text.
Two: you can inspect the data set when you build the list of filters. The docs at https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter shows examples for a start decade list filter (always shows «80s» and «90s») and a dynamic filter (shows «80s» if there are matching records, same for «90s»).
Also as a convenience, the ModelAdmin object is passed to the lookups
method, for example if you want to base the lookups on the available
data
This is a filter I wrote to filter data by language:
class BaseLanguageFilter(admin.SimpleListFilter):
title = _('language')
parameter_name = 'lang'
def lookups(self, request, model_admin):
# Inspect the existing data to return e.g. ('fr', 'français (11)')
# Note: the values and count are computed from the full data set,
# ignoring currently applied filters.
qs = model_admin.get_queryset(request)
for lang, name in settings.LANGUAGES:
count = qs.filter(language=lang).count()
if count:
yield (lang, f'{name} ({count})')
def queryset(self, request, queryset):
# Apply the filter selected, if any
lang = self.value()
if lang:
return queryset.filter(language=lang)
You can start from that and adapt it for your cities by replacing the part with settings.LANGUAGES with a queryset aggregation + values_list that will return the distinct values and counts for cities.
Éric's code got me 80% of what I needed. To address the comment he left in his code (about ignoring currently applied filters), I ended up using the following for my use case:
from django.db.models import Count
class CountAnnotatedFeedFilter(admin.SimpleListFilter):
title = 'feed'
parameter_name = 'feed'
def lookups(self, request, model_admin):
qs = model_admin.get_queryset(request).filter(**request.GET.dict())
for pk, name, count in qs.values_list('feed__feed_id', 'feed__feed_name').annotate(total=Count('feed')).order_by('-total'):
if count:
yield pk, f'{name} ({count})'
def queryset(self, request, queryset):
feed_id = self.value()
if feed_id:
return queryset.filter(feed_id=feed_id)
And then, in the admin model:
class FeedEntryAdmin(admin.ModelAdmin):
list_filter = (CountAnnotatedFeedFilter,)
Note: As Éric also mentioned, this can impact the speed of the admin panel quite heavily, as it may have to perform expensive queries.

Django Admin shows "(nothing)"

I want to show in the app/model admin the columns of the model but with some customization. These 3 'tar', 'per_hor','per_tar' have choices in their modelfield.
First I wrote this code:
class ValoresAdmin(admin.ModelAdmin):
list_display = ('fecha', 'tar', 'per_hor','per_tar')
list_filter = ('fecha','tar','per_tar','per_hor')
date_hierarchy = 'fecha'
fieldsets = (
(None, {
'fields': ('fecha',('tar', 'per_hor', 'per_tar'))
}),
(None, {
'fields': ('feu', 'coef_perf','sah', 'pmh','carg_cap')
}),
)
I shows the verbose name of the column but the values is always "(nothing)" on the filter page but if I enter the change form they display correctly their value (their choide).
I read some and decided to create methods like these ones and call them in the list_display:
def get_tar(Self):
return self.get_tar_display()
def get_per_hor(Self):
return self.get_per_hor_display()
def get_per_tar(Self):
return self.get_per_tar_display()
get_tar_display.short_description = 'Tarifa'
get_per_hor_display.short_description = 'Periodo horario'
get_per_tar_display.short_description = 'Periodo tarifario'
Now the filter page will display columns named as the short description BUT with the real value of the field instead of theirs "choice value".
Addiotionally if I mark 'per_tar' as non editable it will show also "(nothing)" in the change from instead of it´s stored value.
What am I doing wrong?
Diving in internet I found the answer here:
http://thinkingnectar.com/2009/django-get_foo_display-behaviour-with-characters-and-integer-fields/
The post comment that when the field is char type, the choice key should be a string but when it´s an integer field it should be an interger!
Here was my problem! Changing strings to integer made it work.

SOAPpy - create a Jira issue and define a component?

I can't figure how to create a jira issue and define its component with SOAPpy:
client = so.WSDL.Proxy(cfg_wsld)
auth_token = client.login(cfg_username, cfg_password)
issue_params = dict()
issue_params['project'] = project
issue_params['type'] = issue_type
issue_params['summary'] = summary
issue_params['description'] = summary
newissue = client.createIssue(auth_token, issue_params)
This sample works fine but I try to add components to it Jira will return missmatchTypeException.
I've tried all kinds of variants: passing arrays, strings, ints into it but it won't pick any of them up.
Most attempts (passing string, int, array of both) will cause TypeMissmatch, this causes NullPointerException inside Jira:
issue_params['components'] = {u'Разное': {'id': '11143', 'name': u'Разное'}}
I know the exact id of the issue type I want to use but how do I pass it properly? When I retrieve an issue with this type components returns as SOAPpy.Types.typedArrayType() but this still fails:
issue_params['components'] = so.Types.typedArrayType(data={'id': '11143', 'name': u'Разное'})
newissue = client.createIssue(auth_token, issue_params)
(<class 'SOAPpy.Errors.Error'>, <Error : Data must be a sequence>, None)
issue_params['components'] = so.Types.typedArrayType(data=[{'id': '11143', 'name': u'Разное'},])
This did the trick - data needs to be an array.

Update custom cascading select field in JIRA via suds

Using JIRA version 4.2. With Python 2.7 and suds 0.4, how can I update an issue's custom cascading select's field (both parent and child)?
There is a SOAPpy example available under "Python (SOAPPy) client".
I was unable to perform this type of update using the Python JIRA CLI.
Example:
When updating the cascading select custom child of parent field, customfield_10, one would want to update the field customfield_10_1.
Update
Code to display cascading field's original value:
issue = client.service.getIssue(auth, "NAHLP-33515")
for f in fields:
if f['customfieldId'] == 'customfield_10050' or f['customfieldId'] == 'customfield_10050_1':
print f
This results in:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
After manually setting the cascading field's child, the above code results in:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = "1"
values[] =
"11560",
}
The above values is what I hope to achieve via suds.
Note the key = "1" field. The key value designates that this object is the child of customfield_10050.
Documentation reference:
parentKey - Used for multi-dimensional custom fields such as Cascading select lists. Null in other cases
Let's try sending a key field value:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050_1", "key":"1", "values":["11560"]}
])
This results in an error because the updateIssue accepts a RemoteFieldValue[] parameter, not a RemoteCustomFieldValue[] parameter (thanks Matt Doar):
suds.TypeNotFound: Type not found: 'key'
So how do we pass a RemoteCustomFieldValue parameter to update an issue?
Update 2, mdoar's answer
Ran following code via suds:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050_1", "values":["11560"]}
])`
After value:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
Unfortunately, this does not update the child of customfield_10050. Verified manually.
Resolution:
Thank you mdoar! To update a parent and child of a cascading select field, use the colon (':') to designate the child filed.
Working example:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050:1", "values":["11560"]}
])

Resources