itemQuery

This commit is contained in:
j 2011-06-05 18:30:30 +02:00
commit 7081cd7544
4 changed files with 34 additions and 3 deletions

View file

@ -10,6 +10,7 @@ import ox
from ox.django import fields
from annotation.models import Annotation
from item.models import Item
import managers
@ -47,7 +48,9 @@ class Event(models.Model):
durationTime = models.BigIntegerField(default=0)
type = models.CharField(default='', max_length=255)
matches = models.IntegerField(default=0)
items = models.ManyToManyField(Item, blank=True, related_name='events')
def get_matches(self):
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
@ -56,7 +59,13 @@ class Event(models.Model):
return Annotation.objects.filter(q)
def update_matches(self):
self.matches = self.get_matches().count()
matches = self.get_matches()
self.matches = matches.count()
ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids):
self.items.remove(i)
for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()):
self.items.add(i)
self.save()
def save(self, *args, **kwargs):

View file

@ -96,6 +96,9 @@ def findEvents(request):
query: query object, more on query syntax at
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
itemQuery: {
//see find request
},
sort: array of key, operator dics
[
{
@ -109,6 +112,8 @@ def findEvents(request):
]
range: result range, array [from, to]
itemQuery can be used to limit the resuts to matches in those items.
with keys, items is list of dicts with requested properties:
return {'status': {'code': int, 'text': string},
'data': {items: array}}