place/event matches

This commit is contained in:
j 2012-01-02 20:59:43 +05:30
parent f23340ddbb
commit 4c25291c88
3 changed files with 16 additions and 6 deletions

View file

@ -7,6 +7,7 @@ import re
from django.db import models, transaction from django.db import models, transaction
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db.models import Q from django.db.models import Q
from django.conf import settings
import ox import ox
from ox.django import fields from ox.django import fields
@ -68,6 +69,8 @@ class Event(models.Model):
return False return False
def get_matches(self): def get_matches(self):
layers = filter(lambda l: l['type'] == 'event' or l.get('hasEvents'),
settings.CONFIG['layers'])
super_matches = [] super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name) q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames: for name in self.alternativeNames:
@ -81,7 +84,7 @@ class Event(models.Model):
for name in self.alternativeNames: for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
matches = [] matches = []
for a in Annotation.objects.filter(q): for a in Annotation.objects.filter(layer__in=layers).filter(q):
value = a.value.lower() value = a.value.lower()
for name in super_matches: for name in super_matches:
value = value.replace(name.lower(), '') value = value.replace(name.lower(), '')

View file

@ -7,6 +7,7 @@ import re
from django.db import models, transaction from django.db import models, transaction
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.db.models import Q from django.db.models import Q
from django.conf import settings
import ox import ox
from ox.django import fields from ox.django import fields
@ -82,6 +83,8 @@ class Place(models.Model):
return j return j
def get_matches(self): def get_matches(self):
layers = filter(lambda l: l['type'] == 'place' or l.get('hasPlaces'),
settings.CONFIG['layers'])
super_matches = [] super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name) q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames: for name in self.alternativeNames:
@ -95,7 +98,7 @@ class Place(models.Model):
for name in self.alternativeNames: for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name) q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
matches = [] matches = []
for a in Annotation.objects.filter(q): for a in Annotation.objects.filter(layer__in=layers).filter(q):
value = a.value.lower() value = a.value.lower()
for name in super_matches: for name in super_matches:
value = value.replace(name.lower(), '') value = value.replace(name.lower(), '')

View file

@ -27,13 +27,17 @@ pandora.ui.placesDialog = function() {
getMatches: function(names, callback) { getMatches: function(names, callback) {
// fixme: the results of this are of course // fixme: the results of this are of course
// not identical to actual place matches // 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({ pandora.api.findClips({
query: { query: {
conditions: names.map(function(name) { conditions: names.map(function(name) {
//FIXME: this should be more generic return {key: key, value: name, operator: operator};
return Ox.getObjectById(pandora.site.layers, 'subtitles')
? {key: 'subtitles', value: name, operator: '='}
: {key: 'places', value: name, operator: '=='};
}), }),
operator: names.length == 1 ? '&' : '|' operator: names.length == 1 ? '&' : '|'
} }