diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-06-04 10:01:34 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-06-04 10:01:34 +0200 |
| commit | 6a16fd4a786fc7b2e033e306d22bcbc235a4772d (patch) | |
| tree | d5df66ce9449d046464e1151d064d97f64c2e71e /addons/fetchmail | |
| parent | fe0115f13abc8bb6d6fc8b1b8d01220e580e4997 (diff) | |
| parent | 37e59e65b393034b4cc3fe79521be9525b650960 (diff) | |
[MERGE] Merged with main addons.
bzr revid: tde@openerp.com-20120604080134-t1zg2sv0jpmhbyge
Diffstat (limited to 'addons/fetchmail')
| -rw-r--r-- | addons/fetchmail/fetchmail.py | 2 | ||||
| -rw-r--r-- | addons/fetchmail/res_config.py | 125 |
2 files changed, 50 insertions, 77 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py index 51702cf28fe..93ebd063051 100644 --- a/addons/fetchmail/fetchmail.py +++ b/addons/fetchmail/fetchmail.py @@ -53,7 +53,7 @@ class fetchmail_server(osv.osv): 'state':fields.selection([ ('draft', 'Not Confirmed'), ('done', 'Confirmed'), - ], 'State', select=True, readonly=True), + ], 'Status', select=True, readonly=True), 'server' : fields.char('Server Name', size=256, readonly=True, help="Hostname or IP of the mail server", states={'draft':[('readonly', False)]}), 'port' : fields.integer('Port', readonly=True, states={'draft':[('readonly', False)]}), 'type':fields.selection([ diff --git a/addons/fetchmail/res_config.py b/addons/fetchmail/res_config.py index 2b4072a63c3..f7dade6ae33 100644 --- a/addons/fetchmail/res_config.py +++ b/addons/fetchmail/res_config.py @@ -25,99 +25,72 @@ class fetchmail_config_settings(osv.osv_memory): """ This wizard can be inherited in conjunction with 'res.config.settings', in order to define fields that configure a fetchmail server. - It relies on the following convention on a set of fields:: + It relies on the following convention on the object:: - class my_config_wizard(osv.osv_memory): + class my_config_settings(osv.osv_memory): _name = 'my.settings' - _inherits = ['res.config.settings', 'fetchmail.config.settings'] + _inherit = ['res.config.settings', 'fetchmail.config.settings'] _columns = { - 'fetchmail_X': fields.boolean(..., fetchmail_model='my.model', fetchmail_name='Blah'), - 'X_server': fields.char('Server Name', size=256), - 'X_port': fields.integer('Port'), - 'X_type': fields.selection( - [('pop', 'POP Server'), ('imap', 'IMAP Server'), ('local', 'Local Server')], - 'Server Type'), - 'X_is_ssl': fields.boolean('SSL/TLS'), - 'X_user': fields.char('Username', size=256), - 'X_password': fields.char('Password', size=1024), + 'fetchmail_stuff': fields.boolean(..., readonly=True, + fetchmail_model='my.stuff', fetchmail_name='Incoming Stuff'), } - The method ``get_default_fetchmail_servers`` retrieves the current fetchmail configuration - for all fields that start with 'fetchmail_'. It looks up configurations that match the - given model name (``fetchmail_model``). The method ``set_fetchmail_servers`` updates the - fetchmail configurations by following the same conventions. Both methods are called - automatically by the methods of the model 'res.config.settings'. + def configure_fetchmail_stuff(self, cr, uid, ids, context=None): + return self.configure_fetchmail(cr, uid, 'fetchmail_stuff', context) - The onchange method ``onchange_fetchmail`` can be used to react on changes on the fields - 'X_type' and 'X_is_ssl'. Its first parameter is the fields' prefix (here 'X'). + and in the form view:: + + <field name="fetchmail_stuff"/> + <button type="object" name="configure_fetchmail_stuff"/> + + The method ``get_default_fetchmail`` determines the value of all fields that start + with 'fetchmail_'. It looks up fetchmail server configurations that match the given + model name (``fetchmail_model``) and are active. + + The button action ``configure_fetchmail_stuff`` is caught by the object, and calls + automatically the method ``configure_fetchmail``; it opens the fetchmail server + configuration form for the corresponding field. """ _name = 'fetchmail.config.settings' - def get_default_fetchmail_servers(self, cr, uid, fields, context=None): + def get_default_fetchmail(self, cr, uid, fields, context=None): + """ determine the value of all fields like 'fetchmail_XXX' """ ir_model = self.pool.get('ir.model') fetchmail_server = self.pool.get('fetchmail.server') - fetchmail_fields = [f for f in self._columns if f.startswith('fetchmail_')] + fetchmail_fields = [f for f in fields if f.startswith('fetchmail_')] res = {} - for field in fetchmail_fields: - model_name = self._columns[field].fetchmail_model + for f in fetchmail_fields: + model_name = self._columns[f].fetchmail_model model_id = ir_model.search(cr, uid, [('model', '=', model_name)])[0] server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'done')]) - if server_ids: - server = fetchmail_server.browse(cr, uid, server_ids[0], context) - prefix = field[10:] - res.update({ - field: True, - prefix + '_server': server.server, - prefix + '_port': server.port, - prefix + '_type': server.type, - prefix + '_is_ssl': server.is_ssl, - prefix + '_user': server.user, - prefix + '_password': server.password, - }) + res[f] = bool(server_ids) return res - def set_fetchmail_servers(self, cr, uid, ids, context): - ir_model = self.pool.get('ir.model') - fetchmail_server = self.pool.get('fetchmail.server') - fetchmail_fields = [f for f in self._columns if f.startswith('fetchmail_')] - config = self.browse(cr, uid, ids[0], context) - for field in fetchmail_fields: - model_name = self._columns[field].fetchmail_model - model_id = ir_model.search(cr, uid, [('model', '=', model_name)])[0] - server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'done')]) - if config[field]: - prefix = field[10:] - values = { - 'server': config[prefix + '_server'], - 'port': config[prefix + '_port'], - 'type': config[prefix + '_type'], - 'is_ssl': config[prefix + '_is_ssl'], - 'user': config[prefix + '_user'], - 'password': config[prefix + '_password'], - } - if not server_ids: - values.update({ - 'name': getattr(self._columns[field], 'fetchmail_name', model_name), - 'object_id': model_id, - }) - server_ids = [fetchmail_server.create(cr, uid, values, context=context)] - else: - server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id)], context=context) - fetchmail_server.write(cr, uid, server_ids, values, context=context) - fetchmail_server.button_confirm_login(cr, uid, server_ids, context) - else: - fetchmail_server.set_draft(cr, uid, server_ids, context) - - def onchange_fetchmail(self, cr, uid, ids, prefix, server_type, ssl, context=None): - values = {} - if server_type == 'pop': - values[prefix + '_port'] = ssl and 995 or 110 - elif server_type == 'imap': - values[prefix + '_port'] = ssl and 993 or 143 + def configure_fetchmail(self, cr, uid, field, context=None): + """ open the form view of the fetchmail.server to configure """ + action = { + 'type': 'ir.actions.act_window', + 'res_model': 'fetchmail.server', + 'view_mode': 'form', + } + model_name = self._columns[field].fetchmail_model + model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', model_name)])[0] + server_ids = self.pool.get('fetchmail.server').search(cr, uid, [('object_id', '=', model_id)]) + if server_ids: + action['res_id'] = server_ids[0] else: - values[prefix + '_server'] = False - values[prefix + '_port'] = 0 - return {'value': values} + action['context'] = { + 'default_name': self._columns[field].fetchmail_name, + 'default_object_id': model_id, + } + return action + + def __getattr__(self, name): + """ catch calls to 'configure_fetchmail_XXX' """ + if name.startswith('configure_fetchmail_'): + return (lambda cr, uid, ids, context=None: + self.configure_fetchmail(cr, uid, name[10:], context)) + return super(fetchmail_config_settings, self).__getattr__(name) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
