add option to sort by number of annotations per layer

This commit is contained in:
j 2015-09-03 00:52:20 +02:00
parent ace04688f2
commit fd2992c588
2 changed files with 12 additions and 1 deletions

View file

@ -578,6 +578,14 @@
"sort": true, "sort": true,
"value": {"layer": "subtitles", "type": "wordsperminute"} "value": {"layer": "subtitles", "type": "wordsperminute"}
}, },
{
"id": "numberofnotes",
"title": "Number of Notes",
"type": "integer",
"columnWidth": 60,
"sort": true,
"value": {"layer": "notes", "type": "length"}
},
{ {
"id": "numberofdocuments", "id": "numberofdocuments",
"title": "Number of Documents", "title": "Number of Documents",

View file

@ -999,6 +999,9 @@ class Item(models.Model):
set_value(s, name, value) set_value(s, name, value)
elif sort_type in ('length', 'integer', 'time', 'float'): elif sort_type in ('length', 'integer', 'time', 'float'):
#can be length of strings or length of arrays, i.e. keywords #can be length of strings or length of arrays, i.e. keywords
if 'layer' in key.get('value', []):
value = self.annotations.filter(layer=key['value']['layer']).count()
else:
value = self.get(source) value = self.get(source)
if isinstance(value, list): if isinstance(value, list):
value = len(value) value = len(value)