improvent to groups and context browser

This commit is contained in:
rolux 2011-01-03 06:44:38 +00:00
commit 19f6c7d82f
4 changed files with 414 additions and 316 deletions

View file

@ -10,7 +10,7 @@ import models
def keyType(key):
if key in ('released', ):
return "date"
if key in ('year', 'cast.length'):
if key in ('cast.length', ):
return "int"
if key in ('rating', 'votes'):
return "float"

View file

@ -147,6 +147,7 @@ Positions
response = json_response({})
if 'group' in query:
'''
if 'sort' in query:
if len(query['sort']) == 1 and query['sort'][0]['key'] == 'items':
if query['group'] == "year":
@ -169,6 +170,8 @@ Positions
query['sort'][i]['key'] = name_sort
elif query['sort'][i]['key'] == 'items':
query['sort'][i]['key'] = items
print query['sort']
print '---------------------------------------------------------'
qs = _order_query(qs, query['sort'], prefix='')
if 'ids' in query:
#FIXME: this does not scale for larger results
@ -181,6 +184,40 @@ Positions
response['data']['items'] = [{'name': i[name], 'items': i[items]} for i in qs]
else:
response['data']['items'] = qs.count()
'''
if 'sort' in query:
if len(query['sort']) == 1 and query['sort'][0]['key'] == 'items':
if query['group'] == "year":
order_by = query['sort'][0]['operator'] == '-' and 'items' or '-items'
else:
order_by = query['sort'][0]['operator'] == '-' and '-items' or 'items'
if query['group'] != "keyword":
order_by = (order_by, 'value_sort')
else:
order_by = (order_by,)
else:
order_by = query['sort'][0]['operator'] == '-' and '-value_sort' or 'value_sort'
order_by = (order_by, 'items')
else:
order_by = ('-value_sort', 'items')
response['data']['items'] = []
items = 'items'
item_qs = query['qs']
qs = models.Facet.objects.filter(key=query['group']).filter(item__id__in=item_qs)
qs = qs.values('value').annotate(items=Count('id')).order_by(*order_by)
if 'ids' in query:
#FIXME: this does not scale for larger results
response['data']['positions'] = {}
ids = [j['value'] for j in qs]
response['data']['positions'] = _get_positions(ids, query['ids'])
elif 'range' in data:
qs = qs[query['range'][0]:query['range'][1]]
response['data']['items'] = [{'name': i['value'], 'items': i[items]} for i in qs]
else:
response['data']['items'] = qs.count()
elif 'ids' in query:
#FIXME: this does not scale for larger results
qs = _order_query(query['qs'], query['sort'])
@ -223,6 +260,45 @@ Positions
actions.register(find)
def autocomplete(request):
'''
param data
key
value
operator '', '^', '$'
range
return
'''
data = json.loads(request.POST['data'])
if not 'range' in data:
data['range'] = [0, 10]
#FIXME: key and sort have to be defined in site.json
if data['key'] == 'title':
qs = models.Item.objects.filter(find__key='title', find__value__icontains=data['value'])
qs = qs.order_by('-sort__votes')
qs = qs[data['range'][0]:data['range'][1]]
response = json_response({})
response['data']['items'] = [i.get('title') for i in qs]
else:
qs = models.Facet.objects.filter(key=data['key'])
op = data.get('operator', '')
if op == '':
qs = qs.filter(value__icontains=data['value'])
elif op == '^':
qs = qs.filter(value__istartswith=data['value'])
elif op == '$':
qs = qs.filter(value__iendswith=data['value'])
qs = qs.values('value').annotate(items=Count('id')).order_by('-items')
qs = qs[data['range'][0]:data['range'][1]]
response = json_response({})
response['data']['items'] = [i['value'] for i in qs]
print response
return render_to_json_response(response)
actions.register(autocomplete)
def getItem(request):
'''
param data

View file

@ -18,7 +18,19 @@
{"id": "summary", "title": "Summary"},
{"id": "dialog", "title": "Dialog"}
],
"groups": ["director", "country", "year", "language", "genre"],
"groups": [
{"id": "director", "title": "Director"},
{"id": "country", "title": "Country"},
{"id": "year", "title": "Year"},
{"id": "language", "title": "Language"},
{"id": "genre", "title": "Genre"},
{"id": "writer", "title": "Writer"},
{"id": "producer", "title": "Producer"},
{"id": "cinematographer", "title": "Cinematographer"},
{"id": "editor", "title": "Editor"},
{"id": "actor", "title": "Actor"},
{"id": "keyword", "title": "Keyword"}
],
"itemName": {
"singular": "Movie",
"plural": "Movies"
@ -61,48 +73,48 @@
{"id": "featured", "title": "Featured Lists"}
],
"sortKeys": [
{"id": "title", "title": "Title", "operator": "", "align": "left", "width": 180, "removable": false},
{"id": "director", "title": "Director", "operator": "", "align": "left", "width": 180, "removable": false},
{"id": "country", "title": "Country", "operator": "", "align": "left", "width": 120},
{"id": "year", "title": "Year", "operator": "-", "align": "right", "width": 60},
{"id": "language", "title": "Language", "operator": "", "align": "left", "width": 120},
{"id": "runtime", "title": "Runtime", "operator": "-", "align": "right", "width": 60},
{"id": "writer", "title": "Writer", "operator": "", "align": "left", "width": 180},
{"id": "producer", "title": "Producer", "operator": "", "align": "left", "width": 180},
{"id": "cinematographer", "title": "Cinematographer", "operator": "", "align": "left", "width": 180},
{"id": "editor", "title": "Editor", "operator": "", "align": "left", "width": 180},
{"id": "actors", "title": "Number of Actors", "operator": "-", "align": "right", "width": 60},
{"id": "genre", "title": "Genre", "operator": "", "align": "left", "width": 120},
{"id": "keywords", "title": "Number of Keywords", "operator": "-", "align": "right", "width": 60},
{"id": "summary", "title": "Words in Summary", "operator": "-", "align": "right", "width": 60},
{"id": "trivia", "title": "Words in Trivia", "operator": "-", "align": "right", "width": 60},
{"id": "releasedate", "title": "Release Date", "operator": "-", "align": "left", "width": 90},
{"id": "budget", "title": "Budget", "operator": "-", "align": "right", "width": 90},
{"id": "gross", "title": "Gross", "operator": "-", "align": "right", "width": 90},
{"id": "profit", "title": "Profit", "operator": "-", "align": "right", "width": 90},
{"id": "rating", "title": "Rating", "operator": "-", "align": "right", "width": 60},
{"id": "votes", "title": "Votes", "operator": "-", "align": "right", "width": 90},
{"id": "id", "title": "ID", "operator": "", "align": "left", "width": 90},
{"id": "aspectratio", "title": "Aspect Ratio", "operator": "-", "align": "left", "width": 90},
{"id": "duration", "title": "Duration", "operator": "-", "align": "right", "width": 90},
{"id": "color", "title": "Color", "operator": "", "align": "left", "width": 90},
{"id": "saturation", "title": "Saturation", "operator": "-", "align": "right", "width": 60},
{"id": "brightness", "title": "Brightness", "operator": "-", "align": "right", "width": 60},
{"id": "volume", "title": "Volume", "operator": "-", "align": "right", "width": 60},
{"id": "clips", "title": "Clips", "operator": "-", "align": "right", "width": 60},
{"id": "cuts", "title": "Cuts", "operator": "-", "align": "right", "width": 60},
{"id": "cutsperminute", "title": "Cuts per Minute", "operator": "-", "align": "right", "width": 60},
{"id": "words", "title": "Words", "operator": "-", "align": "right", "width": 60},
{"id": "wordsperminute", "title": "Words per Minute", "operator": "-", "align": "right", "width": 60},
{"id": "resolution", "title": "Resolution", "operator": "-", "align": "left", "width": 90},
{"id": "pixels", "title": "Pixels", "operator": "-", "align": "right", "width": 90},
{"id": "size", "title": "Size", "operator": "-", "align": "right", "width": 90},
{"id": "bitrate", "title": "Bitrate", "operator": "-", "align": "right", "width": 90},
{"id": "files", "title": "Files", "operator": "-", "align": "right", "width": 60},
{"id": "filename", "title": "Filename", "operator": "", "align": "left", "width": 180},
{"id": "published", "title": "Date Published", "operator": "-", "align": "left", "width": 90},
{"id": "modified", "title": "Date Modified", "operator": "-", "align": "left", "width": 90},
{"id": "popularity", "title": "Popularity", "operator": "-", "align": "left", "width": 60}
{"id": "title", "title": "Title", "width": 180, "removable": false, "type": "title", "autocompleteSortKey": "votes"},
{"id": "director", "title": "Director", "width": 180, "removable": false, "type": "person"},
{"id": "country", "title": "Country", "width": 120, "type": "text"},
{"id": "year", "title": "Year", "width": 60, "type": "year"},
{"id": "language", "title": "Language", "width": 120, "type": "text"},
{"id": "runtime", "title": "Runtime", "width": 60, "type": "integer"},
{"id": "writer", "title": "Writer", "width": 180, "type": "person"},
{"id": "producer", "title": "Producer", "width": 180, "type": "person"},
{"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"},
{"id": "editor", "title": "Editor", "width": 180, "type": "person"},
{"id": "actors", "title": "Number of Actors", "width": 60, "type": "person"},
{"id": "genre", "title": "Genre", "width": 120, "type": "text"},
{"id": "keyword", "title": "Number of Keywords", "width": 60, "type": "integer"},
{"id": "summary", "title": "Words in Summary", "width": 60, "type": "words"},
{"id": "trivia", "title": "Words in Trivia", "width": 60, "type": "words"},
{"id": "releasedate", "title": "Release Date", "width": 90, "type": "date"},
{"id": "budget", "title": "Budget", "width": 90, "type": "integer"},
{"id": "gross", "title": "Gross", "width": 90, "type": "integer"},
{"id": "profit", "title": "Profit", "width": 90, "type": "integer"},
{"id": "rating", "title": "Rating", "width": 60, "type": "float"},
{"id": "votes", "title": "Votes", "width": 90, "type": "integer"},
{"id": "id", "title": "ID", "width": 90, "type": "string"},
{"id": "aspectratio", "title": "Aspect Ratio", "width": 90, "type": "float"},
{"id": "duration", "title": "Duration", "width": 90, "type": "float"},
{"id": "color", "title": "Color", "width": 90, "type": "float"},
{"id": "saturation", "title": "Saturation", "width": 60, "type": "float"},
{"id": "brightness", "title": "Brightness", "width": 60, "type": "float"},
{"id": "volume", "title": "Volume", "width": 60, "type": "float"},
{"id": "clips", "title": "Clips", "width": 60, "type": "integer"},
{"id": "cuts", "title": "Cuts", "width": 60, "type": "integer"},
{"id": "cutsperminute", "title": "Cuts per Minute", "width": 60, "type": "float"},
{"id": "words", "title": "Words", "width": 60, "type": "integer"},
{"id": "wordsperminute", "title": "Words per Minute", "width": 60, "type": "float"},
{"id": "resolution", "title": "Resolution", "width": 90, "type": "integer"},
{"id": "pixels", "title": "Pixels", "width": 90, "type": "integer"},
{"id": "size", "title": "Size", "width": 90, "type": "integer"},
{"id": "bitrate", "title": "Bitrate", "width": 90, "type": "integer"},
{"id": "files", "title": "Files", "width": 60, "type": "integer"},
{"id": "filename", "title": "Filename", "width": 180, "type": "text"},
{"id": "published", "title": "Date Published", "width": 90, "type": "date"},
{"id": "modified", "title": "Date Modified", "width": 90, "type": "date"},
{"id": "popularity", "title": "Popularity", "type": "float"}
],
"totals": [
{"id": "items"},
@ -118,6 +130,7 @@
"ui": {
"columns": ["id", "title", "director", "country", "year", "language", "genre"],
"findQuery": {"conditions": [], "operator": ""},
"groups": ["director", "country", "year", "language", "genre"],
"groupsQuery": {"conditions": [], "operator": "|"},
"groupsSize": 176,
"item": "",