diff options
| author | Aaron Bohy <aab@odoo.com> | 2016-04-29 15:22:23 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2016-05-03 10:34:41 +0200 |
| commit | 2264378739520fdc8b4c3967eebd4b35fff9f7fc (patch) | |
| tree | 5b6cb0eb3f7d66f4a1eecf8bd7f2c39a08887ca0 /addons/mail/models | |
| parent | 29483ffe2eed65eee66ea49053ae5c8fda221a6b (diff) | |
[ADD] im_livechat,mail: canned responses support
Use the mention mechanism of the composer to autocomplete on canned responses
(keyword :) with fuzzy search.
Directly perform the string replacement in the composer, instead of
server-side as before.
Add a menu item to access an editable list view to create and edit canned
responses.
Add two canned responses as demo data.
Diffstat (limited to 'addons/mail/models')
| -rw-r--r-- | addons/mail/models/mail_channel.py | 2 | ||||
| -rw-r--r-- | addons/mail/models/mail_shortcode.py | 20 |
2 files changed, 3 insertions, 19 deletions
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 41fc8e0d551..02607bfcbc3 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -213,8 +213,6 @@ class Channel(models.Model): def message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False, attachments=None, content_subtype='html', **kwargs): # auto pin 'direct_message' channel partner self.filtered(lambda channel: channel.channel_type == 'chat').mapped('channel_last_seen_partner_ids').write({'is_pinned': True}) - # apply shortcode (text only) subsitution - body = self.env['mail.shortcode'].apply_shortcode(body, shortcode_type='text') message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs) return message diff --git a/addons/mail/models/mail_shortcode.py b/addons/mail/models/mail_shortcode.py index 478fb7be2ef..8c659a1f134 100644 --- a/addons/mail/models/mail_shortcode.py +++ b/addons/mail/models/mail_shortcode.py @@ -15,12 +15,12 @@ class MailShortcode(models.Model): _name = 'mail.shortcode' _description = 'Canned Response / Shortcode' - source = fields.Char('Shortcut', required=True, index=True, help="The shortcut which must be replace in the Chat Messages") - substitution = fields.Char('Substitution', required=True, index=True, help="The escaped html code replacing the shortcut") + source = fields.Char('Shortcut', required=True, index=True, help="The shortcut which must be replaced in the Chat Messages") + substitution = fields.Text('Substitution', required=True, index=True, help="The escaped html code replacing the shortcut") description = fields.Char('Description') shortcode_type = fields.Selection([('image', 'Smiley'), ('text', 'Canned Response')], required=True, default='text', help="* Smiley are only used for HTML code to display an image "\ - "* Text (default value) is use to substitute text with another text") + "* Text (default value) is used to substitute text with another text") @api.model def create(self, values): @@ -43,17 +43,3 @@ class MailShortcode(models.Model): if is_img_tag: return substitution return cgi.escape(substitution) - - @api.model - def apply_shortcode(self, message, shortcode_type=None): - """ Apply the substitution on the given text - :param message : the text where the shortcode will be applied - :param shortcode_type : shortcode type that should be applied during the substitution - """ - domain = [] - if shortcode_type: - domain.append(('shortcode_type', '=', shortcode_type)) - for shortcode in self.search(domain): - regex = '(?:^|\s)(%s)(?:\s|$)' % re.escape(shortcode.source) - message = re.sub(regex, " " + shortcode.substitution + " ", message) - return message |
