Exemplo n.º 1
0
    def post_process_request(self, req, template, data, content_type):
        # The /query paths are handled in filter_stream()
        if req.path_info.startswith('/ticket/') or \
           req.path_info.startswith('/newticket'):
            add_script(req, 'subcomponents/componentselect.js')
        
                                 
        if template == "query.html":
            # Allow users to query for parent components and include all subs
            data['modes']['select'].insert(0, {'name': "begins with", 'value': "^"})

        if template == "milestone_view.html":
            # Group components in the milestone view by base component.
            if data['grouped_by'] == "component":
                componentname = ''
                newgroups = []
                newcomponents = []
                for component in data['groups']:
                    componentname = component['name'].split('/')[0]
                    if componentname not in newcomponents:
                        # This component is not yet in the new list of components, add it.
                        newcomponents.append(componentname)
                        # Fix URLs to the querys (we use unicode_quote_plus to replace the '/'
                        # with something URL safe (like the hrefs are)
                        new_hrefs = []
                        for interval_href in component['interval_hrefs']:
                            new_hrefs.append(interval_href.replace(unicode_quote_plus(component['name']), '^' + componentname))
                        component['stats_href'] = component['stats_href'].replace(unicode_quote_plus(component['name']), '^' + componentname)
                        component['interval_hrefs'] = new_hrefs
                        # Set the name to the base name (in case this originally
                        # is a subcomponent.
                        component['name'] = componentname
                        
                        newgroups.append(component)
                    else:
                        # This is a subcomponent. Add the stats to the main component.
                        # Note that above two lists are created. Whenever an
                        # item is added to one, an analogous one is added to
                        # the other. This code uses that logic.
                        corecomponent = newgroups[newcomponents.index(componentname)]
                        mergedstats = corecomponent['stats'] #TicketGroupStats from trac.ticket.roadmap
                        newstats = component['stats']
                        
                        # Bear with me as we go to this mess that is the group stats
                        # (or of course this hack, depending on who's viewpoint).
                        # First merge the totals
                        mergedstats.count += newstats.count 
                        
                        # The stats are divided in intervals, merge these.
                        i = 0
                        for interval in mergedstats.intervals:
                            newinterval = newstats.intervals[i]
                            interval['count'] += newinterval['count']
                            i += 1
                        mergedstats.refresh_calcs()
                
                # Now store the new milestone component groups
                data['groups'] = newgroups
        return template, data, content_type        
Exemplo n.º 2
0
 def _get_help_href(self, req):
     if not self.help_opt:
         return None
     link = resource_id = None
     if self.help_opt.startswith('/'):
         # Assume valid URL to arbitrary resource inside
         #   of the current Trac environment.
         link = req.href(self.help_opt)
     if not link and ':' in self.help_opt:
         realm, resource_id = self.help_opt.split(':', 1)
         # Validate realm-like prefix against resource realm list,
         #   but exclude 'wiki' to allow deferred page creation.
         rsys = ResourceSystem(self.env)
         if realm in set(rsys.get_known_realms()) - set('wiki'):
             mgr = rsys.get_resource_manager(realm)
             # Handle optional IResourceManager method gracefully.
             try:
                 if mgr.resource_exists(Resource(realm, resource_id)):
                     link = mgr.get_resource_url(resource_id, req.href)
             except AttributeError:
                 # Assume generic resource URL build rule.
                 link = req.href(realm, resource_id)
     if not link:
         if not resource_id:
             # Assume wiki page name for backwards-compatibility.
             resource_id = self.help_opt
         if '#' in resource_id:
             path, anchor = resource_id.split('#', 1)
             anchor = unicode_quote_plus(anchor, safe="?!~*'()")
             link = '#'.join((req.href.wiki(path), anchor))
         else:
             link = req.href.wiki(resource_id)
     return link
Exemplo n.º 3
0
 def _get_helppage_link(self, req):
     link = realm = resource_id = None
     if self.helppage_opt.startswith('/'):
         # Assume valid URL to arbitrary resource inside
         #   of the current Trac environment.
         link = req.href(self.helppage_opt)
     if not link and ':' in self.helppage_opt:
         realm, resource_id = self.helppage_opt.split(':', 1)
         # Validate realm-like prefix against resource realm list,
         #   but exclude 'wiki' to allow deferred page creation.
         rsys = ResourceSystem(self.env)
         if realm in set(rsys.get_known_realms()) - set('wiki'):
             mgr = rsys.get_resource_manager(realm)
             # Handle optional IResourceManager method gracefully.
             try:
                 if mgr.resource_exists(Resource(realm, resource_id)):
                     link = mgr.get_resource_url(resource_id, req.href)
             except AttributeError:
                 # Assume generic resource URL build rule.
                 link = req.href(realm, resource_id)
     if not link:
         if not resource_id:
             # Assume wiki page name for backwards-compatibility.
             resource_id = self.helppage_opt
         # Preserve anchor without 'path_safe' arg (since Trac 0.12.2dev).
         if '#' in resource_id:
             path, anchor = resource_id.split('#', 1)
         else:
             anchor = None
             path = resource_id
         if hasattr(unicode_quote_plus, "safe"):
             # Use method for query string quoting (since Trac 0.13dev).
             anchor = unicode_quote_plus(anchor, safe="?!~*'()")
         else:
             anchor = unicode_quote_plus(anchor)
         link = '#'.join([req.href.wiki(path), anchor])
     return link
Exemplo n.º 4
0
 def test_unicode_quote_plus(self):
     self.assertEqual(u'the+%C3%9C+thing',
                      unicode_quote_plus(u'the Ü thing'))
     self.assertEqual(u'%2520%C3%9C+%2520', unicode_quote_plus(u'%20Ü %20'))
Exemplo n.º 5
0
 def test_unicode_quote_plus(self):
     self.assertEqual(u"the+%C3%9C+thing", unicode_quote_plus(u"the Ü thing"))
     self.assertEqual(u"%2520%C3%9C+%2520", unicode_quote_plus(u"%20Ü %20"))
Exemplo n.º 6
0
 def test_unicode_quote_plus(self):
     self.assertEqual(u'the+%C3%9C+thing',
                      unicode_quote_plus(u'the Ü thing'))
     self.assertEqual(u'%2520%C3%9C+%2520',
                      unicode_quote_plus(u'%20Ü %20'))
Exemplo n.º 7
0
    def post_process_request(self, req, template, data, content_type=None):
        if req.path_info.startswith('/ticket/') or \
                req.path_info.startswith('/newticket') or \
                req.path_info.startswith('/query'):
            add_script(req, 'subcomponents/componentselect.js')

        if template == "query.html":
            # Allow users to query for parent components and include all subs
            data['modes']['select'].insert(0, {
                'name': "begins with",
                'value': "^"
            })

        if template == "milestone_view.html":
            # Group components in the milestone view by base component.
            if data['grouped_by'] == "component":
                componentname = ''
                newgroups = []
                newcomponents = []
                for component in data['groups']:
                    componentname = component['name'].split('/')[0]
                    if componentname not in newcomponents:
                        # This component is not yet in the new list of components, add it.
                        newcomponents.append(componentname)
                        # Fix URLs to the querys (we use unicode_quote_plus to replace the '/'
                        # with something URL safe (like the hrefs are)
                        new_hrefs = []
                        for interval_href in component['interval_hrefs']:
                            new_hrefs.append(
                                interval_href.replace(
                                    unicode_quote_plus(component['name']),
                                    '^' + componentname))
                        component['stats_href'] = component[
                            'stats_href'].replace(
                                unicode_quote_plus(component['name']),
                                '^' + componentname)
                        component['interval_hrefs'] = new_hrefs
                        # Set the name to the base name (in case this originally
                        # is a subcomponent.
                        component['name'] = componentname

                        newgroups.append(component)
                    else:
                        # This is a subcomponent. Add the stats to the main component.
                        # Note that above two lists are created. Whenever an
                        # item is added to one, an analogous one is added to
                        # the other. This code uses that logic.
                        corecomponent = newgroups[newcomponents.index(
                            componentname)]
                        mergedstats = corecomponent[
                            'stats']  # TicketGroupStats from trac.ticket.roadmap
                        newstats = component['stats']

                        # Bear with me as we go to this mess that is the group stats
                        # (or of course this hack, depending on who's viewpoint).
                        # First merge the totals
                        mergedstats.count += newstats.count

                        # The stats are divided in intervals, merge these.
                        i = 0
                        for interval in mergedstats.intervals:
                            newinterval = newstats.intervals[i]
                            interval['count'] += newinterval['count']
                            i += 1
                        mergedstats.refresh_calcs()

                # Now store the new milestone component groups
                data['groups'] = newgroups

        if template == "admin_components.html" and data['view'] == 'detail':
            if len(self._get_component_children(data['component'].name)) > 0:
                add_script(req, 'subcomponents/componentselect.js')
                add_script_data(req, {"rename_children": True})

        return template, data, content_type
Exemplo n.º 8
0
    def post_process_request(self, req, template, data, content_type):
        # The /query paths are handled in filter_stream()
        if req.path_info.startswith('/ticket/') or \
           req.path_info.startswith('/newticket'):
            add_script(req, 'subtickettypes/tickettypeselect.js')

        if template == "query.html":
            # Allow users to query for parent ticket types and include all

            # sub ticket types as well
            # check if the entry already exists (might be added by another
            # plugin)
            begins_with_select_item = {'name': _("begins with"), 'value': ""}
            if begins_with_select_item not in data['modes']['select']:
                data['modes']['select'].insert(0, begins_with_select_item)

        if template == "milestone_view.html":
            # Group tickets in the milestone view by base component.
            if data['grouped_by'] == "type":
                ticket_type_name = ''
                new_groups = []
                new_ticket_types = []
                for ticket_type in data['groups']:
                    ticket_type_name = ticket_type['name'].split("/")[0]
                    if ticket_type_name not in new_ticket_types:
                        # This ticket type is not yet in the new list of ticket
                        # types, add it.
                        new_ticket_types.append(ticket_type_name)
                        # Fix URLs to the querys (we use unicode_quote_plus to
                        # replace the '/' with something URL safe (like the
                        # hrefs are)
                        new_hrefs = []
                        for interval_href in ticket_type['interval_hrefs']:
                            new_hrefs.append(interval_href.replace(unicode_quote_plus(ticket_type['name']), '^' + ticket_type_name))
                        ticket_type['stats_href'] = ticket_type['stats_href'].replace(unicode_quote_plus(ticket_type['name']), '^' + ticket_type_name)
                        ticket_type['interval_hrefs'] = new_hrefs
                        # Set the name to the base name (in case this originally
                        # is a sub ticket type.
                        ticket_type['name'] = ticket_type_name

                        new_groups.append(ticket_type)
                    else:
                        # This is a sub ticket type. Add the stats to the main ticket type.
                        # Note that above two lists are created. Whenever an
                        # item is added to one, an analogous one is added to
                        # the other. This code uses that logic.
                        core_ticket_type = new_groups[new_ticket_types.index(ticket_type_name)]
                        merged_stats = core_ticket_type['stats'] #TicketGroupStats from trac.ticket.roadmap
                        new_stats = ticket_type['stats']

                        # Bear with me as we go to this mess that is the group stats
                        # (or of course this hack, depending on who's viewpoint).
                        # First merge the totals
                        merged_stats.count += new_stats.count

                        # The stats are divided in intervals, merge these.
                        i = 0
                        for interval in merged_stats.intervals:
                            new_interval = new_stats.intervals[i]
                            interval['count'] += new_interval['count']
                            i += 1
                        merged_stats.refresh_calcs()

                # Now store the new milestone tickey type groups
                data['groups'] = new_groups

        return template, data, content_type