コード例 #1
0
 def render_signature_id(self):
     if not self.signature_id:
         return
     mako = mako_template_env.from_string(tools.ustr(self.signature_id.template))
     html = mako.render({"user": self})
     if html != self.signature:
         self.signature = html
コード例 #2
0
 def render_signature_id(self):
     for rec in self:
         if not rec.signature_id:
             continue
         mako = mako_template_env.from_string(tools.ustr(rec.signature_id.template))
         html = mako.render({'user': rec})
         if html != rec.signature:
             rec.signature = html
コード例 #3
0
    def _eval_aeroo_attachment_filename(self, filename, record):
        """Evaluate the given attachment filename for the given record.

        :param filename: the filename mako template
        :param record: the record for which to evaluate the filename
        :return: the rendered attachment filename
        """
        template = mako_template_env.from_string(tools.ustr(filename))
        context = {'o': record.with_context()}
        context.update(self._get_aeroo_extra_functions())
        return template.render(context)
コード例 #4
0
ファイル: merge_user.py プロジェクト: vidtsin/odoo-users
    def do_pre_merge_from_users(self):
        """ Send email to ask permission to do merge or do merge directly if the
        email of user to merge
        is the same of the main user
        """
        self.ensure_one()
        wzr_brw = self.sudo()
        parent_brw = wzr_brw.user_id
        body = '''
  <div cellspacing="10" style="font-family:verdana;background-color:#C6DEFF;">
      <div>Result:</div>
      <div>${r.get('message')}</div>
      <div>${r.get('request')}</div>
  </div>
        '''
        template = mako_template_env.from_string(tools.ustr(body))
        if wzr_brw.user_ids:
            if all([((i.user_id.login == parent_brw.login) or
                     (i.user_id.email == parent_brw.email)) and True or False
                    for i in wzr_brw.user_ids]):
                fuse_obj = self.env['merge.fuse.wizard'].sudo()
                user_ids = [i.user_id.id for i in wzr_brw.user_ids]
                user_ids.insert(0, parent_brw.id)
                fuse_obj.\
                    with_context({'active_model': 'res.users',
                                  'active_ids': user_ids}).create({})
                wzr_brw.write({'executed': True})
                body = template.\
                    render(
                        {'r':
                         {'message': _('Process Completed'),
                          'request': _(
                              'Process finished the users were merged')}})
                self.update({'message': body})
                return True

            token = self.sudo().random_token()
            wzr_brw.write({
                'access_token': token,
                'user_ids': [(0, 0, {
                    'user_id': wzr_brw.user_id.id
                })]
            })
            user_mails = []
            for i in wzr_brw.user_ids:
                if i.user_id.id not in user_mails:
                    self.send_emails(self._uid, i.user_id.id, token,
                                     wzr_brw.id)
                user_mails.append(i.user_id.id)
            if wzr_brw.user_id.id not in user_mails:
                self.send_emails(self._uid, wzr_brw.user_id.id, token,
                                 wzr_brw.id)
コード例 #5
0
    def produce(self, records):
        """Produce the content of a message

        This component uses Jinja2 from a template file to produce
        the message. The :meth:`render_context` method must be overridden
        to return the values to fill in the template.
        For safetc the odoo sandboxed Jinja environment is used.
        """
        template_txt = self._template
        mako_template_env.variable_start_string = "{{"
        mako_template_env.variable_end_string = "}}"
        mako_template_env.block_start_string = "{%"
        mako_template_env.block_end_string = "%}"
        mako_template_env.comment_start_string = "{#"
        mako_template_env.comment_end_string = "#}"
        template = mako_template_env.from_string(ustr(template_txt))
        template.globals['format_datetime'] = self._format_datetime
        return template.render(**self._render_context(records))
コード例 #6
0
ファイル: merge_user.py プロジェクト: vidtsin/odoo-users
    def onchange_search(self):
        """ Search user with the same email sent from view and return the result or
        a message
        :type: String with the field used to find user, this may be name or
        email
        :param: String with the name or email used to find user with same
        Criteria
        @user: User ID of the main user
        return all user found and a message reporting it
        """
        user_obj = self.env['res.users']
        parent_brw = self.user_id
        user = []
        users = []
        res = {'value': {}}
        body = '''
  <div cellspacing="10" style="font-family:verdana;background-color:#C6DEFF;">
      <div>Result:</div>
      <div>${r.get('message')}</div>
      <div>${r.get('request')}</div>
  </div>
        '''
        template = mako_template_env.from_string(tools.ustr(body))
        # pylint: disable=W1401
        if self.search_c and self.type == 'email' and \
                re.match("[^@]+@[^@]+\.[^@]+", self.search_c) or self.search_c:
            users += user_obj.sudo().\
                search([('%s' % self.type, '=', self.search_c)]).ids
        old_token = self.sudo().search([('user_id', 'in', users),
                                        ('executed', '=', False)])
        if old_token:
            old_token.unlink()

        users = list(set(users))
        if users:
            user += [{
                'user_id':
                i.id,
                'same_email': (i.email == parent_brw.email and True or False)
            } for i in user_obj.sudo().browse(users)]
            body = template.render({
                'r': {
                    'message':
                    _('User Found'),
                    'request':
                    _('Please press the Send '
                      'Mail button to send '
                      'the Merge request '
                      'for this user')
                }
            })
            res['value'] = {'message': body}
            res['value'].update({'user_ids': user})
        else:
            if self.search_c:
                body = template.\
                    render({'r': {'message': _('User not Found'),
                                  'request': _('The value filled out '
                                               'in the field '
                                               'was not found, please '
                                               'check it and try again')}})
                res['value'] = {'message': body}

        for i in self.user_ids:
            if i and i[0] == 0 and not i[2].get('user_id', 0) in users:
                user += [i[2]]
        res['value'].update({'user_ids': user})

        self.update(res.get('value'))
コード例 #7
0
ファイル: merge_user.py プロジェクト: vidtsin/odoo-users
    def send_emails(self, main_id, user_id, action, res_id):
        """ Send an email to ask permission to do merge with users that have the
        same email account
        :param user_id: User id that receives the notification mail
        :param action_id: String with the token of the record created
        :param res_id: Id of record created to do merge
        """
        mail_mail = self.env['mail.mail']
        partner_obj = self.env['res.partner'].sudo()
        user_obj = self.env['res.users'].sudo()
        user = user_obj.browse(user_id)
        main_user = user_obj.browse(main_id)
        data_obj = self.env['ir.model.data']
        url = partner_obj.browse(user.partner_id.id).\
            _get_signup_url_for_action(action='',
                                       res_id=res_id,
                                       model='merge.user.for.login',).\
            get(user.partner_id.id)
        base_url = self.env['ir.config_parameter'].sudo().\
            get_param('web.base.url', default='')
        url = '%s/do_merge/execute_merge?token=%s' % (base_url, action)
        if not user.login:
            raise UserError(
                _('Email Required'),
                _('The current user must have an '
                  'email address configured in '
                  'User Preferences to be able '
                  'to send outgoing emails.'))

        #  TODO: also send an HTML version of this mail
        email_to = user.login
        subject = user.name
        template_obj = data_obj.get_object('auth_multi',
                                           'merge_proposal_template')
        body = template_obj.body_html
        body_dict = {
            'r': {
                'tittle':
                _('Merge Proposal'),
                'access':
                _('Access to Merge'),
                'url':
                url,
                'base_url':
                base_url,
                'genereted':
                _('Generated By:'),
                'name':
                main_user.name,
                'message':
                _('If you are disagree ignore '
                  'this email Contact with your administrator'),
                'user': (_('Dear ') + user.name),
                'message2':
                _('You have a request to join this '
                  'user. If you agree do click '
                  'on the access link'),
            }
        }
        template = mako_template_env.from_string(tools.ustr(body))
        body = template.render(body_dict)
        mail_mail.create({
            'email_from': user.login,
            'email_to': email_to,
            'subject': subject,
            'body_html': body
        }).send()
        # force direct delivery, as users expect instant notification
        return True
コード例 #8
0
 def render_body_html(self, template, partner, order):
     mako = mako_template_env.from_string(tools.ustr(template))
     html = mako.render({"partner": partner, "order": order})
     html = strip_tags(html)
     return html