SelectField renders unicode syntax - forms

When dynamically creating choices for SelectField in WTForms, I get (u'Choice',) rendered in the dropdown list.
I suspect its something to do with unicode, but no idea how to get the correct string.
for example
form.group_id_name.choices = [(row, row) for row in db.session.query(entry.group_id_name).distinct()]
In my forms I have
group_id_name = SelectField('group_id_name')
I would like it to render
<select id="group_id_name" name="group_id_name"><option value="Choice1">Choice1</option><option value="Choice2">Choice2</option></select>
Instead I get
<select id="group_id_name" name="group_id_name"><option value="(u'Choice1',)">(u'Choice1',)</option><option value="(u'Choice2',)">(u'Choice2',)</option></select>

It's not anything to do with Unicode.
query() returns a sequence of column values for each row. For a query with only one column in it you get a length-1-tuple.
When you implicitly convert a tuple to a string as part of the template you get the Python code representation of the tuple, which looks like (somevalue,).
You want to include the string value of the column itself in the template, so you should access the first element of the sequence, eg:
form.group_id_name.choices = [(row[0], row[0]) for row in db.session.query(entry.group_id_name).distinct()]
or using unpacking assignment:
form.group_id_name.choices = [(name, name) for (name,) in db.session.query(entry.group_id_name).distinct()]

Related

How Can I Verify Text Amount in Katalon

I'm trying to verify a text in Katalon and my script isn't working.
Here's my element:
<span id="overviewTabStoreCredit" class="h2 strong amountCredit text-danger">-$100.00</span>
Here's my script:
def StoreCreditAmount = '-$100.00'
TestObject StoreCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
WebUI.verifyElementAttributeValue(StoreCreditTO, 'text', StoreCreditAmount, GlobalVariable.G_Timeout_Tiny, FailureHandling.CONTINUE_ON_FAILURE)
When running the script, I get an error message, "Object does not have attribute 'text'"
I also tried this to character it by class instead of text:
def StoreCreditAmount = 'h2 strong amountCredit text-danger'
TestObject StoreCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
WebUI.verifyElementAttributeValue(StoreCreditTO, 'class', StoreCreditAmount, GlobalVariable.G_Timeout_Tiny, FailureHandling.CONTINUE_ON_FAILURE)
I got this error:
Has attribute 'class' with actual value 'text-success h2 strong amountCredit' instead of expected value 'h2 strong amountCredit text-danger' even though the value is correct.
'Text' might not be an attribute. You can getText() from the element and then compare with the expected result. Sometimes, the value you see might not from Text, but from the attribute 'value'.
When you look at your tag there is no "text" attribute:
<span id="overviewTabStoreCredit" class="h2 strong amountCredit text-danger">
Some elements (like text-boxes) have hidden "value" elements for input text, but that is not the case here.
I believe what you want to do is check that the text between your tags equals a certain amount, in this case: "-$100.00".
To check the text between your opening/closing tags for your element use
WebUI.getText(). So your code could grab the text between the tags of your element, and then do an assert (or do it in one step) to finish your validation. I'll show it in two for readability:
def testStoreCreditAmountText = '-$100.00'
TestObject storeCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
def actualStoreCreditAmountText = WebUI.getText(storeCreditTO)
WebUI.verifyMatch(testStoreCreditAmountText, actualStoreCreditAmountText, false)
I hope that helps!

One way data binding not working when using date pipe

I'm using a date object to keep track of the current date in an application.
In my view I have a one way binding like this:
<h3>{{ currentDate | date }}</h3>
And in the component, I have functions to change this date, like this:
previousMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() - 1);
}
nextMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() + 1);
}
But when these functions are triggered, the currentDate value doesn't update on the view.
I made sure the date object is being updated, just not on the view.
Whenever I remove the date pipe, it works.
Anyone has any idea how to fix this?
Thanks!
The value is not updating in the view because the pipes in angular are so called pure (or, stateless) by default. That means that the input will not be re-evaluated if the input object changes, but only if it's replaced.
From the documentation (see section Pure and Impure pipes):
Angular executes a pure pipe only when it detects a pure change to the
input value. A pure change is either a change to a primitive input
value (String, Number, Boolean, Symbol) or a changed object reference
(Date, Array, Function, Object).
Try the following code instead:
previousMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() - 1);
this.currentDate = new Date(this.currentDate);
}
nextMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() + 1);
this.currentDate = new Date(this.currentDate);
}

D3 invalid character in element

I'm getting a response in JSON format, which contains an _id that is stored as an ObjectID in Mongodb on the server side. However, I change it into a String, and it still won't let me add it. Is it because it has numbers? I need the element to be identifiable by the id, so if I can't append this way, is there any other way I can reference the element by the id?
var group = d3.select("#containerthing");
var id = response._id.toString();
console.log(id);
//5802bc044f6313c1097de4a2
var responseNode = group.append(id).attr("fill","black").attr("x", 15).attr("y", 15).attr("width", 190).attr("height", 90);
//InvalidCharacterError: String contains an invalid character
I believe that I understand your problem.
D3's .append():
If the specified type is a string, appends a new element of this type (tag name) as the last child of each selected element, or the next following sibling in the update selection if this is an enter selection. [...] This function should return an element to be appended. (The function typically creates a new element, but it may instead return an existing element.
Why .append() work fine if you pass 'foo'? Because D3 append a custom tag element. If you see in your console I'am sure that you will see <foo>...</foo>
Why .append() work wrong if you pass '5802bc044f6313c1097de4a2'? A custom tag element can't start with a number. You don't use _id, you should try to find another pattern for identify your element.
I hope that helps
The reason was that you can't start elements with numbers. I had to do:
var responseNode = group.append("n"+id).attr("fill","black").attr("x", 15).attr("y", 15).attr("width", 190).attr("height", 90);
to get it to work.

How to fetch value from custom multifield component?

I have created a multifield custom widget having two fields with names ./urlLink and ./urlText.
Now i m trying to fetch the values from widget into the component's jsp with following code
String property = properties.get("./urlLink",String[].class);
for(String value: property ) {
out.print(value);
}
out.print(property);
But i am not able to get its value instead i m getting error.
If you're getting a property and it contains a string value, you need to use the method getString() - that way when you have the property, you can set the string to the value by doing something like this:
Property property = properties.get("./urlLink",String.class);
String value = property.getString();
Just a side note, if your return is supposed to be a string array, your type that you're putting the values in should be a string array.
String[] value
Check out the documentation on day.com for Properties and getting the values inside them.
Looks like a typo: you don't prefix a property name with .\ when accessing it.
My guess is you got a NullPointerException, right? That's because there's no ./urlLink property in the value map (properties). You should check against that anyway (so that it's not thrown on a fresh page with no content).
If that doesn't help -- double check that you have the properties in the content (call your page with .xml or .infinite.json extensions, and then double check if you can read them as plain strings (you should be able to -- CRX does some magic, smart type conversions).
It's good to register custom xtype as :
// registering the custom widget with the name dualfield
CQ.Ext.reg("dualfield", CQ.Ext.form.DualField);
Then u can easily fetch the value as :
String[] data = properties.get("multi",String[].class);
Here multi is the name of widget having multifield as xtype

How to pass a byte[] parameter type in a sql query in MyBatis?

I need to match against an encrypted column in the DB. I need to pass the encrypted value for matching as a byte[]. The hashcode of the byte[] is passed instead of the actual value stored in the byte[]. Because the hash code is passed, it does not match the value correctly. Below is my query and the function call in the Mapper.java.
AccBalNotificationBean selectAccBalNotificationBean(#Param("acctIdByteArray") byte[] acctIdByteArray);
SELECT toa.accounts_id from tbl_transactions_other_accounts toa WHERE other_account_number = #{acctIdByteArray}
Thank you for your help.
I assume the datatype of your other_account_number column is of type string (char, varchar etc). Mybatis will use the StringDataTypeHandler by default and call the .toString() method of your byte array. Give MyBatis a hint that you want the content of your array to be used, by specifying the typeHandler.
.. WHERE other_account_number = #{acctIdByteArray, typeHandler=org.apache.ibatis.type.ByteArrayTypeHandler}