Commits

Azoff committed 1b4b216

Fixed duplicated 'order' parameter in Query.to_string().
Query.get_group() now returns (None, None) when no group is to be applied; fixes almost every testcase.

Comments (0)

Files changed (1)

          kw_arys = ['rows']
          kw_bools = ['desc', 'groupdesc', 'verbose']
          kw_synonyms = {'row': 'rows'}
-@@ -166,6 +172,7 @@ class Query(object):
+@@ -166,6 +172,9 @@ class Query(object):
          synonyms = TicketSystem(env).get_field_synonyms()
          constraints = [{}]
          cols = []
-+        order = []
++        order = kw.pop('order', [])
++        if isinstance(order, basestring):
++            order = order.split('|')
          report = None
          def as_str(s):
              if isinstance(s, unicode):
-@@ -204,6 +211,9 @@ class Query(object):
+@@ -204,6 +213,9 @@ class Query(object):
              elif field == 'col':
                  cols.extend(synonyms.get(value, value)
                              for value in processed_values)
              elif field == 'report':
                  report = processed_values[0]
              else:
-@@ -211,7 +221,7 @@ class Query(object):
+@@ -211,7 +223,8 @@ class Query(object):
                                             []).extend(processed_values)
          constraints = filter(None, constraints)
          report = kw.pop('report', report)
 -        return cls(env, report, constraints=constraints, cols=cols, **kw)
-+        return cls(env, report, constraints=constraints, cols=cols, order=order, **kw)
++        return cls(env, report, constraints=constraints, cols=cols, \
++                   order=order, **kw)
  
      def get_columns(self):
          if not self.cols:
-@@ -277,16 +287,32 @@ class Query(object):
+@@ -277,16 +290,32 @@ class Query(object):
              # Only display the first seven columns by default
              cols = cols[:7]
  
 +        # Returns a single (field, desc_bool) item; field may be None.
 +        if self.group:
 +            return self.get_order()[0] # Group is first order item
-+        return (None, False)
++        return (None, None)
 +    
      def count(self, req=None, db=None, cached_ids=None, authname=None,
                tzinfo=None, locale=None):
          """Get the number of matching tickets for the present query.
-@@ -393,9 +419,13 @@ class Query(object):
+@@ -393,9 +422,13 @@ class Query(object):
  
          if id is None:
              id = self.id
              order = self.order
          if max is None:
              max = self.max
-@@ -422,9 +452,8 @@ class Query(object):
+@@ -422,9 +455,8 @@ class Query(object):
          
          return href.query(constraints,
                            report=id,
                            col=cols,
                            row=self.rows,
                            max=max,
-@@ -458,11 +487,10 @@ class Query(object):
+@@ -458,11 +490,10 @@ class Query(object):
              for col in args:
                  if not col in cols:
                      cols.append(col)
          cols.extend([c for c in self.constraint_cols if not c in cols])
  
          custom_fields = [f['name'] for f in self.fields if f.get('custom')]
-@@ -483,14 +511,13 @@ class Query(object):
+@@ -483,14 +514,13 @@ class Query(object):
  
          # Join with the enum table for proper sorting
          for col in [c for c in enum_columns
              sql.append("\n  LEFT OUTER JOIN %s ON (%s.name=%s)"
                         % (col, col, col))
  
-@@ -641,11 +668,10 @@ class Query(object):
+@@ -641,11 +671,10 @@ class Query(object):
                             (','.join([str(id) for id in cached_ids])))
              
          sql.append("\nORDER BY ")
              if name in enum_columns:
                  col = name + '.value'
              elif name in custom_fields:
-@@ -673,10 +699,11 @@ class Query(object):
+@@ -673,10 +702,11 @@ class Query(object):
                             % (desc, desc, col, desc))
              else:
                  sql.append("%s%s" % (col, desc))
 -        if self.order != 'id':
 -            sql.append(",t.id")  
 +            sql.append(",")
-+        if order_cols:
++        if sql[-1] == ',': # Remove trailing ,
 +            del sql[-1]
 +        if 'id' not in order_cols:
 +            sql.append(",t.id")
  
          if errors:
              raise QueryValueError(errors)
-@@ -760,6 +787,7 @@ class Query(object):
+@@ -760,6 +790,7 @@ class Query(object):
                      for (label, milestones) in groups]
              fields[name] = field
  
          groups = {}
          groupsequence = []
          for ticket in tickets:
-@@ -770,8 +798,8 @@ class Query(object):
+@@ -770,8 +801,8 @@ class Query(object):
                      ticket['added'] = True
                  elif ticket['changetime'] > orig_time:
                      ticket['changed'] = True
                  groups.setdefault(group_key, []).append(ticket)
                  if not groupsequence or group_key not in groupsequence:
                      groupsequence.append(group_key)
-@@ -861,15 +889,19 @@ class QueryModule(Component):
+@@ -861,15 +892,19 @@ class QueryModule(Component):
      default_columns = ListOption('query', 'default_columns',
          default=None,
          doc="""List of columns to show in query unless defined by the query.
  
      # IContentConverter methods
  
-@@ -932,10 +964,6 @@ class QueryModule(Component):
+@@ -932,10 +967,6 @@ class QueryModule(Component):
                  query = Query.from_string(self.env, qstring)
                  args = {'order': query.order, 'group': query.group,
                          'col': query.cols, 'max': query.max}
                  constraints = query.constraints
  
              # Substitute $USER, or ensure no field constraints that depend
-@@ -949,6 +977,18 @@ class QueryModule(Component):
+@@ -949,6 +980,18 @@ class QueryModule(Component):
                              del clause[field]
                              break
  
          cols = args.get('col')
          if isinstance(cols, basestring):
              cols = [cols]
-@@ -963,13 +1003,11 @@ class QueryModule(Component):
+@@ -963,13 +1006,11 @@ class QueryModule(Component):
          max = args.get('max')
          if max is None and format in ('csv', 'tab'):
              max = 0 # unlimited unless specified explicitly
  
          if 'update' in req.args:
              # Reset session vars
-@@ -1423,19 +1461,21 @@ class TicketQueryMacro(WikiMacroBase):
+@@ -1423,19 +1464,21 @@ class TicketQueryMacro(WikiMacroBase):
  
          def ticket_groups():
              groups = []
                  href = q.get_href(formatter.context)
                  groups.append((v, [t for t in g], href, title))
              return groups
-@@ -1456,7 +1496,7 @@ class TicketQueryMacro(WikiMacroBase):
+@@ -1456,7 +1499,7 @@ class TicketQueryMacro(WikiMacroBase):
                      [(tag.p(tag_('%(groupvalue)s %(groupname)s tickets:',
                                   groupvalue=tag.a(v, href=href, class_='query',
                                                    title=title),