Ticket #2288: datetime-based-queries-1.patch
| File datetime-based-queries-1.patch, 7.0 KB (added by ecarter, 5 years ago) |
|---|
-
trac-trunk/trac/ticket/api.py
265 265 field = {'name': name, 'type': 'text', 'label': name.title()} 266 266 fields.append(field) 267 267 268 # Date/Time fields 269 for name in ('time', 'changetime'): 270 field = {'name': name, 'type': 'time', 'label': name.title()} 271 fields.append(field) 272 268 273 for field in self.get_custom_fields(): 269 274 if field['name'] in [f['name'] for f in fields]: 270 275 self.log.warning('Duplicate field name "%s" (ignoring)', -
trac-trunk/trac/ticket/web_ui.py
934 934 field.setdefault('optional', False) 935 935 field.setdefault('options', []) 936 936 field['skip'] = name in ('summary', 'reporter', 'description', 937 'status', 'resolution', 'owner' )937 'status', 'resolution', 'owner', 'time', 'changetime') 938 938 fields.append(field) 939 939 940 940 data['author_id'] = author_id -
trac-trunk/trac/ticket/query.py
64 64 rows.append('description') 65 65 self.fields = TicketSystem(self.env).get_ticket_fields() 66 66 field_names = [f['name'] for f in self.fields] 67 #field_names.append('time') 68 #field_names.append('changetime') 67 69 self.cols = [c for c in cols or [] if c in field_names or c == 'id'] 68 70 self.rows = [c for c in rows if c in field_names] 69 71 … … 97 99 raise QuerySyntaxError('Query filter requires field name') 98 100 # from last char of `field`, get the mode of comparison 99 101 mode, neg = '', '' 100 if field[-1] in ('~', '^', '$' ):102 if field[-1] in ('~', '^', '$', '@', '#'): 101 103 mode = field[-1] 102 104 field = field[:-1] 103 105 if field[-1] == '!': … … 136 138 # Prepare the default list of columns 137 139 cols = ['id'] 138 140 cols += [f['name'] for f in self.fields if f['type'] != 'textarea'] 141 #cols.append('time') 142 #cols.append('changetime') 139 143 for col in ('reporter', 'keywords', 'cc'): 140 144 if col in cols: 141 145 cols.remove(col) 142 146 cols.append(col) 147 import sys 148 sys.stderr.write("columns: %r\n" % (cols, )) 143 149 144 150 # Semi-intelligently remove columns that are restricted to a single 145 151 # value by a query constraint. 146 152 for col in [k for k in self.constraints.keys() 147 153 if k != 'id' and k in cols]: 148 154 constraint = self.constraints[col] 155 sys.stderr.write("column %s has constraint %r\n" % (col, constraint)) 149 156 if len(constraint) == 1 and constraint[0] \ 150 and not constraint[0][0] in ('!', '~', '^', '$' ):157 and not constraint[0][0] in ('!', '~', '^', '$', '@', '#'): 151 158 if col in cols: 152 159 cols.remove(col) 153 160 if col == 'status' and not 'closed' in constraint \ … … 156 163 if self.group in cols: 157 164 cols.remove(self.group) 158 165 166 sys.stderr.write("columns afer removal: %r\n" % (cols, )) 167 159 168 def sort_columns(col1, col2): 160 169 constrained_fields = self.constraints.keys() 161 170 # Ticket ID is always the first column … … 169 178 return col1 in constrained_fields and -1 or 1 170 179 return 0 171 180 cols.sort(sort_columns) 181 182 sys.stderr.write("columns returned: %r\n" % (cols, )) 172 183 return cols 173 184 174 185 def get_default_columns(self): … … 308 319 name = name + '.value' 309 320 value = value[len(mode) + neg:] 310 321 322 import sys 323 sys.stderr.write("eli: %s %s %s %s\n" % (name, value, mode, neg)) 324 311 325 if mode == '': 312 326 return ("COALESCE(%s,'')%s=%%s" % (name, neg and '!' or ''), 313 327 value) 328 329 if mode == '@': 330 return ("%s<=%%s" % name, value) 331 elif mode == '#': 332 return ("%s>=%%s" % name, value) 333 314 334 if not value: 315 335 return None 316 336 db = self.env.get_db_cnx() … … 334 354 # starts-with, negation, etc.) 335 355 neg = v[0].startswith('!') 336 356 mode = '' 337 if len(v[0]) > neg and v[0][neg] in ('~', '^', '$' ):357 if len(v[0]) > neg and v[0][neg] in ('~', '^', '$', '@', '#'): 338 358 mode = v[0][neg] 339 359 340 360 # Special case id ranges … … 454 474 if neg: 455 475 val = val[1:] 456 476 mode = '' 457 if val[:1] in ('~', '^', '$' ):477 if val[:1] in ('~', '^', '$', '@', '#'): 458 478 mode, val = val[:1], val[1:] 459 479 constraint['mode'] = (neg and '!' or '') + mode 460 480 constraint['values'].append(val) … … 495 515 {'name': "is", 'value': ""}, 496 516 {'name': "is not", 'value': "!"} 497 517 ] 518 modes['time'] = [ 519 {'name': "before", 'value': "@"}, 520 {'name': "after", 'value': "#"}, 521 #{'name': "on", 'value': ""}, 522 ] 498 523 499 524 groups = {} 500 525 groupsequence = [] -
trac-trunk/trac/ticket/templates/query.html
105 105 <input type="text" name="${field_name}" value="$constraint_value" size="42" /> 106 106 </py:when> 107 107 108 <py:when test="'time'"> 109 <input type="text" name="${field_name}" value="$constraint_value" size="42" /> 110 </py:when> 111 108 112 </td> 109 113 <td class="actions" 110 114 py:with="rm_idx = multiline and constraint_idx or len(constraint['values']) - 1"><input -
trac-trunk/trac/htdocs/js/query.js
224 224 element.type = "text"; 225 225 element.name = propertyName; 226 226 element.size = 42; 227 } else if (property.type == "time") { 228 var element = document.createElement("input"); 229 element.type = "text"; 230 element.name = propertyName; 231 element.size = 42; 227 232 } 228 233 td.appendChild(element); 229 234 element.focus();
