Conf/Messages Choice in Play! + Scala - html

I run the sample code in play 2.2 "comuputer-database-jpa"
In the Conf/Messages
# Messages
computers.list.title={0,choice,0#No computers|1#One computer|1<{0,number,integer} computers} found
I want to used this conditional messages in my error messages to make my error message as dynamic as possible. In my code say that i'm passing 2 parameters and 1 of it is the message id.
#Messages(messageId,errors(1).getOrElse(""),errors(2).getOrElse(""))
equivalent to
#Messages(error.format,FIRST NAME)
can also be
#Messages(error.format,EMAIL)
How can i use the conditional conf/messages in my code? I tried some using the sample and an error occurred.
Code:
error.format = Enter {0,choice,FIRST NAME#{0} in half-width alphanumeric|EMAIL#{0} in valid format.}
What am i doing wrong?

The below code will yield what you are looking for
//html<br/>
#Messages("error.format",2, "name error","email error")
Number 2 in the example above will show the message "EMAIL in valid format". if you change it to 1 it will show the message "FIRST NAME in half-width alphanumeric"
//messages<br/>
error.format = Enter {0,choice,1#FIRST NAME in half-width alphanumeric|2#EMAIL in valid format.}

Related

discord.js : how do I pick up a random item from a json file?

I'm coding a discord bot. I want to it to pick up in a json file a random item from a list. That's my json file :
{
"emailPass": ["email1:pass1", "email2:pass2"],
"capture": "capture1"
}
Now I want it to send a private message to the author, with the "capture" item, and one of the "emailPass" items, randomly chosen. So that's my js code :
message.author.send(Math.floor(jsonFile.emailPass.lenght*Math.random()) + "\n" + jsonFile.capture);
The bot sends the message, but instead of the "emailPass" item, it displays "NaN".
Does someone know how to fix that ? I think the error is from the random command, but I don't know exactly why...
Use Math.floor(jsonFile["emailPass"].length * Math.random()).
But this will only output a random number between 0 and the number of values in your emailPass array - 1. Use this if you want to return a random element from there:
message.author.send(jsonFile.emailPass[Math.floor(jsonFile["emailPass"].length * Math.random())] + "\n" + jsonFile.capture);

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U57') dtype('<U57') dtype('<U57')

I am using great-expectation for pipeline testing.
I have One Dataframe batch of type :-
great_expectations.dataset.pandas_dataset.PandasDataset
I want to build dynamic validation expression.
i.e
batch.("columnname","value") in which
validationtype columname and value coming from json file .
JSON structure:-
{
"column_name": "sex",
"validation_type": "expect_column_values_to_be_in_set",
"validation_value": ["MALE","FEMALE"]
},
when i am building this expression getting error message described below .
Code:-
def add_validation(self,batch,validation_list):
for d in validation_list:
expression = "." + d["validation_type"] + "(" + d["column_name"] + "," +
str(d["validation_value"]) + ")"
print(expression)
batch+expression
batch.save_expectation_suite(discard_failed_expectations=False)
return batch
Output:-
print statement output
.expect_column_values_to_be_in_set(sex,['MALE','FEMALE'])
Error:-
TypeError: ufunc 'add' did not contain a loop with signature matching
types dtype('
In great_expectations, the expectation_suite object is designed to capture all of the information necessary to evaluate an expectation. So, in your case, the most natural thing to do would be to translate the source json file you have into the great_expectations expectation suite format.
The best way to do that will depend on where you're getting the original JSON structure from -- you'd ideally want to do the translation as early as possible (maybe even before creating that source JSON?) and keep the expectations in the GE format.
For example, if all of the expectations you have are of the type expect_column_values_to_be_in_set, you could do a direct translation:
expectations = []
for d in validation_list:
expectation_config = {
"expectation_type": d["validation_type"],
"kwargs": {
"column": d["column_name"],
"value_set": d["validation_value"]
}
}
expectation_suite = {
"expectation_suite_name": "my_suite",
"expectations": expectations
}
On the other hand, if you are working with a variety of different expectations, you would also need to make sure that the validation_value in your JSON gets mapped to the right kwargs for the expectation (for example, if you expect_column_values_to_be_between then you actually need to provide min_value and/or max_value).

How to return number and newline with JSON

I want to return a number and a new line
{ data : "3
"}
But every time, I try to do this it is considered invalid
Update
My parser tool tries to do things with Newlines. Here is the complete screenshot:
** Update 2**
This is with jsonlint.com
The problem is that data is not a valid key (check https://www.json.org/ or Do the JSON keys have to be surrounded by quotes?), you need to use quotes for keys in order to have valid syntax. Also you need to add \n for a new line character:
{ "data": "3\n"}
I pasted this into the console without an error:
{ "data" : "3\n"}
Testing one step further:
a = { "data" : "3\n"}
a.data + "hello" // pasted into the console
produced this:
3
hello

active admin strong parameters failing

I am trying to create a record in active admin. My activeadmin is set up with this:
ActiveAdmin.register MyObject do
permit_params :all_my_params, :client_id
end
The form should be submitting the params as such:
{"utf8"=>"✓", "authenticity_token"=>"WnStZr//M1rBDSwNWSrZs2rvCmcpji/MKaLywxuf9oG0Ef3b1uojy5jszs3yHEYmpvjt+qtJrmi3jz3KKJgUCQ==", "MyObject"=>{"client_id"=>"1", "all_my_params"=>"something here"}, "commit"=>"Create My Object"}
However, the form submits with an extra client_id outside of the MyObject hash like so:
{"utf8"=>"✓", "authenticity_token"=>"WnStZr//M1rBDSwNWSrZs2rvCmcpji/MKaLywxuf9oG0Ef3b1uojy5jszs3yHEYmpvjt+qtJrmi3jz3KKJgUCQ==", "MyObject"=>{"client_id"=>"1", "all_my_params"=>"something here"}, "commit"=>"Create My Object", "client_id"=>"1"}
(notice the extra client_id)
This gives me an error:
unpermitted parameter: client_id
because it is not expected outside my MyObject hash.
How can I fix this? I've been stuck on this for days!
My relevant routes: batch_action_admin_client_wedding_cakes POST /admin/clients/:client_id/wedding_cakes/batch_action(.:format) admin/wedding_cakes#batch_action
admin_client_wedding_cakes GET /admin/clients/:client_id/wedding_cakes(.:format) admin/wedding_cakes#index
POST /admin/clients/:client_id/wedding_cakes(.:format) admin/wedding_cakes#create
new_admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/new(.:format) admin/wedding_cakes#new
edit_admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/:id/edit(.:format) admin/wedding_cakes#edit
admin_client_wedding_cake GET /admin/clients/:client_id/wedding_cakes/:id(.:format) admin/wedding_cakes#show
where wedding_cake = MyObject in my previous code.
In essence, the client_id that is parsed from the url automatically which would normally be accepted in a rails controller is not getting accepted in activeadmin and I have no way of making it permitted since I can only permit things that are inside the wedding cakes hash in my params.

reHow to send a set of string in single variable through url

I want to send a value in URL that value contains more than one words i am using the given concept for example
<a href=page.jsp?variable1=value1&variable2=value2>click here</a>
Suppose in above value value1=aa and value2=bb cc dd
but in the url of page.jsp i am getting value1=aa and value2=bb only and the rest value "cc dd" is missing.
what should i do to get complete value for example value2=bb cc dd
I am giving here my code after making it more simple to focus on desire problem
`<%
MongoClient mongo = new MongoClient("localhost",27017);
DB database = mongo.getDB("studentDB");
DBCollection collection = database.getCollection("AskQuestion");
DBCursor cursor = collection.find();
String bodycontent="";
while(cursor.hasNext())
{
DBObject str=cursor.next();
bodycontent+="<table><tr><td><div> "+ str.get("TITLE") +"</div></td></tr></table>";
}
out.print(bodycontent);
%>`
For example str.get("_id") gives value "55093da9223da86a0212b364" and
str.get("TITLE") gives value "Question Title" .
Now my problem is i got value in Answer.jsp for str.get("TITLE") is only "Question" but not "Title" and i want the full value i.e Question Title.
I hope i am clear with my problem.
Try encoding your second variable and then attach it.
example: bb%20cc%20dd
<a href=page.jsp?variable1=value1&variable2=bb%20cc%20dd>click here</a>
You need to use java script for encoding your URL see this question for more details.
Passing a URL as a GET parameter in Javascript
Edit
See these answers
How to URL encode a URL in JSP?
http://www.coderanch.com/t/521213/JSP/java/encoding-URL-href-element-JSP