From 0de254984cd8491dc79086bddee3697587fb09dd Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 14:01:03 +0100 Subject: [PATCH 1/7] events are case insensitive --- pandora/event/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index cae266024..e5a3a1bbf 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -72,9 +72,9 @@ class Event(models.Model): q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) matches = [] for a in Annotation.objects.filter(q): - words = ox.words(a.value) + words = ox.words(a.value.lower()) for name in [self.name] + list(self.alternativeNames): - if name in words: + if name.lower() in words: matches.append(a.id) break if not matches: From 93c24419f18ab4cb984727142f86de18a707ff5f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 14:46:36 +0100 Subject: [PATCH 2/7] also match multiword names --- pandora/event/models.py | 10 +++++++--- pandora/place/models.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index e5a3a1bbf..4c4a2375c 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -2,10 +2,11 @@ # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division, with_statement +import re + from django.db import models from django.contrib.auth.models import User from django.db.models import Q - import ox from ox.django import fields @@ -72,9 +73,12 @@ class Event(models.Model): q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) matches = [] for a in Annotation.objects.filter(q): - words = ox.words(a.value.lower()) + value = a.value.lower() for name in [self.name] + list(self.alternativeNames): - if name.lower() in words: + name = name.lower() + if name in value and (value.startswith(name) or \ + value.endswith(name) or \ + re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: diff --git a/pandora/place/models.py b/pandora/place/models.py index 738bb72e1..52ecd6803 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division, with_statement -from django.db import models -import ox -from ox.django import fields +import re + +from django.db import models from django.contrib.auth.models import User, Group from django.db.models import Q +import ox +from ox.django import fields import managers from annotation.models import Annotation @@ -81,9 +83,11 @@ class Place(models.Model): q = q|Q(value__contains=" " + name)|Q(value__startswith=name) matches = [] for a in Annotation.objects.filter(q): - words = ox.words(a.value) + value = a.value for name in [self.name] + list(self.alternativeNames): - if name in words: + if name in value and (value.startswith(name) or \ + value.endswith(name) or \ + re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: From 0253cda7e1ddda5013aff0f733f81598953cfc3c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 14:50:14 +0100 Subject: [PATCH 3/7] , --- pandora/event/models.py | 2 +- pandora/place/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index 4c4a2375c..56f87d74d 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -78,7 +78,7 @@ class Event(models.Model): name = name.lower() if name in value and (value.startswith(name) or \ value.endswith(name) or \ - re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): + re.compile('\s%s[\.,;:!?\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: diff --git a/pandora/place/models.py b/pandora/place/models.py index 52ecd6803..7ab8876da 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -87,7 +87,7 @@ class Place(models.Model): for name in [self.name] + list(self.alternativeNames): if name in value and (value.startswith(name) or \ value.endswith(name) or \ - re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): + re.compile('\s%s[\.,;:!?\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: From e92f0a4d56f04552bef140c8094b504355b3a189 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 15:01:38 +0100 Subject: [PATCH 4/7] name/foo should work too --- pandora/event/models.py | 2 +- pandora/place/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index 56f87d74d..a378c4c3e 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -78,7 +78,7 @@ class Event(models.Model): name = name.lower() if name in value and (value.startswith(name) or \ value.endswith(name) or \ - re.compile('\s%s[\.,;:!?\-\s]'%name).findall(value)): + re.compile('\s%s[\.,;:!?\-\/\s]'%name).findall(value)): matches.append(a.id) break if not matches: diff --git a/pandora/place/models.py b/pandora/place/models.py index 7ab8876da..9c01b2eec 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -87,7 +87,7 @@ class Place(models.Model): for name in [self.name] + list(self.alternativeNames): if name in value and (value.startswith(name) or \ value.endswith(name) or \ - re.compile('\s%s[\.,;:!?\-\s]'%name).findall(value)): + re.compile('\s%s[\.,;:!?\-\/\s]'%name).findall(value)): matches.append(a.id) break if not matches: From fda38026520669e5edd02723e4c3f567304b69a1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 15:17:21 +0100 Subject: [PATCH 5/7] only update if number of matches changed --- pandora/event/models.py | 9 ++++++--- pandora/place/models.py | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index a378c4c3e..f7d1baaa7 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -4,7 +4,7 @@ from __future__ import division, with_statement import re -from django.db import models +from django.db import models, transaction from django.contrib.auth.models import User from django.db.models import Q import ox @@ -85,9 +85,11 @@ class Event(models.Model): matches = [-1] return Annotation.objects.filter(id__in=matches) + + @transaction.commit_on_success def update_matches(self): matches = self.get_matches() - self.matches = matches.count() + numberofmatches = matches.count() for i in self.annotations.exclude(id__in=matches): self.annotations.remove(i) for i in matches.exclude(id__in=self.annotations.all()): @@ -98,7 +100,8 @@ class Event(models.Model): for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()): self.items.add(i) #only update matches, other values might have been changed - Event.objects.filter(id=self.id).update(matches=self.matches) + if self.matches != numberofmatches: + Event.objects.filter(id=self.id).update(matches=numberofmatches) def set_name_sort(self, value=None): if not value: diff --git a/pandora/place/models.py b/pandora/place/models.py index 9c01b2eec..31ed45f40 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -4,7 +4,7 @@ from __future__ import division, with_statement import re -from django.db import models +from django.db import models, transaction from django.contrib.auth.models import User, Group from django.db.models import Q import ox @@ -94,9 +94,10 @@ class Place(models.Model): matches = [-1] return Annotation.objects.filter(id__in=matches) + @transaction.commit_on_success def update_matches(self): matches = self.get_matches() - self.matches = matches.count() + numberofmatches = matches.count() for i in self.annotations.exclude(id__in=matches): self.annotations.remove(i) for i in matches.exclude(id__in=self.annotations.all()): @@ -106,7 +107,8 @@ class Place(models.Model): self.items.remove(i) for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()): self.items.add(i) - Place.objects.filter(id=self.id).update(matches=self.matches) + if self.matches != numberofmatches: + Place.objects.filter(id=self.id).update(matches=numberofmatches) def save(self, *args, **kwargs): if not self.name_sort: From a9d9a7ca6355280d9e6ef38be19844e6cd1b7dde Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 15:27:26 +0100 Subject: [PATCH 6/7] make places case-insensitive too --- pandora/place/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora/place/models.py b/pandora/place/models.py index 31ed45f40..03d313357 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -78,13 +78,14 @@ class Place(models.Model): return j def get_matches(self): - q = Q(value__contains=" " + self.name)|Q(value__startswith=self.name) + q = Q(value__icontains=" " + self.name)|Q(value__istartswith=self.name) for name in self.alternativeNames: - q = q|Q(value__contains=" " + name)|Q(value__startswith=name) + q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name) matches = [] for a in Annotation.objects.filter(q): - value = a.value + value = a.value.lower() for name in [self.name] + list(self.alternativeNames): + name = name.lower() if name in value and (value.startswith(name) or \ value.endswith(name) or \ re.compile('\s%s[\.,;:!?\-\/\s]'%name).findall(value)): From 66c0cea92893519d91dcd9dda61cfbd2b5348fb7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 15:48:46 +0100 Subject: [PATCH 7/7] do not allow find filename if not canSeeFiles --- pandora/item/managers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora/item/managers.py b/pandora/item/managers.py index b07dea68e..cb02745d0 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -45,6 +45,10 @@ def parseCondition(condition, user): else: return q + if k == 'filename' and user.is_anonymous() or \ + not user.get_profile().capability('canSeeFiles'): + return Q(id=0) + key_type = settings.CONFIG['keys'].get(k, {'type':'string'}).get('type') if isinstance(key_type, list): key_type = key_type[0]