Regex code for email address, and how to link it with my feedback form - rasa-nlu

I want to link my feedback form's email address and Regex to validate the email address entered by an customer

What you probably need is a validate method. Inside your FormAction class you can define a validate_{slot_name} method which will be automatically called after the slot is successfully extracted using your defined slot mappings.
Assuming your email slot is called email your validate method name should be validate_email and would look like this:
def validate_email(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate email value."""
# Your regex validation logic...
Check this link to check an example of what you should return inside a validate_{slot_name} method.

Related

How can I receive the submitted data in a contact form into my own private email

I have called in Laravel's Mail inside my Controller like this:
\Mail::to($candidate)->send(new EmailVerification($candidate));
return view('/formsubmit');
The data received in the form are name, email, job_title, dob and interests. Is there a way I can receive the information entered by the user inside another email address?
According to the docs, you can add cc and bcc.
Mail::to($candidate)
->cc($moreUsers)
->bcc($evenMoreUsers)
->send(new EmailVerification($candidate));

How to save Foreign Key values in DJANGO REST?

Let's say i have models like follow.
class Department(models.Model):
name = models.CharField(max_length=255)
class Student(models.Model):
department = models.Foreignkey(Department, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
Now i need to set Department(which is created already) of the Student whenever i create the student instance.
which is best practice
i) Sending the department id in URI like `departments/{pk}/students`
ii) sending department id in body parameter
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
in this case, It'd be better to send department id in the body and keep the endpoint simple as
{base}/api/student/
make an HTTP POST to this endpoint
{
"department_id":"",
.
.
}
by taking a look at this endpoint this clearly shows endpoint for operations involving student object, I'd say it's more close to REST standards.

Grails command object validation with Ajax

In a Grails project I have a command object to validate submitted forms. This command obj. also has custom validators. The data is submitted with jQuery ajax ($.post).
My question is how can I now map the data send with jQuery Ajax to the properties listed in the Command object?
For example:
$.post('comment/save', {id: id, title: title});
and then in the controller:
def save(saveCommand cmd){
if (!cmd.validate()){
...
}
}
class saveCommand {
Comment comment_id // maps to: params.comment_id send with ajax
String title // maps to: params.title send with ajax
// constraints
// validators
}
The comment_id attribute should be bound from a "comment_id" parameter in the parameter map you sent from jQuery, not as "id" as you have right now.
Anyway, I guess you have a Comment domain class, and you expect to bind this entity from database. In this case, you should add a ".id" suffix to your parameter name.
$.post('comment/save', {"comment_id.id": id, "title": title});
PS: maybe you want to rename the "comment_id" to "comment" in your command class. Doing that, you will have to change the parameter name in your ajax request as "comment.id".

Auto-populate fields in email form in Dynamics CRM 2011

Imagine, you want to add an email to a case. The email form opens and the "To" field is auto-populated with the case's customer account.
I want to change the behavior in order to auto-populate the content of "To" with a custom property of the related case.
My first approach was to register a JavaScript for the OnLoad event of the form and let the script change the field. That would work, but I am wondering if there is a smarter way to achieve this. There is already some logic, which fills the "To" field. Is it possible to configure this existing feature?
Any hints are appreciated.
I do not believe that this specific scenario can be done more effectively than how you've already worked it out. I would've suggested looking at the data mappings (left-nav item when you pop open the relationship in the entity's customizations, same concept as discussed in this Dynamics CRM 4.0 article http://www.dynamicscare.com/blog/index.php/modifying-mapping-behavior-between-parent-child-records-in-microsoft-dynamics-crm/), but it does not appear to be applicable to this relationship.
This might help you:
DataService.EntityReference toEntityRef = new DataService.EntityReference();
toEntityRef.LogicalName = "contact";
toEntityRef.Id = Guid.Parse(to_id);
Entity toParty = new Entity();
toParty["partyid"] = toEntityRef;
toParty.LogicalName = "activityparty";
Entity emailEntity = new Entity();
emailEntity.LogicalName = "email";
EntityCollection toCollection = new EntityCollection();
toCollection.Entities = new ObservableCollection<Entity>();
toCollection.Entities.Add(toParty);
emailEntity["to"] = toCollection;
IOrganizationService soapService = ServerUtility.GetSoapService();
IAsyncResult res = soapService.BeginCreate(emailEntity, OnCreateComplete, soapService);
Call Back method:
private void OnCreateComplete(IAsyncResult result)
{
Guid emailId = (IOrganizationService)result.AsyncState).EndCreate(result);
}
Another approach would be to replace the Add Email buttons in the ribbon in order to call a custom JavaScript function. This function could open the mail window with window.open and initialize the To: field by setting the extraqs parameter to configure an ActivityParty for the email about to create. This can be done by setting:
partyid to the id of an allowed entity's instance
partyname to the name of the entity instance
partytype to 2 (for the recipent field, see here for details)
But the extraqs parameter is limited: You can set only one receiver and no other field (from, cc, bcc, ...). Moreover, replacing the buttons would bypass built-in functionality, which may change in future versions,
So I prefer the handling of the OnLoad event of the form.

Initializing a django modelform with data from url

I have two models for store and city:
class City(models.Model):
name = models.CharField()
slug = models.SlugField()
class Store(models.Model):
name = models.CharField()
slug = models.SlugField()
city = models.ForeignKey(City)
If I have my Add Store url designed as
r^'mysite.com/city/(?[-\w]+)/venue/add$'
where the represents the City.slug field can I initialize a StoreForm that automatically populates the Store.city field from the url data?
In your template, define your link as follows.
{%url somename relevant_slug_text%}
Or :
href='/mysite.com/city/{{slug_text}}/venue/add'
In your url conf, define your url like:
url(r^'mysite.com/city/(?P<slug_text>\w+)/venue/add$', 'func_name', name='somename')
So, you can pass the value of relelvant_slug_text variable to your url as slug_text, and in your function definiton:
def func_name(request, slug_text):
So , you can pass text value to your funcrtion with slug_text parameter...
EDIT:
There are tow ways...
One:
Crete your city selection form using ModelForm..., then inthe second step, use posted data to populate your form again like:
form = StoreForm(request.POST)
then you can render this form to your template...
But if it is not possible o use this, yo ucan do the following...
Since you are using ModelForm to create your forms:
class StoreForm(forms.ModelForm):
# your form field definitions are here
im your function, just override city field, but at this point, since you use modelform, your form thml will be created as
<select>
<option value="id of record">"unicode value of record"</option>
So, you have record id's as option values. And you have slug_field values to initialize your field. So you have to get related city to use it...
my_city = City.objects.get(slug=<your_slug_value>)
Now you can override the form, but you must do it before you pass your form to a variable to render to your template...
StoreForm.base_fields['city'] = forms.ModelChoiceField(queryset=City.objects.all(), initial=my_city)
form = StoreForm()

Resources