Bad management of BR tag by M2Doc - m2doc

I have come across a weird behavior of M2Doc.
My template is the following:
1.1 {M:REQ.REQIFNAME}
{m:req.ReqIFText.fromHTMLBodyString().replaceLink(req).reduceAllImages(380,380)}
If the ReqIfName field contains the following
<div id="LHDD__006"><br/>Beginning of the ReqIfText<br/>abc<br/>def<div/>
Then the whole content of the field is displayed in the title. Meaning that it actually merges with the preceding content.
If the ReqIfName field contains the following
<div id="LHDD__006">Beginning of the ReqIfText<br/>abc<br/>def<div/>
Then the result is the one one would expect.
Here is a screencopy of the result
Word document resulting from the generation

Related

Django: display a preview of an object's attribute - Class based views

Using a ListView Class-based-view, I am looping over the objects present in the database of a certain model in my HTML template, and, for instance, I can access an object's "body_text" attribute with the following syntax: {{object.body_text}}
What if I wanted to only show the first 20 characters of that "body_text" attribute in my HTML template?
How can I set that?
1st Method
Use the truncatechars filter in your HTML template.Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis character (“…”).
{{object.body_text|truncatechars:20}}
Reference:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#truncatechars
2nd Method
Use the slice filter in your HTML template.
{{object.body_text|slice:":20"}}
Referernce: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slice
Found it, eventually.
Use the |slice:":" filter in your HTML template.
For example, if you only want to display the first 10 characters of a given attribute, use:
{{object.body_text|slice:":10"}}

Use Yahoo Pipes to convert RSS html tags to standard tag items

I want to move from using bookmarking service Delicious to Diigo, but the way diigo organise tags in their RSS is preventing the move.
I want to use a Yahoo Pipe to turn Diigo rss tags into the same format as Delicious rss tags
Diigo tags are stored as a html list at the bottom of the 'Description' item, like this:
Some test describing the link.
<p class="diigo-tags"><strong>Tags:</strong>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/firsttag'>firsttag</a>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/2ndtag'>2ndtag</a>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/anothertag'>anothertag</a>
etc... </p>
I need to extract each of these and store them in their own item. Delicious stores each tag in a nested field category by number, like this:
category
0
domain http://delicious.com/username/
content firsttag
1
domain http://delicious.com/username/
content 2ndtag
So, the Yahoo Pipe needs to strip the html list and separate each tag into single category fields.
Not sure where to start, except maybe this regular expression in regex to strip the html:
(?si)<a[^<>]*?[^<>]*>(.*?)</a>
Any advice appreciated.
You can extract the tags from the diigo stream by performing the following replacements using the Regex operator:
replace <a[^<>]*?[^<>]*>(.*?)</a> with $1, using options g and s (the tag itself within the <a>...</a>)
replace <.+> with nothing, using options g and m (delete all HTML tags)
replace [\s]+ with a single space, using options g and s
As a result, the description field now contains the list of tags separated by spaces. I'm not sure what you need next, if you tell me I can try to help.
Here's the pipe:
https://pipes.yahoo.com/pipes/pipe.info?_id=1656d9fcab9d9ed6016bdae7486ee71f
UPDATE
I see, the tricky part is adding multiple category nodes to an RSS feed. Unfortunately, I don't think that's possible. I updated the pipe, so that now you have item.category.1, .2, .3, and so on, but when you look at the RSS output of the pipe, it doesn't show any categories. (I think this might be related to the fact that the Create RSS operator doesn't have a category field either.)
In the JSON output there are multiple categories correctly.
I also tested that if there is only one category field, it would show up correctly in the RSS output. If there are more than one then no.
And I'm afraid this is as far as I can get you.

Displaying extra field - specification in store front end

I have added an extra field Specification in Catalog->Product->Data tab.
This text is stored in a column called specification in product_description table.
Now I want to display this information in my Store Front (default theme). On product page there is a tab Specification that displays attribute. I want to display specification instead of attribute.
Please suggest me how to do it :(
First: edit Your Product model - should be in catalog/model/product/product.php - find the method getProduct and edit the SQL that selects the product details to also get the specification column.
Second: edit Your Product controller - should be in catalog/controller/product/product.php and make sure that Your specification column will be added to $this->data['specification'], e.g.
Third: edit Your Product detail template - should be in catalog/view/theme/default/templates/product/product.tpl and find that part where <div class="tabs"> (or similar) is - then find the tab for specification and print out Your specification column here...
Should be done.

Ordered list form value in Django form

Is there a way to submit an unbounded list of values as part of a form and retrieve it in Django as an ordered list? I saw this question: Django equivalent of PHP's form value array/associative array which makes sense, however since the values are submitted with the same name as separate POST values I assume they are unordered.
Ideally, I'd like this on the front end:
<input type="hidden" name="list[0]" value="blah">
<input type="hidden" name="list[1]" value="blah2">
<input type="hidden" name="list[2]" value="blah3">
and be able to see which list item occurred in which position when the form was submitted.
I want it sorted in an order determined in the front-end HTML, not sorted by value. I know about getlist(), but that doesn't preserve order.
As far as I'm aware, the square bracket notation is a convention of PHP rather than HTML per se.
There seems to be a Django workaround using dot notation to generate expanded dictionaries (http://stackoverflow.com/questions/2527476/phps-form-bracket-trick-is-to-djangos). I haven't tried it, but it seems it could work
The other solution is to parse the form names yourself, extracting the number from the square brackets and generating your own ordered list
(DISCLAIMER: I'm a mere casual programmer, and am more than willing to acknowledge that im wrong - but hopefully the SO moderation system will moderate any silly comments into oblivion)

Does default_if_none have any use in Django templates?

From the Django docs,
Generally, if a variable doesn't
exist, the template system inserts the
value of the
TEMPLATE_STRING_IF_INVALID setting,
which is set to '' (the empty string)
by default.
Filters that are applied to an invalid
variable will only be applied if
TEMPLATE_STRING_IF_INVALID is set to
'' (the empty string). If
TEMPLATE_STRING_IF_INVALID is set to
any other value, variable filters will
be ignored.
This behavior is slightly different
for the if, for and regroup template
tags. If an invalid variable is
provided to one of these template
tags, the variable will be interpreted
as None. Filters are always applied to
invalid variables within these
template tags.
If an invalid variable always gets translated to '', for template tags and filters other than if, for and regroup, then what good does the template filter default_if_none do? Obsolete?
There is a difference between an invalid variable and one that exists but has a value of None.
Consider the following context:
{'apple':'green','banana':None}`
In your template {{ apple }} resolves to green, while {{ banana }} resolves to None, and {{ orange }} resolves to TEMPLATE_STRING_IF_INVALID.
Now consider {{ banana|default_if_none:'yellow' }} and you should see the use of the default_if_none tag.
Here's a case where I have used default_if_none a few times. I'm querying a secondary database in which I have no control and I'm displaying the data in the template. Most of the times the data looks fine but sometimes, the data value will show None. In that case, I will use the filter as:
{{ data_value|default_if_none:"N/A" }}
The general public and users of site doesn't usually understand what the None value means, by replacing it with a more friendly word, the filter default_if_none comes in handy.
I have a Django model with a method returning the the number of days a trade has been open (an integer). For the first 24 hours it returns 0. However, once the trade is closed, it returns None.
In this situation, the distinction between default and default_if_none is important... I need to use default_if_none... otherwise, for the first 24 hours a trade is open, it looks as if they were already closed (because zero is falsy).