Odoo blog cover image not showing - odoo

I have created custom latest blog template. But I can't show cover images in thumbnails.
Cover image should be here:
I have written following code to show the cover image:
<div class="panel">
<t t-set="properties" t-value="json.loads(post.cover_properties)">
<a class="o_panel_cover" t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}" t-att-style="background-image: #{cover_properties.get('background-image')};">
</a>
</t>
<div class="panel-heading mt0 mb0">
<h4 class="mt0 mb0">
<a t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}" t-field="post.name"></a>
<span t-if="not post.website_published" class="text-warning">
<span class="fa fa-exclamation-triangle ml8" title="Unpublished"/>
</span>
</h4>
</div>
After writing the code image not loading and it shows like this:
How can I show the image?

I will suggest you to clear the cache of the browser, sometimes because of cache overloading we don't get image.

Firstly, there are several things with the controller.
The latest post route doesn't render cover-properties, it is like below:
return request.render("website_blog.latest_blogs", {
'posts': posts,
'pager': pager,
'blog_url': blog_url,
})
So I added necessary functions in my controller and returned like this:
return request.render("website_blog.latest_blogs", {
'posts': posts,
'pager': pager,
'blog_url': blog_url,
'blogs':blogs,
'blog_posts': blog_posts,
'blog_posts_cover_properties': [json.loads(b.cover_properties) for b in blog_posts],
})
On XML returned like this:
<t t-set="cover_properties" t-value="blog_posts_cover_properties[post_index]"/>
<a class="o_panel_cover" t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}"
t-attf-style="background-image: #{cover_properties.get('background-image')};"></a>

Related

Show as Html on vuejs

i have json file for translate ( en.json ) and this line :
{
"cancel order": "Hi, How can i <b> Cancel </b> ?",
}
<div class="d-flex align-items-center justify-content-center align-content-center mb-4">
<span class="description col-sm-11 col-md-7 col-lg-10">
{{ $t('cancel order') }}
</span>
</div>
now my result is " Hi, How can i Cancel "
The problem is that the html code does not apply like this code and the tags are displayed exactly without being applied.
You can use the v-html directive to rander raw html.
const htmlcontent = '<h1>Hello</h1>'
<span v-html="htmlcontent">
</span>
https://vuejs.org/guide/essentials/template-syntax.html#raw-html
use this :
<div v-html="$t('cancel order')"></div>
One observation : Using camelCase in property names consider as a best practice. Hence, use cancel order instead of cancel order.
To render your translation as an HTML message and not a static string. You can use v-html.
Template :
<span class="description col-sm-11 col-md-7 col-lg-10" v-html="$t('cancelOrder')"></span>

how to select the elements dont have a particular class inside div

I have the html like below. And I want those webelments through CSSselector or xpath which don't have div< class="locked"
Can anyone help me. The output should come as two webelements which are
"I am free video1" & I am free video2.
Locked Video
<div class="item video " data-reactid="165">
<a href="/video/peppa/xyz" data-reactid="166">
<div class="LazyLoad is-visible" style="height:168px;" data-reactid="167">
<img class="visual-video" src="https://abc.jpg?w=300" alt="I am locked video">
</div>
<p class="text" data-reactid="168">Episodio completo</p>
<img class="video" src="/images/icon-video.svg" data-reactid="169">
<div class="locked" data-reactid="170">
<div class="opaque" data-reactid="171"></div>
<p data-reactid="172">Activa tu cuenta</p>
</div>
</a>
<p class="name" data-reactid="173">I am locked video</p>
</div>
Free Video 1
<div class="item video " data-reactid="185">
<a href="/video/ghi" data-reactid="186">
<div class="LazyLoad is-visible" style="height:168px;" data-reactid="187">
<img class="visual-video" src="https://ghi.jpg?w=300" alt="I am free video1">
</div>
<p class="text" data-reactid="188">Episodio completo</p>
<img class="video" src="/images/icon-video.svg" data-reactid="189">
</a>
<p class="name" data-reactid="190">I am free video1</p>
</div>
Free Video 2
<div class="item video " data-reactid="192">
<a href="/video/sddfo" data-reactid="193">
<div class="LazyLoad is-visible" style="height:168px;" data-reactid="194">
<img class="video" src="/images/icon-video.svg" data-reactid="195">
</div>
</a>
<p class="name" data-reactid="196">I am free video2</p>
</div>
This is relatively straightforward to do with XPath:
//div[contains(#class, 'video') and not(div[#class='locked'])]
Note that, strictly speaking, to avoid false positives, you should be handling the class attribute values properly:
//div[contains(concat(' ', #class, ' '), ' video ') and
not(div[contains(concat(' ', #class, ' '), ' locked ')])]
Are those Texts are constant? If yes, then you can take elements from text.
How do I find an element that contains specific text in Selenium Webdriver (Python)?
This is an interesting question and i came up with a idea.
My idea is to capture all the videos first and then remove the locked videos from all videos list. Code is below,
//Gather all the videos
List<WebElement> all = driver.findElements(By.xpath("//div[#class,'item video']/a"));
//Gather the videos which has locked
List<WebElement> locked = driver.findElements(By.xpath("//div[#class,'item video']//div[#class,'locked']"));
//Remove the locked videos from all videos
for(WebElement lock : locked)
{
all.remove(lock);
}
//Now "all" contains only the free videos.
for(WebElement free : all)
{
//Do the stuff
}
Note - Not tested. Kindly check and let me know if works
If your CSS implementation supports the :not() "pseudo-element" selector, then you could try
.item.video:not(div.locked) p.name
cf. https://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:not
That may be overly specific as I don't understand the context of the mark-up.
For XPath, I think it would be something like this:
//div[contains(#class, 'video') and not(.//div[contains(#class, 'locked')])]//p[contains(#class,'name')

How can i click an image from the search results page

I am writing a test in Webdriver C# with Nunit. I have a search results page loaded with a list of products with images. I want to click the 1st image in the results.
I have tried using the Xpath (I used firepath to get this value)
[FindsBy(How = How.XPath, Using = "html/body/form/div[2]/div[4]/div/div[2]/p")]
private IWebElement ProductImage_xpath {get; set; }
When it runs it says:
Could not find element by XPath.
I would like to use CSS selector if possible as that is faster than finding by Xpath.
What syntax could I use to locate the image from the code snipped below?
Note: the hyperlinks are dynamic, I don't want to use the href.
public SearchResultsPage clickProduct_Image()
{
ProductImage_xpath.Click();
Console.Out.WriteLine("ProductImage = " + ProductImage_xpath.Text);
return new SearchResultsPage(Driver);
}
The Code snippet:
<div id="main" class="nav_redesign s-left-nav-rib-redesign" data-page-construction="aui" skeleton-key="results--searchTemplate listLayout so_gb_en --left-nav--shopping-engine">
<div id="topStatic">
<div id="top">
<div id="topAmabot"> </div>
<div id="searchTemplate" class="searchTemplate listLayout so_gb_en ">
<div id="topDynamicContent">
<div id="rightContainerATF">
<div id="rightResultsATF">
<div id="widthPreserver"></div>
<div id="centerPlus">
<div id="rhsAjax"></div>
<div id="resultsCol" class="">
<div id="centerMinus" class="">
<div id="atfResults" class="list results apsList">
<div id="result_0" class="fstRow prod celwidget" name="1780974728">
<div class="linePlaceholder"></div>
<div class="image imageContainer">
<a href="http://testerServer1co.uk/SpaceExplorer/dp/1780974728/ref=sr_1_1?ie=UTF8&qid=1409311161&sr=8-1&keywords=planets+1">
<div class="imageBox">
<img class="productImage cfMarker" alt="Product Details" src="http://ecx.images-test.com/images/I/51iYWWt1BqL._SL160_PIsitb-sticker-arrow-dp,TopRight,12,-18_SH30_OU02_AA160_.jpg" onload="viewCompleteImageLoaded(this, new Date().getTime(), 16, false);">
</div>
Xpath is very very bad choice to find element on the page =). As you said better use css selector. I don't know how your image presents on the page, but i'll write possible variants, choose the best one. So, using css selectors to find your image:
1. You can find any element using it's class
//will find "div class="image imageContainer""
driver.findElement(By.Css(".imageContainer"))
2. Combine searching by class and find first "a" child in that div
driver.findElement(By.css(".imageContainer > a"))
3.Find element using known attribute
driver.findElement(By.css("img[alt='Product Details']"))
4. Find element by ID
driver.findElement(By.Css("#atfResults"));
//or
driver.findElement(By.Id("atfResults"));
Well, it will be enough for you, i think. If you have any questions, you are welcome.

static content in partial view mvc4

I have two views as shown below:
boott.cshtml
#model model
<div>
#if (Model.ViewModel != null)
{
#Html.Partial("_b_table", Model)
}
<span class="d2-fldr">Enter folder name: </span>
<input type="text" name="txtName" class="txtFldrname"/>
<a class="small d2-createfldr" title="Create folder" href="#">
<span class="glyphicon glyphicon-plus d2-ico"></span>
<span class="d2-axn">Create folder</span>
</a>
)
</div>
_boott_table.cshtml
#model model
<div class="#BOOTSTRAP.ROW">
-- some content from model
</div>
The view boott.cshtml is directly rendered from the controller's action "boott".
The partial view _boott_table.cshtml content changes always based on the option we select in partial view.
When we click on the options in partial view, we are calling the same action method "boott" and renders the partial boott.cshtml and send the html back.
However there is some static content in boott.cshtml (spans, input, a tag), they are not part of partial view _boott_table.cshtml and should not get re-rendered when ever we click on the options in _boott_table.cshtml.
How can we handle this situation ?
can somebody advise?/

How to Know Available Data from my website for my Google Custom Search

I'm trying to implement a Google Custom Search Engine into my website. So far, I've been able of changing my snippets layout, and show the variables Google shows in its examples:
http://googleajaxsearchapi.blogspot.com.es/2010/04/rendering-custom-data-in-custom-search.html
Well, in the examples, everything looks great, BECAUSE THEY KNOW THE VALUES THEY MAY PRINT. I mean, if you see this snippet:
<div id="mysite_thumbnail">
<div data-if="Vars.thumbnail" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:thumbnail.src, width:48, height: 48}"/>
</a>
</div>
</div>
it's pretty clear that "Vars" is holding some data GSE is printing. My problem is that I don't know what "Vars" holds, and when developing my view I can't know if the value is there, and what is its name.
So, the question is: How can I print "Vars"? I suppose is a js variable you may obtain from the jsapi, but juss guessing, console.log() was not working for me, :(
Well, I finally found out how to post the data:
From Google Search Engine Api documentation:
https://developers.google.com/custom-search/docs/js/rendering?hl=es&csw=1#richsnip
You only have to add the following code in your snippet:
<span data-body="JSON.stringify(Vars)"></span>
So, you'll have something like:
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
// Load the Search API
google.load('search', '1');
// Set a callback to load the Custom Search Control when you page loads
google.setOnLoadCallback(
function(){
new google.search.CustomSearchControl('XXXXXXXXXXXXXXX').draw('cse');
google.search.Csedr.addOverride("mysite_");
},
true);
console.log(google);
</script>
<div style="display:none">
<div id="mysite_thumbnail">
//This will show all Vars content
<span data-body="JSON.stringify(Vars)"></span>
<div data-if="Vars.thumbnail" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:thumbnail.src, width:48, height: 48}"/>
</a>
</div>
<div data-ifel="Vars.thumbnail == 0" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:'XXXXX.png', width:115, height: 90}"/>
</a>
</div>
</div>
<div id="mysite_webResult">
<div class="gs-webResult gs-result"
data-vars="{longUrl:function() {
var i = unescapedUrl.indexOf(visibleUrl);
return i < 1 ? visibleUrl : unescapedUrl.substring(i);}}">
<table>
<tr>
<td valign="top">
<div data-if="Vars.richSnippet" data-attr="0"
data-body="render('thumbnail',richSnippet,{url:unescapedUrl,target:target})"></div>
</td>
<td valign="top">
<div class="gs-title">
<a class="gs-title" data-attr="{href:unescapedUrl,target:target}"
data-body="html(title)"></a>
</div>
<div class="gs-snippet" data-body="html(content)"></div>
</td>
</tr>
</table>
</div>
</div>
</div>