2013-04-25 68 views
0

我试图通过电子邮件发送一个表,该列将在单击该列时根据列进行排序。我发现http://tablesorter.com/docs/,它看起来非常直截了当。作为HTML邮件发送时,Tablesorter不工作

我正在使用python来编写html。 有问题的功能是

def getOpportunitiesTable(opps): #formats html table for email 

它发生在字典的一个列表,应该返回HTML

html = "" 
html += "<head>" 
html += '<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>' 
html += '<script type="text/javascript" src="http://mottie.github.com/tablesorter/js/jquery.tablesorter.js"></script>' 
html += "</head>" 
html += '<table id="opportunities" class="tablesorter">' 
html += '<thead><tr><th>Opportunity Name</th><th>Forcasted Close Date</th><th>Pipeline Category</th><th>Stage</th><th>Priority</th></tr></thead>' 

html += '<tbody>' 
for o in iter(opps): 
    html += "<tr>" 
    #opportunity name linked to insightly's page 

    html += "<td>" + '<a href="https://googleapps.insight.ly/Opportunities/Details/' + str(o['OPPORTUNITY_ID']) + '">' 
    try: 
     html += o['OPPORTUNITY_NAME'].encode('utf-8') 
    except: 
     html += '************************' 
     logging.info(str(o)) 
    html += "</a>" + "</td>" 
    html += "<td>" 
    if 'FORECAST_CLOSE_DATE' in o and o["FORECAST_CLOSE_DATE"] != None: #if fclose date provided format it 
     html += datetime.strptime(o["FORECAST_CLOSE_DATE"], '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d') 
    else: 
     html += ' - ' 
    html += "</td>" 

    html += "<td>" + pipelineCategory[o['PIPELINE_ID']] if o['PIPELINE_ID'] in pipelineCategory else ' - ' + "</td>" 
    html += "<td>" + stageName[o['STAGE_ID']] if o['STAGE_ID'] in stageName else ' - ' + "</td>" 
    html += "<td>" + str(o["OPPORTUNITY_FIELD_5"]) + "</td>" 
    html += "</tr>" 

html += '</tbody>' 
html += "</table><br/>" 

return html 

我的困惑带有这两条线

html += '<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>' 
html += '<script type="text/javascript" src="http://mottie.github.com/tablesorter/js/jquery.tablesorter.js"></script>' 

而且内在的问题我应该被允许发送一个HTML电子邮件来操纵发送的表格吗?

任何帮助表示赞赏!

+0

你想发送一个HTML电子邮件与JavaScript元素?因为那不行。 – samanthasquared 2013-04-25 20:56:16

回答

1

在HTML电子邮件中不可能使用Javascript,因为这会带来很大的安全风险。大多数邮件客户端将被删除或简单地忽略HTML邮件中的任何脚本。

此外,远程脚本的加载可能会被许多客户端阻止为远程内容,并且需要用户手动加载远程内容。但即使他们允许这样做,它仍然不允许在电子邮件中运行脚本。

最好的办法是将HTML作为一个附件,然后可以打开(风险自负),或将HTML保存在服务器的某个地方并链接到它。