forked from 0x2620/pandora
event matches
This commit is contained in:
parent
06db65f475
commit
1db636d8c1
1 changed files with 23 additions and 4 deletions
|
@ -4,10 +4,12 @@ from __future__ import division, with_statement
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
from ox.django import fields
|
from ox.django import fields
|
||||||
|
|
||||||
|
from annotation.models import Annotation
|
||||||
import managers
|
import managers
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,12 +36,28 @@ class Event(models.Model):
|
||||||
ordering = ('name_sort', )
|
ordering = ('name_sort', )
|
||||||
|
|
||||||
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00
|
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00
|
||||||
#end yyyy-mm-dd|mm-dd|dow 00:00|00:01
|
|
||||||
start = models.CharField(default='', max_length=255)
|
start = models.CharField(default='', max_length=255)
|
||||||
end = models.CharField(default='', max_length=255)
|
|
||||||
startTime = models.BigIntegerField(default=0)
|
startTime = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
|
#end yyyy-mm-dd|mm-dd|dow 00:00|00:01
|
||||||
|
end = models.CharField(default='', max_length=255)
|
||||||
endTime = models.BigIntegerField(default=0)
|
endTime = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
|
duration = models.CharField(default='', max_length=255)
|
||||||
|
durationTime = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
type = models.CharField(default='', max_length=255)
|
type = models.CharField(default='', max_length=255)
|
||||||
|
matches = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
def get_matches(self):
|
||||||
|
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
|
||||||
|
for name in self.alternativeNames:
|
||||||
|
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
|
||||||
|
return Annotation.objects.filter(q)
|
||||||
|
|
||||||
|
def update_matches(self):
|
||||||
|
self.matches = self.get_matches().count()
|
||||||
|
self.save()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.name_sort:
|
if not self.name_sort:
|
||||||
|
@ -56,7 +74,8 @@ class Event(models.Model):
|
||||||
'user': self.user.username,
|
'user': self.user.username,
|
||||||
}
|
}
|
||||||
for key in ('created', 'modified',
|
for key in ('created', 'modified',
|
||||||
'name', 'alternativeNames', 'start', 'end',
|
'name', 'alternativeNames',
|
||||||
'type'):
|
'start', 'end', 'duration',
|
||||||
|
'type', 'matches'):
|
||||||
j[key] = getattr(self, key)
|
j[key] = getattr(self, key)
|
||||||
return j
|
return j
|
||||||
|
|
Loading…
Reference in a new issue