nodes: 0, module; 1, function_definition; 2, function_name:folderitems; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, return_statement; 15, identifier:full_objects; 16, False; 17, identifier:classic; 18, True; 19, comment:"""Sort by Categories
          """; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, attribute; 25, block; 26, else_clause; 27, identifier:items; 28, identifier:bsc; 29, call; 30, attribute; 31, call; 32, attribute; 33, call; 34, identifier:items; 35, call; 36, identifier:self; 37, identifier:do_cats; 38, expression_statement; 39, block; 40, identifier:getToolByName; 41, argument_list; 42, identifier:self; 43, identifier:an_cats; 44, identifier:bsc; 45, argument_list; 46, identifier:self; 47, identifier:an_cats_order; 48, identifier:dict; 49, argument_list; 50, attribute; 51, argument_list; 52, assignment; 53, expression_statement; 54, attribute; 55, string:"bika_setup_catalog"; 56, keyword_argument; 57, keyword_argument; 58, list_comprehension; 59, call; 60, identifier:folderitems; 61, attribute; 62, call; 63, call; 64, identifier:self; 65, identifier:context; 66, identifier:portal_type; 67, string:"AnalysisCategory"; 68, identifier:sort_on; 69, string:"sortable_title"; 70, tuple; 71, for_in_clause; 72, identifier:super; 73, argument_list; 74, identifier:self; 75, identifier:categories; 76, identifier:map; 77, argument_list; 78, attribute; 79, argument_list; 80, attribute; 81, call; 82, pattern_list; 83, call; 84, identifier:AnalysisServicesView; 85, identifier:self; 86, lambda; 87, call; 88, attribute; 89, identifier:sort; 90, identifier:b; 91, identifier:Title; 92, attribute; 93, argument_list; 94, identifier:a; 95, identifier:b; 96, identifier:enumerate; 97, argument_list; 98, lambda_parameters; 99, subscript; 100, identifier:sorted; 101, argument_list; 102, identifier:self; 103, identifier:categories; 104, string:"{:04}"; 105, identifier:format; 106, identifier:a; 107, attribute; 108, identifier:x; 109, identifier:x; 110, integer:0; 111, attribute; 112, keyword_argument; 113, identifier:self; 114, identifier:an_cats; 115, identifier:self; 116, identifier:categories; 117, identifier:key; 118, lambda; 119, lambda_parameters; 120, subscript; 121, identifier:x; 122, identifier:x; 123, integer:1
code: def folderitems(self, full_objects=False, classic=True):
          """Sort by Categories
          """
          bsc = getToolByName(self.context, "bika_setup_catalog")
          self.an_cats = bsc(
              portal_type="AnalysisCategory",
              sort_on="sortable_title")
          self.an_cats_order = dict([
              (b.Title, "{:04}".format(a))
              for a, b in enumerate(self.an_cats)])
          items = super(AnalysisServicesView, self).folderitems()
          if self.do_cats:
              self.categories = map(lambda x: x[0],
                                    sorted(self.categories, key=lambda x: x[1]))
          else:
              self.categories.sort()
          return items