Get index of a meta-tag in Contact Form 7 - contact-form-7

I use a meta-tag in Contact Form 7 to send email:
[select category "Billing" "Suggestion" "Problems"]
For email body I insert this shortcode:
Category: [category]
Then I get email which contains "Category: Billing", or "Category: Suggestion", or "Category: Problems".
Is it possible to use some shortcode in Contact Form 7 which returns an index number of a value in meta-tag - 1,2,3? A number instead of a word. For example, "Category: 1", or "Category: 2", "Category: 3".

Use pipes,
[select category "Billing|1" "Suggestion|2" "Problems|3"]

Related

Fake email generation using factory.LazyAttribute

I am trying to generate fake email ID's for the purpose of research. I employ LazyAttribute towards this end. I want the email ID to correspond to the first and the last names of the person (generated using Faker). The function I wrote is below.
I am unable to get the expected output. If the name of the person is John Snow, I see the following as the output:
John Snow <factory.declarations.LazyAttribute object at ......
Can I expect some help to fix my code? Thanks!
def faker_categorical(num=1, seed=None):
np.random.seed(seed)
fake.seed_instance(seed)
output = []
for x in range(num):
gender = np.random.choice(["M", "F"], p=[0.5, 0.5])
output.append(
{
"First name": fake.first_name(),
"Last name": fake.last_name(),
"E-mail": factory.LazyAttribute(lambda obj: "%s#example.com" % obj.first_name),
})
return output

Updating SendGrid contact custom fields via SendGrid API. Why isn't this working?

I'm trying to update my SendGrid contacts and can't figure out why my attempts to update my contacts' custom fields are not working. My reserved fields (first_name, last_name, email) update, but my custom fields do not. Any ideas why?
Documentation here: https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact
try:
headers = {
'authorization': f"Bearer {settings.SENDGRID_API_KEY}",
}
data = {
"list_ids": [
# "Users" list
"7c2...d20"
],
"contacts": [{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"custom_fields": {
"educator_role": user.educator_role,
}
}]
}
response = requests.put("https://api.sendgrid.com/v3/marketing/contacts", headers=headers, data=json.dumps(data))
if(response.status_code != 202):
capture_message(f"Could not add user with email {user.email} to Sendgrid.", level="error")
except:
capture_message(f"Adding/updating SendGrid contact failed for {user.email}.", level="error")```
Unlike reserved fields, updating a custom field requires you pass the custom field id instead of the field name in your call. So instead of educator_role, use the id, it will be something random like e1_T.
You can get the id via the /marketing/field_definitions endpoint.
As said by #Matt, to update a custom field value via SendGrid API, we need to refer to the custom field by its ID, not by the field name.
To get a list with your custom field IDs, do:
from sendgrid import SendGridAPIClient
SENDGRID_API_KEY="print-your-key-here"
sg = SendGridAPIClient(SENDGRID_API_KEY)
response = sg.client.marketing.field_definitions.get()
print(response.body)
Also, take a look at the docs: https://docs.sendgrid.com/api-reference/custom-fields/get-all-field-definitions.
The custom field ID has logic
For custom fields, the unique ID always starts with the suffix e. Followed by an integer number that represents the creation order of the custom fields on the SendGrid platform, p.e. 1, 2, 3. Followed by underscore _. Followed by a letter that represents the custom field type:
N - Number
T - Text
D - Date
Here is an example of a custom field ID list:
{
"custom_fields":[
{"id":"e1_N","name":"number_field_test","field_type":"Number"},
{"id":"e2_T","name":"text_field_test","field_type":"Text"},
{"id":"e3_D","name":"data_field_test","field_type":"Date"}
]
}

Material-UI <Autocomplete /> different label than option value

I have a Material-UI <Autocomplete /> component I am using where you can type in someone's name and it will provide a list of people to select from. This is a pretty standard use case, however I need the selected item in the form to be different than the label.
Currently if you pick the entry labelled "John Smith", the text field will be filled with "John Smith". Instead, I want to fill the text field with that user's ID.
The data for autocomplete is an array of objects like this:
{ "name": "John Smith", "id": 123456789 }
How can I make the autocomplete component put the user ID in the text field instead of the user label?
You can customize renderOption props in Material-UI Autocomplete
Render the option, use getOptionLabel by default.
Signature: function(option: T, state: object) => ReactNode
option: The option to render.
state: The state of the component.
As for the code
getOptionLabel={option => option.name}
renderOption={(option) => <span>{option.name}</span>}
Refer to the demo in an official document
If you just want to display name in Textfield, You could try this
getOptionLabel={option => option.id}
renderOption={option => <>{option.name}</>}
If you want to display name in TextField and OptionLabel but want to get id as value of TextField in order to store id after form submission.
You could try this
getOptionLabel={(option) => option.name}
renderOption={(option) => (
<>
{option.name} ({option.surname})
</>
)}
onChange={(event, newValue) => {
setValue(newValue);
setCustomValue(newValue.id);
}}
using onChange event you could select any field of the option you want to get as value.In this example I stored id of the option in the state.
Complete working example is here https://codesandbox.io/s/material-demo-forked-wlzr8?file=/demo.js:804-1084

Get text between two annotated tags in ruta

How to get data present between two annotated texts?
Sample input:
Seller Name FirstAvenue Mortgage, TN 12230 Contact Name John
Code :
BLOCK(sellerName) Line{CONTAINS(SellerNameKeyword)} {
c:ANY+{-PARTOF(SellerNameKeyword), -PARTOF(SellerName)->
CREATE(SellerName, "label"="Seller Name", "value"=c.ct)}
ContactNameKeyword;
}
This code is not giving any output for SellerName annotation
Expected Output : FirstAvenue Mortgage, TN 12230
What changes if input is spread across two lines ?
Sample input:
Seller Name FirstAvenue Mortgage, Contact Name John
TN 12230 Contact Title Supervisor
Code for above mentioned use case:
TYPESYSTEM utils.PlainTextTypeSystem;
ENGINE utils.PlainTextAnnotator;
DECLARE Keyword (STRING label);
DECLARE Entry(Keyword keyword);
DECLARE Keyword SellerNameKeyword, SellerNameContextBlocker, ContactNameKeyword;
EXEC(PlainTextAnnotator, {Line,Paragraph});
ADDRETAINTYPE(WS);
Line{->TRIM(WS)};
Paragraph{->TRIM(WS)};
REMOVERETAINTYPE(WS);
"Seller Name" -> SellerNameKeyword ( "label" = "Seller Name");
"Contact Title" -> SellerNameContextBlocker("label" = "Seller Name Context Blocker");
"Contact Name" -> ContactNameKeyword("label"= "Contact Name");
DECLARE Entity (STRING label, STRING value);
DECLARE Entity ContactName, SellerName;
BLOCK(line1) Line{CONTAINS(ContactNameKeyword)} {
ContactNameKeyword c:#{-PARTOF(ContactName)-> CREATE(ContactName,"label"="Contact Name", "value"=c.ct)};
}
SellerNameKeyword c:#{-PARTOF(ContactNameKeyword),-PARTOF(SellerNameContextBlocker),-PARTOF(ContactName) ->
CREATE(SellerName,"label"="Seller Name", "value"=c.ct)} SellerNameContextBlocker;
Output : FirstAvenue Mortgage, Contact Name John TN 12230
Expected Output : FirstAvenue Mortgage, TN 12230
Please suggest required changes and what I have missed ?
Since the information you want to annotate is not sequential in text ("Contact Name John" comes in between) you cannot represent the desired output in CAS as the covered text of a single annotation.
However, in your case, you might want to join together the text of interest in a feature of the output annotation. For example:
DECLARE SellerNameKeyword, ContactNameKeyword, ContactTitleKeyword;
DECLARE SellerName (STRING value);
"Seller Name" -> SellerNameKeyword;
"Contact Name" -> ContactNameKeyword;
"Contact Title" -> ContactTitleKeyword;
ADDRETAINTYPE(BREAK);
SellerNameKeyword ANY[0,5]{-PARTOF(ContactNameKeyword), -PARTOF(COMMA) ->
s1:CREATE(SellerName)} COMMA?
ContactNameKeyword ANY[0,5]{-PARTOF(BREAK)} BREAK? ANY[0,10]{-PARTOF(ContactTitleKeyword) ->
s2:CREATE(NameId), s1.value=""+s1.ct+s2.ct} ContactTitleKeyword;
ADDRETAINTYPE(BREAK);
The output of this rules will return an annotation SellerName on "FirstAvenue Mortgage" with feature value containing the desired output "FirstAvenue Mortgage TN 12230".
Mind that this is not a general solution but rather an example how it can be done in the give case.

Make a value appear first in drop down others after

I have a collection of Industries that I am displaying in a drop down using this code:
<%= ff.select :area_of_business_id, Industry.all.map { |x| [x.name, x.id] }, {include_blank: "Select an industry"}, class: 'droplist default-droplist required' %>
I would like one of the specific Industries from the list to appear first in the dropdown and the rest to appear after that in alphabetical order. For example, if I have this list:
Airlines
Broadcasting
Chemicals
Entertainment
Insurance
And, I would like Entertainment to appear first, then I want the order to be changed to this:
Entertainment
Airlines
Broadcasting
Chemicals
Insurance
What is the cleanest way to do this?
Yes possible as below. Say you have a instance variable inside the controller:
#option_values = Industry.order("name <> 'Entertainment', name asc")
.pluck(:name, :id)
Now do,
<%= ff.select :area_of_business_id, #option_values, {include_blank: "Select an industry"}, class: 'droplist default-droplist required' %>
That part order("name <> 'Entertainment', name asc") will put the record with name = 'Entertainment' first, then the rest in decreasing order.
Rails support priority of options out of the box for time_zones only. In all other cases you should do it manually use something like this:
<% industries = [Industry.find_by(name: 'Entertainment')] + [Industry.where.not(name: 'Entertainment')] %>
<%= ff.select :area_of_business_id, industries.map { |x| [x.name, x.id] }, {include_blank: "Select an industry"}, class: 'droplist default-droplist required' %>
but I recommend to add additional filed to Industry model for specify position in lists and sort by this filed.