示例#1
0
def convert_to_html(tagname,
                    text,
                    font_family="sans-serif",
                    font_size=9,
                    line_height=10,
                    text_align='left'):
    try:
        html_text = ''
        html_node = etree.HTML('<div>%s</div>' % toHtml(text))
        html_text = etree.tostring(html_node.find('body/div'),
                                   xml_declaration=False,
                                   encoding='utf-8').decode("utf-8")
        html_text = html_text.strip()[5:-6]
        xml_text = etree.XML("<%(tagname)s>%(text)s</%(tagname)s>" % {
            'tagname': tagname,
            'text': html_text
        })
        xml_text.attrib['font_family'] = font_family
        xml_text.attrib['font_size'] = "%d" % font_size
        xml_text.attrib['line_height'] = "%d" % line_height
        xml_text.attrib['text_align'] = text_align
        xml_text.attrib['spacing'] = "0.0"
    except etree.XMLSyntaxError:
        getLogger("lucterios.core.print").exception('convert_to_html')
        raise Exception(
            'convert_to_html error:tagname=%s text=%s html_text=%s' %
            (tagname, text, html_text))
    return xml_text
示例#2
0
 def sendemail(self, nb_to_send, http_root_address):
     if will_mail_send() and (self.status == 2):
         email_list = self.email_to_send.split("\n")
         link_html = ""
         files = []
         for doc in self.documents.all():
             if self.doc_in_link:
                 if doc.sharekey is None:
                     doc.change_sharekey(False)
                     doc.save()
                 doc.set_context(http_root_address)
                 link_html += "<li><a href='%s'>%s</a></li>" % (doc.shared_link, doc.name)
             else:
                 files.append((doc.name, doc.content))
         if self.doc_in_link and (link_html != ''):
             link_html = "<hr/><h3>%s</h3><ul>%s</ul>" % (_('Shared documents'), link_html)
         email_content = "<html><body>%s%s</body></html>" % (toHtml(self.body), link_html)
         for contact_email in email_list[:nb_to_send]:
             contact_id, email = contact_email.split(':')
             try:
                 contact = AbstractContact.objects.get(id=contact_id)
             except AbstractContact.DoesNotExist:
                 contact = None
             try:
                 send_email([email], self.subject, email_content, files=files if len(files) > 0 else None)
                 EmailSent.objects.create(message=self, contact=contact, email=email, date=timezone.now(), success=True)
             except Exception as error:
                 EmailSent.objects.create(message=self, contact=contact, email=email, date=timezone.now(), success=False, error=six.text_type(error))
         self.email_to_send = "\n".join(email_list[nb_to_send:])
         if self.email_to_send == '':
             self.status = 1
         self.save()
     return
示例#3
0
 def send_email(self):
     nb_sent, nb_failed = 0, 0
     if will_mail_send():
         email_content = "<html><body>%s</body></html>" % toHtml(self.body)
         for contact in self.get_contacts():
             if contact.email != '':
                 try:
                     send_email(
                         [contact.email], self.subject, email_content)
                     nb_sent += 1
                 except:
                     nb_failed += 1
     return nb_sent, nb_failed
示例#4
0
def convert_to_html(tagname, text, font_family="sans-serif", font_size=9, line_height=10, text_align='left'):
    try:
        xml_text = etree.XML(
            "<%(tagname)s>%(text)s</%(tagname)s>" % {'tagname': tagname, 'text': toHtml(text)})
        xml_text.attrib['font_family'] = font_family
        xml_text.attrib['font_size'] = "%d" % font_size
        xml_text.attrib['line_height'] = "%d" % line_height

        xml_text.attrib['text_align'] = text_align
        xml_text.attrib['spacing'] = "0.0"
    except etree.XMLSyntaxError:
        raise Exception(
            'convert_to_html error:tagname=%s text=%s' % (tagname, text))
    return xml_text
示例#5
0
 def define_email_message(self):
     if not hasattr(self, 'http_root_address'):
         raise LucteriosException(GRAVE, "No http_root_address")
     link_html = ""
     self._attache_files = []
     for doc in self.attachments.all():
         if self.doc_in_link:
             if doc.sharekey is None:
                 doc.change_sharekey(False)
                 doc.save()
             doc.set_context(self.http_root_address)
             link_html += "<li><a href='%s'>%s</a></li>" % (doc.shared_link,
                                                            doc.name)
         else:
             self._attache_files.append((doc.name, doc.content))
     if self.doc_in_link and (link_html != ''):
         link_html = "<hr/><h3>%s</h3><ul>%s</ul>" % (_('Shared documents'),
                                                      link_html)
     self._email_content = "<html><body>%s%s</body></html>" % (toHtml(
         self.body), link_html)