add time type, use sort table for numbers and dates in find api
This commit is contained in:
parent
c3b5d19e9f
commit
fbcec1bf18
4 changed files with 28 additions and 11 deletions
|
@ -133,7 +133,7 @@
|
||||||
{
|
{
|
||||||
"id": "runtime",
|
"id": "runtime",
|
||||||
"title": "Runtime",
|
"title": "Runtime",
|
||||||
"type": "integer",
|
"type": "time",
|
||||||
"columnWidth": 60,
|
"columnWidth": 60,
|
||||||
"format": {"type": "duration", "args": [0, "short"]}
|
"format": {"type": "duration", "args": [0, "short"]}
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,9 +7,11 @@ from django.conf import settings
|
||||||
|
|
||||||
from itemlist.models import List
|
from itemlist.models import List
|
||||||
import models
|
import models
|
||||||
|
import utils
|
||||||
|
|
||||||
from ox.django.query import QuerySet
|
from ox.django.query import QuerySet
|
||||||
|
|
||||||
|
|
||||||
def parseCondition(condition, user):
|
def parseCondition(condition, user):
|
||||||
'''
|
'''
|
||||||
condition: {
|
condition: {
|
||||||
|
@ -143,13 +145,13 @@ def parseCondition(condition, user):
|
||||||
q = Q(id=0)
|
q = Q(id=0)
|
||||||
return q
|
return q
|
||||||
elif key_type == 'date':
|
elif key_type == 'date':
|
||||||
def parseDate(d):
|
def parse_date(d):
|
||||||
while len(d) < 3:
|
while len(d) < 3:
|
||||||
d.append(1)
|
d.append(1)
|
||||||
return datetime(*[int(i) for i in d])
|
return datetime(*[int(i) for i in d])
|
||||||
|
|
||||||
#using sort here since find only contains strings
|
#using sort here since find only contains strings
|
||||||
v = parseDate(v.split('-'))
|
v = parse_date(v.split('-'))
|
||||||
vk = 'sort__%s%s' % (k, {
|
vk = 'sort__%s%s' % (k, {
|
||||||
'==': '__exact',
|
'==': '__exact',
|
||||||
'>': '__gt',
|
'>': '__gt',
|
||||||
|
@ -157,23 +159,25 @@ def parseCondition(condition, user):
|
||||||
'<': '__lt',
|
'<': '__lt',
|
||||||
'<=': '__lte',
|
'<=': '__lte',
|
||||||
}.get(op,''))
|
}.get(op,''))
|
||||||
|
vk = str(vk)
|
||||||
q = Q(**{vk: v})
|
q = Q(**{vk: v})
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
else: #number
|
else: #numbers
|
||||||
vk = 'find__value%s' % ({
|
#use sort table here
|
||||||
|
if key_type == 'time':
|
||||||
|
v = int(utils.parse_time(v))
|
||||||
|
|
||||||
|
vk = 'sort__%s%s' % (k, {
|
||||||
'==': '__exact',
|
'==': '__exact',
|
||||||
'>': '__gt',
|
'>': '__gt',
|
||||||
'>=': '__gte',
|
'>=': '__gte',
|
||||||
'<': '__lt',
|
'<': '__lt',
|
||||||
'<=': '__lte',
|
'<=': '__lte',
|
||||||
'^': '__istartswith',
|
}.get(op,''))
|
||||||
'$': '__iendswith',
|
|
||||||
}.get(op,'__exact'))
|
|
||||||
vk = str(vk)
|
vk = str(vk)
|
||||||
|
q = Q(**{vk: v})
|
||||||
q = Q(**{'find__key': k, vk: v})
|
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
|
|
|
@ -1156,7 +1156,7 @@ attrs = {
|
||||||
'item': models.OneToOneField('Item', related_name='sort', primary_key=True),
|
'item': models.OneToOneField('Item', related_name='sort', primary_key=True),
|
||||||
'duration': models.FloatField(null=True, blank=True, db_index=True),
|
'duration': models.FloatField(null=True, blank=True, db_index=True),
|
||||||
}
|
}
|
||||||
for key in filter(lambda k: 'columnWidth' in k, settings.CONFIG['itemKeys']):
|
for key in filter(lambda k: 'columnWidth' in k or k['type'] in ('integer', 'time', 'float', 'data'), settings.CONFIG['itemKeys']):
|
||||||
name = key['id']
|
name = key['id']
|
||||||
name = {'id': 'itemId'}.get(name, name)
|
name = {'id': 'itemId'}.get(name, name)
|
||||||
sort_type = key.get('sort', key['type'])
|
sort_type = key.get('sort', key['type'])
|
||||||
|
@ -1177,6 +1177,7 @@ for key in filter(lambda k: 'columnWidth' in k, settings.CONFIG['itemKeys']):
|
||||||
'length': 'integer',
|
'length': 'integer',
|
||||||
'date': 'date',
|
'date': 'date',
|
||||||
'hue': 'float',
|
'hue': 'float',
|
||||||
|
'time': 'integer',
|
||||||
'label': 'integer',
|
'label': 'integer',
|
||||||
}.get(sort_type, sort_type)]
|
}.get(sort_type, sort_type)]
|
||||||
attrs[name] = model[0](**model[1])
|
attrs[name] = model[0](**model[1])
|
||||||
|
|
|
@ -20,6 +20,18 @@ def parse_decimal(string):
|
||||||
d = string.split('/')
|
d = string.split('/')
|
||||||
return Decimal(d[0]) / Decimal(d[1])
|
return Decimal(d[0]) / Decimal(d[1])
|
||||||
|
|
||||||
|
def parse_time(t):
|
||||||
|
'''
|
||||||
|
parse time string and return seconds as float
|
||||||
|
'''
|
||||||
|
s = 0.0
|
||||||
|
p = t.split(':')
|
||||||
|
for i in range(len(p)):
|
||||||
|
_p = p[i]
|
||||||
|
if _p.endswith('.'):
|
||||||
|
_p =_p[:-1]
|
||||||
|
s = s * 60 + float(_p)
|
||||||
|
return s
|
||||||
|
|
||||||
def plural_key(term):
|
def plural_key(term):
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue