Changeset deed211 in tailbone
- Timestamp:
- 11/15/2022 04:29:15 PM (3 months ago)
- Branches:
- master
- Children:
- 3178894
- Parents:
- 3e8924e
- Location:
- tailbone
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tailbone/grids/filters.py
r3e8924e rdeed211 77 77 Input renderer for numeric values. 78 78 """ 79 # TODO 80 # data_type = 'number' 79 data_type = 'number' 81 80 82 81 def render(self, value=None, **kwargs): … … 138 137 'is_empty': "is empty", 139 138 'is_not_empty': "is not empty", 139 'between': "between", 140 140 'is_null': "is null", 141 141 'is_not_null': "is not null", … … 379 379 return query.filter(self.column <= self.encode_value(value)) 380 380 381 def filter_between(self, query, value): 382 """ 383 Filter data with a "between" query. Really this uses ">=" and 384 "<=" (inclusive) logic instead of SQL "between" keyword. 385 """ 386 if value is None or value == '': 387 return query 388 389 if '|' not in value: 390 return query 391 392 values = value.split('|') 393 if len(values) != 2: 394 return query 395 396 start_value, end_value = values 397 398 # we'll only filter if we have start and/or end value 399 if not start_value and not end_value: 400 return query 401 402 return self.filter_for_range(query, start_value, end_value) 403 404 def filter_for_range(self, query, start_value, end_value): 405 """ 406 This method should actually apply filter(s) to the query, 407 according to the given value range. Subclasses may override 408 this logic. 409 """ 410 if start_value: 411 if self.value_invalid(start_value): 412 return query 413 query = query.filter(self.column >= start_value) 414 415 if end_value: 416 if self.value_invalid(end_value): 417 return query 418 query = query.filter(self.column <= end_value) 419 420 return query 421 381 422 382 423 class AlchemyStringFilter(AlchemyGridFilter): … … 533 574 # expose greater-than / less-than verbs in addition to core 534 575 default_verbs = ['equal', 'not_equal', 'greater_than', 'greater_equal', 535 'less_than', 'less_equal', 'is_null', 'is_not_null', 'is_any'] 576 'less_than', 'less_equal', 'between', 577 'is_null', 'is_not_null', 'is_any'] 536 578 537 579 # TODO: what follows "works" in that it prevents an error...but from the … … 542 584 543 585 def value_invalid(self, value): 586 587 # first just make sure it's somewhat numeric 588 try: 589 float(value) 590 except ValueError: 591 return True 592 544 593 return bool(value and len(six.text_type(value)) > 8) 545 594 … … 727 776 return query.filter(self.column <= self.encode_value(date)) 728 777 778 # TODO: this should be merged into parent class 729 779 def filter_between(self, query, value): 730 780 """ … … 754 804 return self.filter_date_range(query, start_date, end_date) 755 805 806 # TODO: this should be merged into parent class 756 807 def filter_date_range(self, query, start_date, end_date): 757 808 """ -
tailbone/static/js/tailbone.buefy.grid.js
r3e8924e rdeed211 1 2 const GridFilterNumericValue = { 3 template: '#grid-filter-numeric-value-template', 4 props: { 5 value: String, 6 wantsRange: Boolean, 7 }, 8 data() { 9 return { 10 startValue: null, 11 endValue: null, 12 } 13 }, 14 mounted() { 15 if (this.wantsRange) { 16 if (this.value.includes('|')) { 17 let values = this.value.split('|') 18 if (values.length == 2) { 19 this.startValue = values[0] 20 this.endValue = values[1] 21 } else { 22 this.startValue = this.value 23 } 24 } else { 25 this.startValue = this.value 26 } 27 } else { 28 this.startValue = this.value 29 } 30 }, 31 methods: { 32 focus() { 33 this.$refs.startValue.focus() 34 }, 35 startValueChanged(value) { 36 if (this.wantsRange) { 37 value += '|' + this.endValue 38 } 39 this.$emit('input', value) 40 }, 41 endValueChanged(value) { 42 value = this.startValue + '|' + value 43 this.$emit('input', value) 44 }, 45 }, 46 } 47 48 Vue.component('grid-filter-numeric-value', GridFilterNumericValue) 49 1 50 2 51 const GridFilterDateValue = { -
tailbone/templates/grids/buefy.mako
r3e8924e rdeed211 1 1 ## -*- coding: utf-8; -*- 2 3 <script type="text/x-template" id="grid-filter-numeric-value-template"> 4 <div class="level"> 5 <div class="level-left"> 6 <div class="level-item"> 7 <b-input v-model="startValue" 8 ref="startValue" 9 @input="startValueChanged"> 10 </b-input> 11 </div> 12 <div v-show="wantsRange" 13 class="level-item"> 14 and 15 </div> 16 <div v-show="wantsRange" 17 class="level-item"> 18 <b-input v-model="endValue" 19 ref="endValue" 20 @input="endValueChanged"> 21 </b-input> 22 </div> 23 </div> 24 </div> 25 </script> 2 26 3 27 <script type="text/x-template" id="grid-filter-date-value-template"> … … 75 99 </option> 76 100 </b-select> 101 102 <grid-filter-numeric-value v-if="filter.data_type == 'number'" 103 v-model="filter.value" 104 v-show="valuedVerb()" 105 :wants-range="filter.verb == 'between'" 106 ref="valueInput"> 107 </grid-filter-numeric-value> 77 108 78 109 <b-input v-if="filter.data_type == 'string' && !multiValuedVerb()"
Note: See TracChangeset
for help on using the changeset viewer.