Migrate to python 3.

This commit is contained in:
Albert Cervera i Areny 2018-08-17 18:35:06 +02:00
parent d54fd2ddd1
commit d8beb61ebc
4 changed files with 10 additions and 14 deletions

View file

@ -5,7 +5,7 @@ from trytond.model import fields, ModelView
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateAction from trytond.wizard import Wizard, StateAction
from email.utils import parseaddr, formataddr, formatdate, make_msgid from email.utils import parseaddr, formataddr, formatdate, make_msgid
from email import Encoders from email import encoders
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.base import MIMEBase from email.mime.base import MIMEBase
@ -24,9 +24,8 @@ except ImportError:
__all__ = ['Activity', 'ActivityReplyMail'] __all__ = ['Activity', 'ActivityReplyMail']
class Activity: class Activity(metaclass=PoolMeta):
__name__ = 'activity.activity' __name__ = 'activity.activity'
__metaclass__ = PoolMeta
mail = fields.Many2One('electronic.mail', "Related Mail", readonly=True, mail = fields.Many2One('electronic.mail', "Related Mail", readonly=True,
ondelete='CASCADE') ondelete='CASCADE')
@ -222,7 +221,7 @@ class Activity:
).split('/', 1) ).split('/', 1)
attachment = MIMEBase(maintype, subtype) attachment = MIMEBase(maintype, subtype)
attachment.set_payload(data) attachment.set_payload(data)
Encoders.encode_base64(attachment) encoders.encode_base64(attachment)
attachment.add_header( attachment.add_header(
'Content-Disposition', 'attachment', filename=filename) 'Content-Disposition', 'attachment', filename=filename)
attachment.add_header( attachment.add_header(
@ -274,7 +273,7 @@ class Activity:
values = [] values = []
attachs = {} attachs = {}
for server_id, mails in received_mails.iteritems(): for server_id, mails in list(received_mails.items()):
servers = IMAPServer.browse([server_id]) servers = IMAPServer.browse([server_id])
server = servers and servers[0] or None server = servers and servers[0] or None
for mail in mails: for mail in mails:
@ -411,7 +410,7 @@ class Activity:
}) })
try: try:
Attachment.create(values) Attachment.create(values)
except Exception, e: except Exception as e:
logging.getLogger('Activity Mail').info( logging.getLogger('Activity Mail').info(
'The mail (%s) has attachments but they are not ' 'The mail (%s) has attachments but they are not '
'possible to attach to the activity (%s).\n\n%s' % 'possible to attach to the activity (%s).\n\n%s' %
@ -419,10 +418,9 @@ class Activity:
return mails return mails
class ActivityReplyMail(Wizard): class ActivityReplyMail(Wizard, metaclass=PoolMeta):
'Activity Reply Mail' 'Activity Reply Mail'
__name__ = 'activity.activity.replymail' __name__ = 'activity.activity.replymail'
__metaclass__ = PoolMeta
start_state = 'open_' start_state = 'open_'
open_ = StateAction('activity.act_activity_activity') open_ = StateAction('activity.act_activity_activity')

View file

@ -4,10 +4,9 @@ from trytond.pool import Pool, PoolMeta
from trytond.model import fields from trytond.model import fields
__all__ = ['IMAPServer'] __all__ = ['IMAPServer']
__metaclass__ = PoolMeta
class IMAPServer: class IMAPServer(metaclass=PoolMeta):
__name__ = 'imap.server' __name__ = 'imap.server'
employee = fields.Many2One('company.employee', 'Default Employee') employee = fields.Many2One('company.employee', 'Default Employee')

View file

@ -4,7 +4,7 @@
from setuptools import setup from setuptools import setup
import re import re
import os import os
import ConfigParser import configparser
MODULE = 'electronic_mail_activity' MODULE = 'electronic_mail_activity'
PREFIX = 'nantic' PREFIX = 'nantic'
@ -24,7 +24,7 @@ def get_require_version(name):
major_version, minor_version + 1) major_version, minor_version + 1)
return require return require
config = ConfigParser.ConfigParser() config = configparser.ConfigParser()
config.readfp(open('tryton.cfg')) config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton')) info = dict(config.items('tryton'))
for key in ('depends', 'extras_depend', 'xml'): for key in ('depends', 'extras_depend', 'xml'):

View file

@ -4,10 +4,9 @@ from trytond.pool import PoolMeta
from trytond.model import fields from trytond.model import fields
__all__ = ['User'] __all__ = ['User']
__metaclass__ = PoolMeta
class User: class User(metaclass=PoolMeta):
__name__ = "res.user" __name__ = "res.user"
smtp_server = fields.Many2One('smtp.server', 'SMTP Server', smtp_server = fields.Many2One('smtp.server', 'SMTP Server',