Flake8 done

This commit is contained in:
Valentin Chemiere 2015-03-24 17:08:32 +01:00
parent 0932cb1e73
commit f40146b110
2 changed files with 36 additions and 52 deletions

View File

@ -27,44 +27,24 @@ import base64
class IrAttachmentMetadata(models.Model): class IrAttachmentMetadata(models.Model):
_inherit = "ir.attachment.metadata" _inherit = "ir.attachment.metadata"
fetchmail_server_id = fields.Many2one('fetchmail.server', string='Email Server') fetchmail_server_id = fields.Many2one('fetchmail.server',
string='Email Server')
def message_process(self, cr, uid, model, message, custom_values=None, def message_process(self, cr, uid, model, message, custom_values=None,
save_original=False, strip_attachments=False, save_original=False, strip_attachments=False,
thread_id=None, context=None): thread_id=None, context=None):
print "message process"
if context is None: if context is None:
context = {} context = {}
context['no_post'] = True context['no_post'] = True
return True return True
# return super(IrAttachmentMetadata, self).message_process(self, cr, uid,
# model,
# message,
# custom_values=custom_values,
# save_original=save_original,
# strip_attachments=strip_attachments,
# thread_id=thread_id,
# context=context
# )
def message_post(self, cr, uid, thread_id, body='', subject=None, type='notification', def message_post(self, cr, uid, thread_id, body='', subject=None,
subtype=None, parent_id=False, attachments=None, type='notification', subtype=None, parent_id=False,
content_subtype='html', context=None, **kwargs): attachments=None, content_subtype='html', context=None,
print "message post" **kwargs):
if context.get('no_post'): if context.get('no_post'):
return None return None
return True return True
# return super(IrAttachmentMetadata, self).message_post(cr, uid, thread_id,
# body=body,
# subject=subject,
# type='notification',
# subtype=subtype,
# parent_id=parent_id,
# attachments=attachments,
# content_subtype=content_subtype,
# context=context,
# **kwargs)
@api.model @api.model
def _get_attachment_metadata_data(self, condition, msg, att): def _get_attachment_metadata_data(self, condition, msg, att):
@ -83,21 +63,23 @@ class IrAttachmentMetadata(models.Model):
@api.model @api.model
def prepare_data_from_basic_condition(self, condition, msg): def prepare_data_from_basic_condition(self, condition, msg):
vals = {} vals = {}
if condition.from_email in msg['from'] and condition.mail_subject in msg['subject']: if (condition.from_email in msg['from']
and condition.mail_subject in msg['subject']):
for att in msg['attachments']: for att in msg['attachments']:
if condition.file_extension in att[0]: if condition.file_extension in att[0]:
vals = self._get_attachment_metadata_data(condition, msg, att) vals = self._get_attachment_metadata_data(condition,
msg, att)
break break
return vals return vals
@api.model @api.model
def _prepare_data_for_attachment_metadata(self, msg): def _prepare_data_for_attachment_metadata(self, msg):
"""Method to prepare the data for creating a attachment metadata. """Method to prepare the data for creating a attachment metadata.
:param msg: a dictionnary with the email data :param msg: a dictionnary with the email data
:type: dict :type: dict
:return: a list of dictionnary that containt the attachment metadata data :return: a list of dictionnary that containt
the attachment metadata data
:rtype: list :rtype: list
""" """
res = [] res = []
@ -124,11 +106,10 @@ class IrAttachmentMetadata(models.Model):
default = self._context.get('default_attachment_metadata_vals') default = self._context.get('default_attachment_metadata_vals')
if default: if default:
for key in default: for key in default:
if not key in vals: if key not in vals:
vals[key] = default[key] vals[key] = default[key]
created_ids.append(self.create(vals)) created_ids.append(self.create(vals))
self._cr.commit() self._cr.commit()
#self._context['created_ids'] = created_ids
return created_ids[0].id return created_ids[0].id
return None return None
@ -147,13 +128,13 @@ class IrAttachmentMetadataCondition(models.Model):
from_email = fields.Char(string='Email', size=64) from_email = fields.Char(string='Email', size=64)
mail_subject = fields.Char(size=64) mail_subject = fields.Char(size=64)
type = fields.Selection( type = fields.Selection(
selection='_get_attachment_metadata_condition_type', selection='_get_attachment_metadata_condition_type',
help="Create your own type if the normal type \ help="Create your own type if the normal type \
do not correspond to your need", do not correspond to your need",
required=True, required=True,
default='normal' default='normal'
) )
file_extension = fields.Char(size=64, file_extension = fields.Char(size=64,
help="File extension or file name", help="File extension or file name",
required=True) required=True)
server_id = fields.Many2one('fetchmail.server', string='Server Mail') server_id = fields.Many2one('fetchmail.server', string='Server Mail')

View File

@ -35,15 +35,19 @@ class fetchmail_server(models.Model):
return self.get_file_type() return self.get_file_type()
def company_default_get(self): def company_default_get(self):
company_id = self.env['res.company']._company_default_get('fetchmail.server') company_id = (self.env['res.company'].
_company_default_get('fetchmail.server'))
return self.env['res.company'].browse(company_id) return self.env['res.company'].browse(company_id)
file_type = fields.Selection(selection='_get_file_type', file_type = fields.Selection(
help='The file type will show some special option') selection='_get_file_type',
company_id = fields.Many2one('res.company', string='Company', help='The file type will show some special option')
# required=True, company_id = fields.Many2one(
default=company_default_get 'res.company',
) #Why this field do not exist by default? string='Company',
required=True,
default=company_default_get
) # Why this field do not exist by default?
attachment_metadata_condition_ids = fields.One2many( attachment_metadata_condition_ids = fields.One2many(
'ir.attachment.metadata.condition', 'server_id', string='Attachment') 'ir.attachment.metadata.condition', 'server_id', string='Attachment')
@ -61,6 +65,5 @@ class fetchmail_server(models.Model):
@api.multi @api.multi
def fetch_mail(self): def fetch_mail(self):
for server in self: for server in self:
ctx = server.get_context_for_server()
super(fetchmail_server, server).fetch_mail() super(fetchmail_server, server).fetch_mail()
return True return True