Browse Source

[IMP] autopep8

[IMP] more efficient sorting of algorithms
[IMP] improve readability of help strings
pull/78/head
Holger Brunn 12 years ago
parent
commit
6c68c1fb1c
  1. 26
      fetchmail_attach_from_folder/model/fetchmail_server.py
  2. 21
      fetchmail_attach_from_folder/model/fetchmail_server_folder.py

26
fetchmail_attach_from_folder/model/fetchmail_server.py

@ -29,6 +29,7 @@ from openerp.addons.fetchmail.fetchmail import logger
from openerp.tools.misc import UnquoteEvalContext from openerp.tools.misc import UnquoteEvalContext
from openerp.tools.safe_eval import safe_eval from openerp.tools.safe_eval import safe_eval
class fetchmail_server(Model): class fetchmail_server(Model):
_inherit = 'fetchmail.server' _inherit = 'fetchmail.server'
@ -42,7 +43,7 @@ class fetchmail_server(Model):
} }
def __init__(self, pool, cr): def __init__(self, pool, cr):
self._columns['object_id'].required=False
self._columns['object_id'].required = False
return super(fetchmail_server, self).__init__(pool, cr) return super(fetchmail_server, self).__init__(pool, cr)
def onchange_server_type( def onchange_server_type(
@ -50,8 +51,9 @@ class fetchmail_server(Model):
object_id=False): object_id=False):
retval = super( retval = super(
fetchmail_server, self).onchange_server_type(cr, uid, fetchmail_server, self).onchange_server_type(cr, uid,
ids, server_type, ssl, object_id)
retval['value']['state']='draft'
ids, server_type, ssl,
object_id)
retval['value']['state'] = 'draft'
return retval return retval
def fetch_mail(self, cr, uid, ids, context=None): def fetch_mail(self, cr, uid, ids, context=None):
@ -100,7 +102,7 @@ class fetchmail_server(Model):
msgdata[0][1], this.original) msgdata[0][1], this.original)
if self.pool.get('mail.message').search(cr, uid, [ if self.pool.get('mail.message').search(cr, uid, [
('message_id','=',mail_message['message-id'])]):
('message_id', '=', mail_message['message-id'])]):
continue continue
found_ids = matcher.search_matches( found_ids = matcher.search_matches(
@ -134,9 +136,8 @@ class fetchmail_server(Model):
partner_id = None partner_id = None
if folder.model_id.model == 'res.partner': if folder.model_id.model == 'res.partner':
partner_id = object_id partner_id = object_id
if self.pool.get(folder.model_id.model)._columns.\
has_key('partner_id'):
partner_id=self.pool.get(
if 'partner_id' in self.pool.get(folder.model_id.model)._columns:
partner_id = self.pool.get(
folder.model_id.model).browse( folder.model_id.model).browse(
cr, uid, object_id, context cr, uid, object_id, context
).partner_id.id ).partner_id.id
@ -161,14 +162,15 @@ class fetchmail_server(Model):
}, },
context) context)
if this.attach: if this.attach:
#TODO: create attachments
# TODO: create attachments
pass pass
if folder.delete_matching: if folder.delete_matching:
connection.store(msgid, '+FLAGS', '\\DELETED') connection.store(msgid, '+FLAGS', '\\DELETED')
def button_confirm_login(self, cr, uid, ids, context=None): def button_confirm_login(self, cr, uid, ids, context=None):
retval = super(fetchmail_server, self).button_confirm_login(cr, uid, retval = super(fetchmail_server, self).button_confirm_login(cr, uid,
ids, context)
ids,
context)
for this in self.browse(cr, uid, ids, context): for this in self.browse(cr, uid, ids, context):
this.write({'state': 'draft'}) this.write({'state': 'draft'})
@ -194,8 +196,8 @@ class fetchmail_server(Model):
if view_type == 'form': if view_type == 'form':
view = etree.fromstring( view = etree.fromstring(
result['fields']['folder_ids']['views']['form']['arch']) result['fields']['folder_ids']['views']['form']['arch'])
modifiers={}
docstr=''
modifiers = {}
docstr = ''
for algorithm in self.pool.get('fetchmail.server.folder')\ for algorithm in self.pool.get('fetchmail.server.folder')\
._get_match_algorithms().itervalues(): ._get_match_algorithms().itervalues():
for modifier in ['required', 'readonly']: for modifier in ['required', 'readonly']:
@ -205,7 +207,7 @@ class fetchmail_server(Model):
if modifiers[field][modifier]: if modifiers[field][modifier]:
modifiers[field][modifier].insert(0, '|') modifiers[field][modifier].insert(0, '|')
modifiers[field][modifier].append( modifiers[field][modifier].append(
("match_algorithm","==",algorithm.__name__))
("match_algorithm", "==", algorithm.__name__))
docstr += _(algorithm.name) + '\n' + _(algorithm.__doc__) + \ docstr += _(algorithm.name) + '\n' + _(algorithm.__doc__) + \
'\n\n' '\n\n'

21
fetchmail_attach_from_folder/model/fetchmail_server_folder.py

@ -18,12 +18,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
##############################################################################
########################################################################
from openerp.osv import fields from openerp.osv import fields
from openerp.osv.orm import Model from openerp.osv.orm import Model
from .. import match_algorithm from .. import match_algorithm
class fetchmail_server_folder(Model): class fetchmail_server_folder(Model):
_name = 'fetchmail.server.folder' _name = 'fetchmail.server.folder'
_rec_name = 'path' _rec_name = 'path'
@ -37,16 +38,17 @@ class fetchmail_server_folder(Model):
match_algorithm.base.base)]) match_algorithm.base.base)])
def _get_match_algorithms_sel(self, cr, uid, context=None): def _get_match_algorithms_sel(self, cr, uid, context=None):
algorithms=[]
algorithms = []
for cls in self._get_match_algorithms().itervalues(): for cls in self._get_match_algorithms().itervalues():
algorithms.append((cls.__name__, cls.name)) algorithms.append((cls.__name__, cls.name))
return tuple(sorted(algorithms, lambda a, b: cmp(a[0], b[0])))
algorithms.sort()
return algorithms
_columns = { _columns = {
'sequence': fields.integer('Sequence'), 'sequence': fields.integer('Sequence'),
'path': fields.char( 'path': fields.char(
'Path', size=256, help='The path to your mail ' 'Path', size=256, help='The path to your mail '
'folder. Typically would be something like \'INBOX.myfolder\'',
"folder. Typically would be something like 'INBOX.myfolder'",
required=True), required=True),
'model_id': fields.many2one( 'model_id': fields.many2one(
'ir.model', 'Model', required=True, 'ir.model', 'Model', required=True,
@ -56,12 +58,12 @@ class fetchmail_server_folder(Model):
help='The field in your model that contains the field to match ' help='The field in your model that contains the field to match '
'against.\n' 'against.\n'
'Examples:\n' 'Examples:\n'
'\'email\' if your model is res.partner, or '
'\'partner_id.email\' if you\'re matching sale orders'),
"'email' if your model is res.partner, or "
"'partner_id.email' if you're matching sale orders"),
'model_order': fields.char( 'model_order': fields.char(
'Order (model)', size=128, 'Order (model)', size=128,
help='Fields to order by, this mostly useful in conjunction ' help='Fields to order by, this mostly useful in conjunction '
'with \'Use 1st match\''),
"with 'Use 1st match'"),
'match_algorithm': fields.selection( 'match_algorithm': fields.selection(
_get_match_algorithms_sel, _get_match_algorithms_sel,
'Match algorithm', required=True, translate=True, 'Match algorithm', required=True, translate=True,
@ -70,14 +72,14 @@ class fetchmail_server_folder(Model):
'mail_field': fields.char( 'mail_field': fields.char(
'Field (email)', size=128, 'Field (email)', size=128,
help='The field in the email used for matching. Typically ' help='The field in the email used for matching. Typically '
'this is \'to\' or \'from\''),
"this is 'to' or 'from'"),
'server_id': fields.many2one('fetchmail.server', 'Server'), 'server_id': fields.many2one('fetchmail.server', 'Server'),
'delete_matching': fields.boolean( 'delete_matching': fields.boolean(
'Delete matches', 'Delete matches',
help='Delete matched emails from server'), help='Delete matched emails from server'),
'flag_nonmatching': fields.boolean( 'flag_nonmatching': fields.boolean(
'Flag nonmatching', 'Flag nonmatching',
help='Flag emails in the server that don\'t match any object '
help="Flag emails in the server that don't match any object "
'in OpenERP'), 'in OpenERP'),
'match_first': fields.boolean( 'match_first': fields.boolean(
'Use 1st match', 'Use 1st match',
@ -107,4 +109,3 @@ class fetchmail_server_folder(Model):
'view_type': 'form', 'view_type': 'form',
'view_mode': 'form', 'view_mode': 'form',
} }
Loading…
Cancel
Save