From 4c25291c88a02bd09d12f6115e85b42543772c91 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 2 Jan 2012 20:59:43 +0530 Subject: [PATCH] place/event matches --- pandora/event/models.py | 5 ++++- pandora/place/models.py | 5 ++++- static/js/pandora/placesDialog.js | 12 ++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index d7e525d5..89f55700 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -7,6 +7,7 @@ import re from django.db import models, transaction from django.contrib.auth.models import User from django.db.models import Q +from django.conf import settings import ox from ox.django import fields @@ -68,6 +69,8 @@ class Event(models.Model): return False def get_matches(self): + layers = filter(lambda l: l['type'] == 'event' or l.get('hasEvents'), + settings.CONFIG['layers']) super_matches = [] q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name) for name in self.alternativeNames: @@ -81,7 +84,7 @@ class Event(models.Model): for name in self.alternativeNames: q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) matches = [] - for a in Annotation.objects.filter(q): + for a in Annotation.objects.filter(layer__in=layers).filter(q): value = a.value.lower() for name in super_matches: value = value.replace(name.lower(), '') diff --git a/pandora/place/models.py b/pandora/place/models.py index 57c7beaa..745e5e62 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -7,6 +7,7 @@ import re from django.db import models, transaction from django.contrib.auth.models import User, Group from django.db.models import Q +from django.conf import settings import ox from ox.django import fields @@ -82,6 +83,8 @@ class Place(models.Model): return j def get_matches(self): + layers = filter(lambda l: l['type'] == 'place' or l.get('hasPlaces'), + settings.CONFIG['layers']) super_matches = [] q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name) for name in self.alternativeNames: @@ -95,7 +98,7 @@ class Place(models.Model): for name in self.alternativeNames: q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name) matches = [] - for a in Annotation.objects.filter(q): + for a in Annotation.objects.filter(layer__in=layers).filter(q): value = a.value.lower() for name in super_matches: value = value.replace(name.lower(), '') diff --git a/static/js/pandora/placesDialog.js b/static/js/pandora/placesDialog.js index 71a64024..05f87d98 100644 --- a/static/js/pandora/placesDialog.js +++ b/static/js/pandora/placesDialog.js @@ -27,13 +27,17 @@ pandora.ui.placesDialog = function() { getMatches: function(names, callback) { // fixme: the results of this are of course // not identical to actual place matches + var key = pandora.site.layers.filter(function(layer) { + return layer.type == 'place' || layer.hasPlaces; + }).map(function(layer) { + return layer.id; + })[0], + operator = Ox.getObjectById(pandora.site.layers, key).type == 'place' ? + '==' : '='; pandora.api.findClips({ query: { conditions: names.map(function(name) { - //FIXME: this should be more generic - return Ox.getObjectById(pandora.site.layers, 'subtitles') - ? {key: 'subtitles', value: name, operator: '='} - : {key: 'places', value: name, operator: '=='}; + return {key: key, value: name, operator: operator}; }), operator: names.length == 1 ? '&' : '|' }