How to disable image caching in Odoo email? - python

I'm currently using Odoo 12.0+e-20181025. I have changed the logo for the email but the GMail that has received the previous email refused to show the new logo although the link of the image in the email has pointed to the new logo.
I have checked the image and it is the correct image. I've also tried following the URL in the email that showed the previous (the wrong) image, and it led to a correct image, just not showing it in the email display.
I've read that it has something to do with the Gmail image caching function, but since most of my users are using Gmail, I need to make it so that the image won't cache and my idea at the moment is to add no-cache at the header HTML, but I don't know where can I set that in my current version of Odoo.
Thank you for reading and for your help.

Okay, I found the answer. It is in the view > mail_notification_light
Here are the first few lines of codes in the XML
<?xml version="1.0"?>
<t t-name="mail.mail_notification_light">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
Then changed into these.
<?xml version="1.0"?>
<t t-name="mail.mail_notification_light">
<meta http-equiv="Cache-control" content="no-cache" />
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
So I put the in there. So far, it works wonder. Once again, thank you for everyone that has been reading and giving comment.

Related

table.tableize-table r function works well in .html, but not display in Gmail through MIMEText

Newbe working on html. I got below settings in .html, and it works as expected when opening the file in a browser (chrom/safari).
(in browser)--> (failed in gmail)
However, when I use MIMEText to send the same html content, it fails: none of the color code features are preserved. It does not matter that attribute I tried to edit in table.tableizer-table, font-size, border, none works when sent in email.
<html><body>
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC;
}
.tableizer-table th {
background-color: #009452;
color: #FFF;
font-weight: bold;
}
.tableizer-firstrow td {
background-color: #009452;
color: #FFF;
display: inline-block;
}
</style>
<table class="tableizer-table">
<thead>
<tr style="background-color:#104E8B; color: #ffffff;"><td align="center" rowspan="1" colspan="5" ><strong>RECORD <strong></td></tr>
</thead>
<tbody>
<tr class="tableizer-firstrow"><th style="background-color: #CCC;color: #FFF;">GOOD COMPANY</th><th>EMAIL</th><th>PHONE</th><th>ADDRESS</th></tr>
<tr><td>company2</a></td><td style="text-align: right;">0</td><td>100</td><td>1st Ave</td></tr>
<tr class="tableizer-firstrow"><th style="background-color: #CCC;color: #FFF;">BAD COMPANY</th><th>EMAIL</th><th>PHONE</th><th>ADDRESS</th></tr>
<tr><td>company2</a></td><td style="text-align: right;">0</td><td>212</td><td>Fifth Ave</td></tr>
</tbody>
</table>
</body>
</html>
I am working primarily on python and email is sent as below:
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
message = MIMEMultipart("alternative", None, [MIMEText(one_email_html, 'html')])
receiver = 'aaa#gmail.com'
sender_email = 'bbb#gmail.com'
print('Type in password')
password = input()
message["Subject"] = subject
message["From"] = sender_email
message["To"] = receiver
# Create secure connection with server and send email
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(
sender_email, receiver, message.as_string()
)
where one_email_html is the """string""" of the html content.
You should be placing the <style> section inside <head>...</head> tags.
Second, you should inline all embedded styles. This is why this works: <tr style="background-color:#104E8B; color: #ffffff;">, but your classes don't. Some email clients, such as some forms of Gmail, and most desktop and webmail environments, do not support embedded styles at all (styles within <style>).
Third, perhaps you need to use the full hex, rather than shortened hex codes. So <th style="background-color: #CCC;color: #FFF;"> becomes: <th style="background-color: #CCCCCC;color: #FFFFFF;">, for example.

How to use border-radius while converting html to pdf using xhtmltopdf

I am trying to round the corners of my table, border-radius doen't seem to work when I convert the below HTML to PDF using xhtmltopdf pdf generator. Below is the HTML written for content file name is sticker_print.html :
<div class="sticker" style="height:196px">
<table class="sticker_box" align="left">
<tr>
<td style="border: 1px solid #222;background-color: #ffffff;">
<h3 style="border-bottom: 1px solid #222222;">Batch Sticker</h3>
<h5 style="padding: 0 0 0 10px;">Batch ID</h5>
<p>MFG Date</p>
<p style="padding-bottom:0px;"><img src="http://www.computalabel.com/Images/C128ff#2x.png" width="195px" height="26px"><span> Bar Code </span></p>
<p style="text-align: left; padding-bottom: 0px;">
<img src="https://www.kaspersky.com/content/en-global/images/repository/isc/2020/9910/a-guide-to-qr-codes-and-how-to-scan-qr-codes-2.png" width="65px" height="65px">
<span style="display: block;margin-top: 0px;">QR Code</span>
</p>
</td>
</tr>
</table>
</div>
PDF CODE
pdf = render_to_pdf('sticker_print.html')
return HttpResponse(pdf, content_type='application/pdf')
Even though I'm not using the same PDF engine as you (and your question is 6 months old), I solved this issue by using corner-radius instead of border-radius on a table cell or div.

Beautiful soup not finding table ID

I am trying to extract some data from a webpage that has multiple tables. All the tables have an id="name" attribute. I am using beautiful soup 4 with Python 3.4.1. My code lopped through the first tables just fine, but on the last one it returns 'None' and I can't figure out why.
The html code for the table info is below and from what I can see, it was not formatted any differently than the other tables that had other id names such as id=Datagrid1
<TR>
<TD vAlign=top>
<TABLE id=Datagrid7
style="FONT-SIZE: smaller; FONT-FAMILY: Verdana; WIDTH: 675px; BORDER-COLLAPSE: collapse"
cellSpacing=0 rules=all align=left border=1>
<TBODY>
The python code below returns None, but will work if I change the id to another known id name.
table = soup.find('table', id='DataGrid7')
print(table)
there was typo error in your program it should be small 'g'
from bs4 import BeautifulSoup
html="""<TR>
<TD vAlign=top>
<TABLE id=Datagrid7
style="FONT-SIZE: smaller; FONT-FAMILY: Verdana; WIDTH: 675px; BORDER-COLLAPSE: collapse"
cellSpacing=0 rules=all align=left border=1>
<TBODY>"""
soup=BeautifulSoup(html)
print soup.find('table',id='Datagrid7')
#output <table align="left" border="1" cellspacing="0" id="Datagrid7" rules="all" style="FONT-SIZE: smaller; FONT-FAMILY: Verdana; WIDTH: 675px; BORDER-COLLAPSE: collapse">
<tbody></tbody></table>
There's a typo in the code.
The id of the table is Datagrid7, not DataGrid7:
table = soup.find('table', id='Datagrid7')
# ^

wkhtmltopdf adds extra spacing when multiple width, height : 100% elements

I'm using wkhtmltopdf via subprocess to generate PDFs in a python flask web app. It works great for most html input I give, but applies some very weird formatting in certain cases. For some cases, I need to append the html block together 5 times. In that case, the PDFs generated contain multiple blank pages in between content (which I would rather not have).
The format of the HTML I provide is the following:
<body>
<center>
<table height="100%" width="100%" id="backgroundTable" style="
height: 100%;
width: 100%;">
<!-- More content -->
</table>
</center>
</body>
I have found that the culprits are the height="100%" width="100%" and style="height: 100%; width: 100%;" calls for the <table> element.
Does anyone know why that would cause the issue?

Using the example from the bottle documentation, I still get an empty value for query_string

Using bottle's built in WSGI server, here is the relevant HTML:
form style="display: inline;" action="/forum?id=2&page=5">
<input type="submit" value="Forum"/></form>
Here is the route from my application:
#rolodex.route('/forum')
def display_forum():
forum_id = bottle.request.query.id
page = bottle.request.query.page or '1'
return 'Forum ID: %s (page %s)' % (forum_id, page)
Here is what I get when I click on the "Forum" button:
Forum ID: (page 1)
Any ideas on what I could possibly be doing wrong? This is essentially exactly the example found in the documentation:
bottlepy.org/docs/0.11/tutorial.html#request-data
Perhaps the query string in your form action is interacting with the request. What happens when you make id and page proper form fields? Like this:
<form action="/forum">
<input type="text" name="id" value="2"/>
<input type="text" name="page" value="5"/>
<input type="submit" value="Forum"/>
</form>
(Or, when you hit it with your browser directly? E.g., http://yourserver/forum?id=2&page=5)
All the documentation I've found about this is quite ambiguous, but it appears that most browsers will not process and submit query strings which are appended to <form> actions. The correct way to do this is to include the query parameters as hidden text fields in the body of the <form> container. So instead of this:
<form style="display: inline;" action="/forum?id=2&page=5">
<input type="submit" value="Edit"/></form>
Do this:
<form style="display: inline;" action="/forum">
<input type="hidden" name="id" value="2"/>
<input type="hidden" name="page" value="5"/>
<input type="submit" value="Edit"/>
</form>
The HTML specification states that a form action must be an HTTP URI, and the definition of URI does include the possibility of a query string; however, if nothing else, it should probably be considered bad form to include the query string variables in the form action when the option of using hidden inputs is a cleaner, less ambiguous solution.
Moreover, as pointed out by Ron Rothman in another answer, there is no reason to use a <form> in this context at all -- just use a link with an appropriate href:
<a class="button" href="/forum?id=2&page=5">Edit</a>
using this CSS (or something similar):
.button {font-size: small;
font-family: Verdana, Arial, sans-serif;
text-decoration: none;
background-color: #DDDDDD;
color: #222222;
padding: 1px 12px 1px 12px;
border-radius:7px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;}

Categories

Resources