Movable Type: MTEntries sort_by="title" doesn't really work - movabletype

Im trying to sort <MTEntries> by title.
I know you can use <MTEntries sort_by="title" sort_order="ascend"> but this modifier some how prioritizes capitalized letters first to the sort. Im not sure if this is a glitch in the system but this modifier should sort by purely the alphabets(caps or no caps) used in the title.
Example:
Template code:
<ul>
<MTEntries sort_by="title" sort_order="ascend">
<li><MTEntryTitle></li>
</MTEntries>
</ul>
I would like to sort these titles alphabetically:
APRICOT
Aligator
ABBEY
Apple
If <MTEntries sort_by="title" sort_order="ascend"> is used:
ABBEY
APRICOT
Aligator
Apple
But it really should be (and I want)
ABBEY
Aligator
Apple
APRICOT
Would someone know how to achive this?

The reason that they are being sorted in this order is that capitalization matters with string sorts. For example, 'B' would come before 'a'.
You could achieve what you're looking for with use of the Order plugin, since that transforms everything to lowercase before performing the sort:
<mt:order sort_order="ascend">
<mt:entries>
<mt:orderitem>
<mt:setvarblock name="order_by"><mt:entrytitle></mt:setvarblock>
...
<!-- entry display bits here -->
...
</mt:orderitem>
</mt:entries>
</mt:order>
(Warning: I haven't tested that)

Related

Freemarker - Split String based on New Line

I want to split a string based on the lines, meaning seperating contents on seperate lines.
Example -
Hello I
am
Bill Gates
Final Array should be ["Hello I","am","Bill Gates"]
I tried using split function and passing '\n' but it ain't working.
<#assign finalValue = body?split('\n') />
I am not getting the desired result in this case. Can you please help me out with this?
For more details, read below -
I am trying to fetch country from an address. Country is always on the last line of address, so I am trying to SPLIT the address based on lines, thus fetching last line which is the desired output.
Example -
ABC, Industries Ltd.,
XYZ Street,
United States.
So here, I am using split function as address?split("\n") but it ain't working.
So, I tried splitting using Developers Console and it worked fine there. Used split() function.
Upon fetching the address value though, I am getting it as -
ABC, Industries Ltd., \n XYZ Street, \nUnited States.
Hence, thought of splitting using \n but it ain't working!
The usual problem is that there are 3 kind of line-breaks in use: \r\n (Windows and some Web protocols), \n (everything else), and very rarely \r (old Mac). The split that works with all is ?split(r'\R', 'r'). Note that the R is capital in \R. That's a regular expression construct, supported since Java 8.
Likely doesn't help the OP, but might help someone else from the frustration of trying to split on line break for an advanced PDF in NetSuite using Freemarker!
You need to use <br />
${var?split(r"<br />", "r")}

How to let currency unmodified with MathJax

I am using MathJax with the following configuration:
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
As you can see, there is nothing fancy.
I work really well and my inline math is correctly transformed.
My problem arise when I have sentences like With a total of twenty $25,000 USD prizes for US contestants and ten $30,000 CAD prizes for the Canucks in Phase 1 of the challenge.
As expected, the $25,000 USD prizes for US contestants and ten $ part is interpreted by MathJax.
As you can imagine, it's not something I am looking for.
Knowing that I have no control on the content because it's inside a feed reader, is there some configuration I can use to escape that kind of strings or I am out of luck and there is nothing I can do?
As per the MathJax documentation:
You can use \$ to prevent a dollar sign from being treated as a math delimiter within the text of your web page, e.g., use “… the cost is $2.50 for the first one, and $2.00 for each additional one …” to prevent these dollar signs from being used as math delimiters in a web page where dollar signs have been configured to be in-line delimiters.
An alternative method is to wrap $ in a span tag (since MathJax will stop searching for closing $ at the end of a span).

python decode partial hex strings

I'm using beautiful soup to parse email invoices and I'm running into consistent problem involving special characters.
The text I am trying to parse is shown in the image.
But what I get from beautiful soup after finding the element and calling elem.text is this:
'Hi Mike, It=E2=80=\r\n=99s probably not a big drama if you are having problems separating product=\r\ns from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.\r\nAlso, remember that we will have just straight up product orders that your =\r\nsystem will not be able to place into a class list, hence having the extra =\r\nsheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.'
As you can see the apostrophe is now represented by "=E2=80=99", double quotes are "=E2=80=9C" and "=E2=80=9D" and there are seemingly random newlines in the text, for example "product=\r\ns".
The newlines don't seem to appear in the image.
Apparently "E2 80 99" is the unicode hex representation of ' , but I don't understand why I can still see it in this form after having done email.decode('utf-8') before sending it to beautiful soup.
This is the element
<td border:="" class='3D"td"' left="" middle="" padding:="" solid="" style='3D"color:' text-align:="" v="ertical-align:">Hi Mike, It=E2=80=
=99s probably not a big drama if you are having problems separating product=
s from classes. It is not uncommon to receive an order for pole classes and=
a bottle of Dry Hands.
Also, remember that we will have just straight up product orders that your =
system will not be able to place into a class list, hence having the extra =
sheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.</td>
I can post my code if required but I figure I must be making a simple mistake.
I checked out the answer to this question
Decode Hex String in Python 3
but i think that expects the entire string to be hex rather than just having random hex parts.
but I'm honestly not even sure how to search for "decode partial hex strings"
My final questions are
Q1 How do I convert
'Hi Mike, It=E2=80=\r\n=99s probably not a big drama if you are having problems separating product=\r\ns from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.\r\nAlso, remember that we will have just straight up product orders that your =\r\nsystem will not be able to place into a class list, hence having the extra =\r\nsheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.'
into
'Hi Mike, It's probably not a big drama if you are having problems separating products from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.Also, remember that we will have just straight up product orders that your system will not be able to place into a class list, hence having the extra sheet for any "erroneous" orders will be handy.'
using python 3, without manually fixing each string and writing a replace method for each possible character.
Q2 Why does this "=\r\n" appear everywhere in my string but not in the rendered html?
#JosefZ's comment lead me to the answer.
Q1 has an answer.
>>> import quopri
>>> print(quopri.decodestring(mystring).decode('utf-8'))
Hi Mike, It’s probably not a big drama if you are having problems separating products from classes. It is not uncommon to receive an order for pole classes and a bottle of Dry Hands.
Also, remember that we will have just straight up product orders that your system will not be able to place into a class list, hence having the extra sheet for any “erroneous” orders will be handy.
Q2 Thanks to #snakecharmerb I now know that the seemingly random unrepresented line endings are to enforce a line length of 80 characters.
#snakecharmerb wrote a much better answer than this one to someone with the same problem as me here.
https://stackoverflow.com/a/55295640/992644

How to printout data from a list in web2py

In a code such as shown below, I have data that is dumped to a list as shown:
def foo():
list1=[It’s possible Arianne could appear in future seasons, but as Kotaku notes, the official character bio of Trystane describes him as the heir to Dorne, while Ariane’s love interest, Aerys Oakheart, has also not been cast. The exclusion comes as a surprise to fans, not just because Arianne is a major player in the fantasy novels’ numerous plot twists, but also because she was a strong, complex female character in a fictional universe that doesn’t have too many of those.]
return list1
In view html:
{{extend 'layout.html'}}
<h1>{{=list1}}</h1>
How do I make it to print out each sentence as a bullet point?
Controller:
def foo():
list1=["It's possible Arianne could appear in future seasons, but as Kotaku notes, the official character bio of Trystane describes him as the heir to Dorne, while Ariane’s love interest, Aerys Oakheart, has also not been cast.", "The exclusion comes as a surprise to fans, not just because Arianne is a major player in the fantasy novels’ numerous plot twists, but also because she was a strong, complex female character in a fictional universe that doesn’t have too many of those."]
return dict(list1=list1)
View:
{{extend 'layout.html'}}
<ul>
{{for row in list1:}}
<li>{{=row}} </li>
{{pass}}
</ul>
The view iterates through the list and creates one "li" tag per each item passed by the controller.

Freemarker - How to prevent Split builtin from breaking prematurely

I'm still fairly new to Freemarker and am currently trying to output a bulleted list using the Split builtin.
My code so far is so:
<#list listingname?split(", ") as x>
• ${x} <br />
</#list>
My issue arises when a value from the 'listingname' field contains a comma-space (, ) - this causes the the outputed code to break prematurely.
So for example, let's say:
listingname = "john's company", "bill, bob's tackle and bait", "john do - attorney at law"
The above code would render it as so:
• "john's company"
• "bill
• bob's tackle and bait"
• "john do - attorney at law"
The issue here is that the 2nd set of double-quoted text breaks instead of displaying "bill, bob's tackle and bait" on one line.
So I guess my question is, is there a way to prevent this from happening?
Can't you just pass that listing to FreeMarker as a Java List or array? I mean, it's like you try to parse the list literals of some language here. That's not something you usually do in templates. And ?split is just for spliting, it's certainly not smart enough for this.
But if you indeed has to do this, parsing in the template, what syntactical rules does this listing string follow? Like, what if a list item value contains a quotation mark? Will it be escaped like \"? If the syntax is compatible with FTL's own syntax, you could do <#list ('[' + listingname + ']')?eval as x>.

Resources