Esempio n. 1
0
    def get_timeline_events(self, req, start, stop, filters):
        format = req.args.get('format')

        status_map = {
            'new': ('newticket', u'créé'),
            'reopened': ('newticket', u'réouvert'),
            'closed': ('closedticket', u'fermé'),
            'edit': ('editedticket', u'mis à jour')
        }

        href = format == 'rss' and req.abs_href or req.href

        def produce(
            (id, t, author, type, summary), status, fields, comment, cid):
            if status == 'edit':
                if 'ticket_details' in filters:
                    info = u''
                    if len(fields) > 0:
                        info = u', '.join([u'<i>%s</i>' % f for f in \
                                          fields.keys()]) + u' modifié<br />'
                else:
                    return None
            elif 'ticket' in filters:
                if status == 'closed' and fields.has_key('resolution'):
                    info = fields['resolution']
                    if info and comment:
                        info = '%s: ' % info
                else:
                    info = ''
            else:
                return None
            kind, verb = status_map[status]
            if format == 'rss':
                title = u'Ticket #%s (%s %s): %s' % \
                        (id, translate(self.env, type).lower(), verb, summary)
            else:
                title = Markup(
                    u'Ticket <em title="%s">#%s</em> (%s) %s par %s', summary,
                    id, translate(self.env, type), verb, author)
            ticket_href = href.ticket(id)
            if cid:
                ticket_href += '#comment:' + cid
            if status == 'new':
                message = unicode(summary)
            else:
                message = Markup(info)
                if comment:
                    if format == 'rss':
                        message += wiki_to_html(comment,
                                                self.env,
                                                req,
                                                db,
                                                absurls=True)
                    else:
                        message += wiki_to_oneliner(comment,
                                                    self.env,
                                                    db,
                                                    shorten=True)
            return kind, ticket_href, title, t, author, message
Esempio n. 2
0
    def get_timeline_events(self, req, start, stop, filters):
        format = req.args.get('format')

        status_map = {
            'new': ('newticket', u'créé'),
            'reopened': ('newticket', u'réouvert'),
            'closed': ('closedticket', u'fermé'),
            'edit': ('editedticket', u'mis à jour')
        }

        href = format == 'rss' and req.abs_href or req.href

        def produce((id, t, author, type, summary), status, fields, comment,
                    cid):
            if status == 'edit':
                if 'ticket_details' in filters:
                    info = u''
                    if len(fields) > 0:
                        info = u', '.join([u'<i>%s</i>' % f for f in \
                                          fields.keys()]) + u' modifié<br />'
                else:
                    return None
            elif 'ticket' in filters:
                if status == 'closed' and fields.has_key('resolution'):
                    info = fields['resolution']
                    if info and comment:
                        info = '%s: ' % info
                else:
                    info = ''
            else:
                return None
            kind, verb = status_map[status]
            if format == 'rss':
                title = u'Ticket #%s (%s %s): %s' % \
                        (id, translate(self.env, type).lower(), verb, summary)
            else:
                title = Markup(
                    u'Ticket <em title="%s">#%s</em> (%s) %s par %s', summary,
                    id, translate(self.env, type), verb, author)
            ticket_href = href.ticket(id)
            if cid:
                ticket_href += '#comment:' + cid
            if status == 'new':
                message = unicode(summary)
            else:
                message = Markup(info)
                if comment:
                    if format == 'rss':
                        message += wiki_to_html(
                            comment, self.env, req, db, absurls=True)
                    else:
                        message += wiki_to_oneliner(
                            comment, self.env, db, shorten=True)
            return kind, ticket_href, title, t, author, message
Esempio n. 3
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and 'owner' in req.args and \
               not req.perm.has_permission('TICKET_MODIFY'):
            del req.args['owner']

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req,
                                       db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = u'Nouveau ticket'
        req.hdf['newticket'] = ticket.values

        field_names = [
            field['name'] for field in ticket.fields if not field.get('custom')
        ]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]

        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = u'Assigner à'
                if not req.perm.has_permission('TICKET_MODIFY'):
                    field['skip'] = True
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options'][:]
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
            field['label'] = translate(self.env, field['label'])
            req.hdf['newticket.fields.' + name] = field

        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['newticket.can_attach'] = True
            req.hdf['newticket.attachment'] = req.args.get('attachment')

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None
Esempio n. 4
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and 'owner' in req.args and \
               not req.perm.has_permission('TICKET_MODIFY'):
            del req.args['owner']

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req, db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = u'Nouveau ticket'
        req.hdf['newticket'] = ticket.values

        field_names = [field['name'] for field in ticket.fields
                       if not field.get('custom')]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]

        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = u'Assigner à'
                if not req.perm.has_permission('TICKET_MODIFY'):
                    field['skip'] = True
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options'][:]
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
            field['label'] = translate(self.env, field['label'])
            req.hdf['newticket.fields.' + name] = field

        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['newticket.can_attach'] = True
            req.hdf['newticket.attachment'] = req.args.get('attachment')

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None
Esempio n. 5
0
        idx = 0
        for col in cols:
            title=col.capitalize()
            prefix = 'report.headers.%d' % idx
            req.hdf['%s.real' % prefix] = col
            if title.startswith('__') and title.endswith('__'):
                continue
            elif title[0] == '_' and title[-1] == '_':
                title = title[1:-1].capitalize()
                req.hdf[prefix + '.fullrow'] = 1
            elif title[0] == '_':
                continue
            elif title[-1] == '_':
                title = title[:-1]
                req.hdf[prefix + '.breakrow'] = 1
            req.hdf[prefix] = translate(self.env, title, True)
            idx = idx + 1

        if req.args.has_key('sort'):
            sortCol = req.args.get('sort')
            colIndex = None
            hiddenCols = 0
            for x in range(len(cols)):
                colName = cols[x]
                if colName == sortCol:
                    colIndex = x
                if colName.startswith('__') and colName.endswith('__'):
                    hiddenCols += 1
            if colIndex != None:
                k = 'report.headers.%d.asc' % (colIndex - hiddenCols)
                asc = req.args.get('asc', None)
Esempio n. 6
0
    def get_ticket_fields(self):
        """Returns the list of fields available for tickets."""
        from trac.ticket import model

        db = self.env.get_db_cnx()
        fields = []

        # Basic text fields
        for name in ('summary', 'reporter'):
            field = {'name': name, 'type': 'text', 'label': name.title()}
            fields.append(field)

        # Owner field, can be text or drop-down depending on configuration
        field = {'name': 'owner', 'label': 'Owner'}
        if self.restrict_owner:
            field['type'] = 'select'
            users = []
            perm = PermissionSystem(self.env)
            for username, name, email in self.env.get_known_users(db):
                if perm.get_user_permissions(username).get('TICKET_MODIFY'):
                    users.append(username)
            field['options'] = users
            field['optional'] = True
        else:
            field['type'] = 'text'
        fields.append(field)

        # Description
        fields.append({'name': 'description', 'type': 'textarea',
                       'label': 'Description'})

        # Default select and radio fields
        selects = [('type', model.Type), ('status', model.Status),
                   ('priority', model.Priority), ('milestone', model.Milestone),
                   ('component', model.Component), ('version', model.Version),
                   ('severity', model.Severity), ('resolution', model.Resolution)]
        for name, cls in selects:
            options = [val.name for val in cls.select(self.env, db=db)]
            if not options:
                # Fields without possible values are treated as if they didn't
                # exist
                continue
            field = {'name': name, 'type': 'select', 
                     'label': translate(self.env, name, True),
                     'value': self.config.get('ticket', 'default_' + name),
                     'options': options}
            if name in ('status', 'resolution'):
                field['type'] = 'radio'
                field['optional'] = True
            elif name in ('milestone', 'version'):
                field['optional'] = True
            fields.append(field)

        # Advanced text fields
        for name in ('keywords', 'cc', ):
            field = {'name': name, 'type': 'text', 
                     'label': translate(self.env, name, True)}
            fields.append(field)

        for field in self.get_custom_fields():
            if field['name'] in [f['name'] for f in fields]:
                self.log.warning('Duplicate field name "%s" (ignoring)',
                                 field['name'])
                continue
            if not re.match('^[a-zA-Z][a-zA-Z0-9_]+$', field['name']):
                self.log.warning('Invalid name for custom field: "%s" '
                                 '(ignoring)', field['name'])
                continue
            field['custom'] = True
            fields.append(field)

        return fields
Esempio n. 7
0
    def get_ticket_fields(self):
        """Returns the list of fields available for tickets."""
        from trac.ticket import model

        db = self.env.get_db_cnx()
        fields = []

        # Basic text fields
        for name in ("summary", "reporter"):
            field = {"name": name, "type": "text", "label": name.title()}
            fields.append(field)

        # Owner field, can be text or drop-down depending on configuration
        field = {"name": "owner", "label": "Owner"}
        if self.restrict_owner:
            field["type"] = "select"
            users = []
            perm = PermissionSystem(self.env)
            for username, name, email in self.env.get_known_users(db):
                if perm.get_user_permissions(username).get("TICKET_MODIFY"):
                    users.append(username)
            field["options"] = users
            field["optional"] = True
        else:
            field["type"] = "text"
        fields.append(field)

        # Description
        fields.append({"name": "description", "type": "textarea", "label": "Description"})

        # Default select and radio fields
        selects = [
            ("type", model.Type),
            ("status", model.Status),
            ("priority", model.Priority),
            ("milestone", model.Milestone),
            ("component", model.Component),
            ("version", model.Version),
            ("severity", model.Severity),
            ("resolution", model.Resolution),
        ]
        for name, cls in selects:
            options = [val.name for val in cls.select(self.env, db=db)]
            if not options:
                # Fields without possible values are treated as if they didn't
                # exist
                continue
            field = {
                "name": name,
                "type": "select",
                "label": translate(self.env, name, True),
                "value": self.config.get("ticket", "default_" + name),
                "options": options,
            }
            if name in ("status", "resolution"):
                field["type"] = "radio"
                field["optional"] = True
            elif name in ("milestone", "version"):
                field["optional"] = True
            fields.append(field)

        # Advanced text fields
        for name in ("keywords", "cc"):
            field = {"name": name, "type": "text", "label": translate(self.env, name, True)}
            fields.append(field)

        for field in self.get_custom_fields():
            if field["name"] in [f["name"] for f in fields]:
                self.log.warning('Duplicate field name "%s" (ignoring)', field["name"])
                continue
            if not re.match("^[a-zA-Z][a-zA-Z0-9_]+$", field["name"]):
                self.log.warning('Invalid name for custom field: "%s" ' "(ignoring)", field["name"])
                continue
            field["custom"] = True
            fields.append(field)

        return fields