trytond-electronic_mail_template / electronic_mail.py

Diff from to

electronic_mail.py

 from trytond.pool import Pool
 from trytond.pyson import Eval
 
+__all__ = ['ElectronicMail']
 
 class ElectronicMail(ModelSQL, ModelView):
     "E-Mail module extended to suit inbuilt reading and templating"
-    _name = 'electronic.mail'
+    __name__ = 'electronic.mail'
 
+    subject = fields.Char('Subject', translate=True)
     body_html = fields.Function(
         fields.Text('HTML (BODY)'), 'get_email_body')
     body_plain = fields.Function(
         fields.Text('Plain Text (BODY)'), 'get_email_body')
 
-    def __init__(self):
-        super(ElectronicMail, self).__init__()
-        self._buttons.update({
+    @classmethod
+    def __setup__(cls):
+        super(ElectronicMail, cls).__setup__()
+        cls._buttons.update({
                 'send_mail': {
                     'invisible': Eval('body_plain') == '',
                     },
                 })
 
-    def get_email_body(self, ids, names):
+    def get_email_body(self, name):
         """Returns the email body
         """
-        result = dict.fromkeys(names)
-        for name in names:
-            result[name] = defaultdict(unicode).fromkeys(ids)
-
-        for email in self.browse(ids):
-            message = message_from_string(self._get_email(email))
-            for part in message.walk():
-                content_type = part.get_content_type()
-                for name in names:
-                    if content_type == 'text/' + name.lstrip('body_'):
-                        result[name][email.id] = part.get_payload()
+        result = ''
+        test = defaultdict(unicode).fromkeys(name)
+        message = message_from_string(self._get_email(self))
+        for part in message.walk():
+            content_type = part.get_content_type()
+            if content_type == 'text/plain':
+                result = part.get_payload()
         return result
 
-    def check_xml_record(self, ids, values):
+    @classmethod
+    def check_xml_record(cls, records, values):
         '''It should be possible to overwrite templates'''
         return True
 
             template_obj.send_email(email_id)
         return True
 
-ElectronicMail()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.