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/mail_shortcode.py | |
| 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/mail_shortcode.py')
| -rw-r--r-- | addons/mail/models/mail_shortcode.py | 20 |
1 files changed, 3 insertions, 17 deletions
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 |
