sync facets saving annotations that are used as filters. i.e. keywords fixes #378
This commit is contained in:
parent
e03a313e77
commit
ac5c2ab9c8
2 changed files with 17 additions and 11 deletions
|
@ -160,6 +160,10 @@ class Annotation(models.Model):
|
||||||
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
||||||
update_matching_events(self.id)
|
update_matching_events(self.id)
|
||||||
|
|
||||||
|
#update facets if needed
|
||||||
|
if filter(lambda f: f['id'] == self.layer, settings.CONFIG['filters']):
|
||||||
|
self.update_layer_facet(self.layer)
|
||||||
|
|
||||||
def cleanup_undefined_relations(self):
|
def cleanup_undefined_relations(self):
|
||||||
layer = self.get_layer()
|
layer = self.get_layer()
|
||||||
if layer.get('type') == 'place':
|
if layer.get('type') == 'place':
|
||||||
|
|
|
@ -779,11 +779,7 @@ class Item(models.Model):
|
||||||
#update cached values in clips
|
#update cached values in clips
|
||||||
self.clips.all().update(director=s.director, title=s.title)
|
self.clips.all().update(director=s.director, title=s.title)
|
||||||
|
|
||||||
def update_layer_facets(self):
|
def update_layer_facet(self, key):
|
||||||
filters = [f['id'] for f in settings.CONFIG['filters']]
|
|
||||||
for layer in settings.CONFIG['layers']:
|
|
||||||
if layer['id'] in filters:
|
|
||||||
key = layer['id']
|
|
||||||
current_values = [a['value']
|
current_values = [a['value']
|
||||||
for a in self.annotations.filter(layer=key).distinct().values('value')]
|
for a in self.annotations.filter(layer=key).distinct().values('value')]
|
||||||
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
||||||
|
@ -795,6 +791,12 @@ class Item(models.Model):
|
||||||
sortvalue = value
|
sortvalue = value
|
||||||
Facet.objects.get_or_create(item=self, key=key, value=value, sortvalue=sortvalue)
|
Facet.objects.get_or_create(item=self, key=key, value=value, sortvalue=sortvalue)
|
||||||
|
|
||||||
|
def update_layer_facets(self):
|
||||||
|
filters = [f['id'] for f in settings.CONFIG['filters']]
|
||||||
|
for layer in settings.CONFIG['layers']:
|
||||||
|
if layer['id'] in filters:
|
||||||
|
self.update_layer_facet(layer['id'])
|
||||||
|
|
||||||
def update_facets(self):
|
def update_facets(self):
|
||||||
for key in self.facet_keys + ['title']:
|
for key in self.facet_keys + ['title']:
|
||||||
current_values = self.get(key, [])
|
current_values = self.get(key, [])
|
||||||
|
|
Loading…
Reference in a new issue