Ejemplo n.º 1
0
 def _format_plaintext_batchmodify(self, event):
     """Format batch ticket change notification e-mail (untranslated)"""
     with translation_deactivated():
         tickets = sort_tickets_by_priority(self.env, event.target)
         changes_descr = '\n'.join('%s to %s' % (prop, val)
                                   for prop, val
                                   in event.new_values.iteritems())
         tickets_descr = ', '.join('#%s' % t for t in tickets)
         link = self.env.abs_href.query(id=','.join(str(t) for t in tickets))
         data = Chrome(self.env).populate_data(None, {
             'CRLF': CRLF,
             'tickets_descr': tickets_descr,
             'changes_descr': changes_descr,
             'comment': event.comment,
             'action': event.action,
             'author': event.author,
             'ticket_query_link': link,
         })
         return self._format_body(data, 'batch_ticket_notify_email.txt')
Ejemplo n.º 2
0
    def _format_plaintext_attachment(self, event):
        """Format ticket attachment notification e-mail (untranslated)"""
        ticket = event.target
        added = event.category == 'attachment added'
        newticket = False
        link = self.env.abs_href.ticket(ticket.id)
        author = event.attachment.author
        with translation_deactivated(ticket):
            changes_body = wrap(
                " * Attachment \"%s\" %s." %
                (event.attachment.filename, "added" if added else "removed"),
                self.COLS, ' ', ' ', '\n', self.ambiwidth) + "\n"
            if event.attachment.description:
                changes_body += "\n" + wrap(event.attachment.description,
                                            self.COLS, ' ', ' ', '\n',
                                            self.ambiwidth)

            ticket_values = ticket.values.copy()
            ticket_values['id'] = ticket.id
            ticket_values['description'] = wrap(ticket_values.get(
                'description', ''),
                                                self.COLS,
                                                initial_indent=' ',
                                                subsequent_indent=' ',
                                                linesep='\n',
                                                ambiwidth=self.ambiwidth)
            ticket_values['new'] = newticket
            ticket_values['link'] = link

            data = Chrome(self.env).populate_data(
                None, {
                    'CRLF': CRLF,
                    'ticket_props': self._format_props(ticket),
                    'ticket_body_hdr': self._format_hdr(ticket),
                    'ticket': ticket_values,
                    'changes_body': changes_body,
                    'changes_descr': '',
                    'change': {
                        'author': self._format_author(author)
                    },
                })
            return self._format_body(data, 'ticket_notify_email.txt')
Ejemplo n.º 3
0
    def _format_plaintext(self, event):
        """Format ticket change notification e-mail (untranslated)"""
        ticket = event.target
        newticket = event.category == 'created'
        with translation_deactivated(ticket):
            link = self.env.abs_href.ticket(ticket.id)

            changes_body = ''
            changes_descr = ''
            change_data = {}
            if not newticket and event.time:  # Ticket change
                from trac.ticket.web_ui import TicketModule
                for change in TicketModule(self.env) \
                              .grouped_changelog_entries(ticket,
                                                         when=event.time):
                    if not change['permanent']:  # attachment with same time...
                        continue
                    author = change['author']
                    change_data.update({
                        'author': self._format_author(author),
                        'comment': wrap(change['comment'], self.COLS, ' ', ' ',
                                        '\n', self.ambiwidth)
                    })
                    link += '#comment:%s' % str(change.get('cnum', ''))
                    for field, values in change['fields'].iteritems():
                        old = values['old']
                        new = values['new']
                        newv = ''
                        if field == 'description':
                            new_descr = wrap(new, self.COLS, ' ', ' ', '\n',
                                             self.ambiwidth)
                            old_descr = wrap(old, self.COLS, '> ', '> ', '\n',
                                             self.ambiwidth)
                            old_descr = old_descr.replace(2 * '\n', '\n' + '>' +
                                                          '\n')
                            cdescr = '\n'
                            cdescr += 'Old description:' + 2 * '\n' + old_descr + \
                                      2 * '\n'
                            cdescr += 'New description:' + 2 * '\n' + new_descr + \
                                      '\n'
                            changes_descr = cdescr
                        elif field == 'cc':
                            addcc, delcc = self._diff_cc(old, new)
                            chgcc = ''
                            if delcc:
                                chgcc += wrap(" * cc: %s (removed)" %
                                              ', '.join(delcc),
                                              self.COLS, ' ', ' ', '\n',
                                              self.ambiwidth) + '\n'
                            if addcc:
                                chgcc += wrap(" * cc: %s (added)" %
                                              ', '.join(addcc),
                                              self.COLS, ' ', ' ', '\n',
                                              self.ambiwidth) + '\n'
                            if chgcc:
                                changes_body += chgcc
                        else:
                            if field in ['owner', 'reporter']:
                                old = self._format_author(old)
                                new = self._format_author(new)
                            elif field in ticket.time_fields:
                                format = ticket.fields.by_name(field) \
                                                      .get('format')
                                old = self._format_time_field(old, format)
                                new = self._format_time_field(new, format)
                            newv = new
                            length = 7 + len(field)
                            spacer_old, spacer_new = ' ', ' '
                            if len(old + new) + length > self.COLS:
                                length = 5
                                if len(old) + length > self.COLS:
                                    spacer_old = '\n'
                                if len(new) + length > self.COLS:
                                    spacer_new = '\n'
                            chg = '* %s: %s%s%s=>%s%s' \
                                  % (field, spacer_old, old,
                                     spacer_old, spacer_new, new)
                            chg = chg.replace('\n', '\n' + length * ' ')
                            chg = wrap(chg, self.COLS, '', length * ' ', '\n',
                                       self.ambiwidth)
                            changes_body += ' %s%s' % (chg, '\n')
                        if newv:
                            change_data[field] = {'oldvalue': old,
                                                  'newvalue': new}

            ticket_values = ticket.values.copy()
            ticket_values['id'] = ticket.id
            ticket_values['description'] = wrap(
                ticket_values.get('description', ''), self.COLS,
                initial_indent=' ', subsequent_indent=' ', linesep='\n',
                ambiwidth=self.ambiwidth)
            ticket_values['new'] = newticket
            ticket_values['link'] = link

            data = Chrome(self.env).populate_data(None, {
                'CRLF': CRLF,
                'ticket_props': self._format_props(ticket),
                'ticket_body_hdr': self._format_hdr(ticket),
                'ticket': ticket_values,
                'changes_body': changes_body,
                'changes_descr': changes_descr,
                'change': change_data
            })
            return self._format_body(data, 'ticket_notify_email.txt')
Ejemplo n.º 4
0
 def format_attachment(self, ticket, attachment, added=True):
     """Format ticket attachment notification e-mail (untranslated)"""
     with translation_deactivated(ticket):
         self._prepare_body_attachment(ticket, attachment, added)
         return self._format_body()
Ejemplo n.º 5
0
 def format(self, ticket, newticket=True, modtime=None):
     """Format ticket change notification e-mail (untranslated)"""
     with translation_deactivated(ticket):
         self._prepare_body(ticket, newticket, modtime)
         return self._format_body()
Ejemplo n.º 6
0
 def notify(self, ticket, newticket=True, modtime=None):
     """Send ticket change notification e-mail (untranslated)"""
     with translation_deactivated(ticket):
         author = self._prepare_body(ticket, newticket, modtime)
         subject = self.data['subject']
         super(TicketNotifyEmail, self).notify(ticket.id, subject, author)
Ejemplo n.º 7
0
 def _format_body(self, data, template_name):
     chrome = Chrome(self.env)
     template = chrome.load_template(template_name, text=True)
     with translation_deactivated():  # don't translate the e-mail stream
         body = chrome.render_template_string(template, data, text=True)
         return body.encode('utf-8')
Ejemplo n.º 8
0
 def _format_body(self, data, template_name):
     template = Chrome(self.env).load_template(template_name, method='text')
     stream = template.generate(**data)
     # don't translate the e-mail stream
     with translation_deactivated():
         return stream.render('text', encoding='utf-8')