list/enum, support find resolution

This commit is contained in:
j 2011-11-10 21:22:58 +00:00
parent e92fff7f42
commit 72c0917d2c
3 changed files with 22 additions and 7 deletions

View file

@ -306,7 +306,9 @@
"id": "resolution",
"title": "Resolution",
"type": ["integer"],
"columnWidth": 90
"capability": "canSeeFiles",
"columnWidth": 90,
"format": {"type": "resolution", "args": ["px"]}
},
{
"id": "aspectratio",
@ -319,6 +321,7 @@
"id": "pixels",
"title": "Pixels",
"type": "integer",
"capability": "canSeeFiles",
"columnWidth": 90,
"format": {"type": "value", "args": ["px"]}
},
@ -393,7 +396,7 @@
"type": "integer",
"capability": "canSeeFiles",
"columnWidth": 60,
"format": {"type": "value", "args": ["bps"]}
"format": {"type": "unit", "args": ["kbps", 0, 0.001]}
},
{
"id": "parts",
@ -447,13 +450,13 @@
{
"id": "rightslevel",
"title": "Rights Level",
"type": "list",
"type": "enum",
"columnWidth": 90,
"format": {"type": "ColorLevel", "args": [
["Public", "Relaxed", "Regular", "Restricted", "Private"]
]},
"list": ["Public", "Relaxed", "Regular", "Restricted", "Private", "Unknown"],
"sortOperator": "+"
"sortOperator": "+",
"values": ["Public", "Relaxed", "Regular", "Restricted", "Private", "Unknown"]
},
{
"id": "canplayvideo",

View file

@ -59,6 +59,12 @@ def parseCondition(condition, user):
elif k == 'filename' and (user.is_anonymous() or \
not user.get_profile().capability('canSeeFiles')):
return Q(id=0)
elif k == 'resolution':
q = parseCondition({'key': 'width', 'value': v[0], 'operator': op}, user) \
& parseCondition({'key': 'height', 'value': v[1], 'operator': op}, user)
if exclude:
q = ~q
return q
elif isinstance(v, list) and len(v) == 2:
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)

View file

@ -606,6 +606,8 @@ class Item(models.Model):
'pixels',
'timesaccessed',
'resolution',
'width',
'height',
'rightslevel',
'saturation',
'size',
@ -678,6 +680,8 @@ class Item(models.Model):
s.duration = sum([v.duration for v in videos])
v = videos[0]
s.resolution = v.width * v.height
s.width = v.width
s.height = v.height
if not s.aspectratio:
s.aspectratio = float(utils.parse_decimal(v.display_aspect_ratio))
s.pixels = sum([v.pixels for v in videos])
@ -1156,8 +1160,10 @@ attrs = {
'__module__': 'item.models',
'item': models.OneToOneField('Item', related_name='sort', primary_key=True),
'duration': models.FloatField(null=True, blank=True, db_index=True),
'width': models.BigIntegerField(null=True, blank=True, db_index=True),
'height': models.BigIntegerField(null=True, blank=True, db_index=True),
}
for key in filter(lambda k: 'columnWidth' in k or k['type'] in ('integer', 'time', 'float', 'date', 'list'), settings.CONFIG['itemKeys']):
for key in filter(lambda k: 'columnWidth' in k or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['itemKeys']):
name = key['id']
name = {'id': 'itemId'}.get(name, name)
sort_type = key.get('sort', key['type'])
@ -1179,7 +1185,7 @@ for key in filter(lambda k: 'columnWidth' in k or k['type'] in ('integer', 'time
'date': 'date',
'hue': 'float',
'time': 'integer',
'list': 'integer',
'enum': 'integer',
}.get(sort_type, sort_type)]
attrs[name] = model[0](**model[1])