'URL': 'http://search:9200/',
'INDEX_NAME': 'haystack',
'INLUDE_SPELLING': True,
- 'EXCLUDED_INDEXES': ['telemeta.search_indexes.LocationIndex', 'telemeta.search_indexes.LocationAliasIndex']
+ 'EXCLUDED_INDEXES': ['telemeta.search_indexes.LocationIndex',
+ 'telemeta.search_indexes.LocationAliasIndex',
+ 'telemeta.search_indexes.InstrumentIndex',
+ 'telemeta.search_indexes.InstrumentAliasIndex'
+ ]
},
'autocomplete': {
# 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
# If this is True, all tasks will be executed locally by blocking until the task returns.
CELERY_ALWAYS_EAGER=False
-REINDEX=False
+REINDEX=True
DATASTART=False
from telemeta.util.kdenlive_session import *
from telemeta.util.unaccent import unaccent_icmp
from xml.dom.minidom import getDOMImplementation
-
+from dirtyfields import DirtyFieldsMixin
PUBLIC_ACCESS_CHOICES = (('none', _('none')), ('metadata', _('metadata')),
('mixed', _('mixed')), ('full', _('full')))
abstract = True
-class ModelCore(EnhancedModel):
+class ModelCore(EnhancedModel, DirtyFieldsMixin):
@classmethod
def required_fields(cls):
from telemeta.models.resource import *
from telemeta.models.enum import *
-
item_published_code_regex = getattr(settings, 'ITEM_PUBLISHED_CODE_REGEX', '[A-Za-z0-9._-]*')
item_unpublished_code_regex = getattr(settings, 'ITEM_UNPUBLISHED_CODE_REGEX', '[A-Za-z0-9._-]*')
'publishing_date', 'scientist', 'topic',
'summary', 'contributor', 'public_access']
-
def keywords(self):
return ContextKeyword.objects.filter(item_relations__item = self)
keywords.verbose_name = _('keywords')
from django.utils.translation import ugettext_lazy as _
from telemeta.models.core import *
from telemeta.models.system import *
-from dirtyfields import DirtyFieldsMixin
-class MediaResource(ModelCore, DirtyFieldsMixin):
+class MediaResource(ModelCore):
"Base class of all media objects"
def public_access_label(self):
def index_queryset(self, using=None):
l = MediaItem.objects.values('location')
- return LocationAlias.objects.filter(location__in=l)
\ No newline at end of file
+ return LocationAlias.objects.filter(location__in=l)
+
+
+class InstrumentIndex(indexes.SearchIndex, indexes.Indexable):
+
+ text = indexes.CharField(document=True, use_template=True)
+
+ def get_model(self):
+ return Instrument
+
+ def index_queryset(self, using=None):
+ instrus = MediaItemPerformance.objects.values('instrument')
+ return Instrument.objects.filter(pk__in=instrus)
+
+
+class InstrumentAliasIndex(indexes.SearchIndex, indexes.Indexable):
+
+ text = indexes.CharField(document=True, use_template=True)
+
+ def get_model(self):
+ return InstrumentAlias
+
+ def index_queryset(self, using=None):
+ instrualias = MediaItemPerformance.objects.values('alias')
+ return InstrumentAlias.objects.filter(pk__in=instrualias)
\ No newline at end of file
--- /dev/null
+{{ object.name }}
\ No newline at end of file
--- /dev/null
+{{ object.name }}
\ No newline at end of file
from telemeta.search_indexes import *
from django.db.models import Q
-class RealTimeCustomSignal(signals.RealtimeSignalProcessor):
- handleModels = (MediaItem,)
+class RealTimeCustomSignal(signals.RealtimeSignalProcessor):
+ handleFields = ('location', 'instrument', 'alias')
+ handleModels = (MediaItem, MediaItemPerformance, )
def __init__(self, *args, **kwargs):
super(RealTimeCustomSignal, self).__init__(*args, **kwargs)
- self.update_model = None
+ self.update_fields = []
- def post_save_mediaitem(self, object):
- if object.get_dirty_fields(check_relationship=True).has_key('location'):
- id = object.get_dirty_fields(check_relationship=True).get('location')
- locs = Location.objects.filter(Q(pk=id)|Q(past_names__pk=id)|Q(descendant_relations__location__pk=id))
- localias = LocationAlias.objects.filter(location__id=id)
+ def post_save_location(self, object):
+ id = object.get_dirty_fields(check_relationship=True).get('location')
+ locs = Location.objects.filter(Q(pk=id) | Q(past_names__pk=id) | Q(descendant_relations__location__pk=id))
+ localias = LocationAlias.objects.filter(location__id=id)
+ for loc in locs:
+ LocationIndex().remove_object(instance=loc, using='autocomplete')
+ for loc in localias:
+ LocationAliasIndex().remove_object(instance=loc, using='autocomplete')
+ if object.location is not None:
+ locs = MediaItem.objects.filter(id=object.id).locations()
+ localias = LocationAlias.objects.filter(location__pk=object.location.id)
for loc in locs:
- LocationIndex().remove_object(instance=loc, using='autocomplete')
+ LocationIndex().update_object(instance=loc, using='autocomplete')
for loc in localias:
- LocationAliasIndex().remove_object(instance=loc, using='autocomplete')
- if object.location is not None:
- locs = MediaItem.objects.filter(id=object.id).locations()
- localias = LocationAlias.objects.filter(location__pk=object.location.id)
- for loc in locs:
- LocationIndex().update_object(instance=loc, using='autocomplete')
- for loc in localias:
- LocationAliasIndex().update_object(instance=loc, using='autocomplete')
+ LocationAliasIndex().update_object(instance=loc, using='autocomplete')
+
+
+ def post_save_instrument(self, object):
+ id = object.get_dirty_fields(check_relationship=True).get('instrument')
+ if id is not None:
+ instru = Instrument.objects.get(pk=id)
+ InstrumentIndex().remove_object(instance=instru, using='autocomplete')
+ if object.instrument is not None:
+ newinstru = Instrument.objects.get(id=object.instrument.id)
+ InstrumentIndex().update_object(instance=newinstru, using='autocomplete')
+
+ def post_save_alias(self, object):
+ id = object.get_dirty_fields(check_relationship=True).get('alias')
+ if id is not None:
+ alias = InstrumentAlias.objects.get(pk=id)
+ InstrumentAliasIndex().remove_object(instance=alias, using='autocomplete')
+ if object.alias is not None:
+ newalias = InstrumentAlias.objects.get(id=object.alias.id)
+ InstrumentAliasIndex().update_object(instance=newalias, using='autocomplete')
def handle_pre_save(self, sender, instance, **kwargs):
if sender in self.handleModels and instance.is_dirty(check_relationship=True):
- self.update_model = sender
+ for field in instance.get_dirty_fields(check_relationship=True).keys():
+ if field in self.handleFields:
+ self.update_fields.append(field)
+
+ def handle_pre_delete(self, sender, instance, **kwargs):
+ InstrumentIndex().remove_object(instance=instance.instrument, using='autocomplete')
+ InstrumentAliasIndex().remove_object(instance=instance.alias, using='autocomplete')
def handle_save(self, sender, instance, **kwargs):
- if sender == self.update_model:
- getattr(self, "post_save_%s" % str(sender).split('.')[-1][:-2].lower())(instance)
- self.update_model = None
+ import sys
+ print(sender, self.update_fields)
+ sys.stdout.flush()
+ if sender in self.handleModels:
+ for field in self.update_fields:
+ getattr(self, "post_save_%s" % field)(instance)
+ del self.update_fields[:]
super(RealTimeCustomSignal, self).handle_save(sender, instance, **kwargs)
def setup(self):
super(RealTimeCustomSignal, self).setup()
- models.signals.pre_save.connect(self.handle_pre_save)
\ No newline at end of file
+ models.signals.pre_save.connect(self.handle_pre_save)
+ models.signals.pre_delete.connect(self.handle_pre_delete, sender=MediaItemPerformance)
return extra
def autocomplete(request):
+ attribut = request.GET.get('attr', '')
sqs = SearchQuerySet().load_all()
- if request.GET.get('attr', '') == "instruments":
- if request.GET.get('attr', '') == "instruments":
- sqs = sqs.filter(instruments__startswith=request.GET.get('q', ''))
- objets = [result.instruments for result in sqs]
- #instrus = [result.instruments for result in sqs]
- #elif request.GET.get('attr', '') == "location":
- # sqs = sqs.filter(SQ(location_principal__startswith=request.GET.get('q', ''))|SQ(location_relation__startswith=request.GET.get('q', '')))
- # objets = [result.location_principal+result.location_relation for result in sqs]
- suggestions = []
- for chaine in objets :
- #for chaine in instrus:
- for word in chaine.split('|'):
- if word != "" and escapeAccentAndLower(request.GET.get('q', '')) in escapeAccentAndLower(word):
- suggestions.append(word)
- elif request.GET.get('attr', '') == "code":
+ if attribut == "code":
sqs = sqs.filter(code__contains=request.GET.get('q', ''))
suggestions = [result.code for result in sqs]
- elif request.GET.get('attr', '') == "collectors":
+ elif attribut == "collectors":
sqs = sqs.filter(collectors__startswith=request.GET.get('q', ''))
collecteurs = [result.collectors for result in sqs]
suggestions = []
for word in chaine.split('; '):
if word != "" and escapeAccentAndLower(request.GET.get('q', '')) in escapeAccentAndLower(word):
suggestions.append(word)
- elif request.GET.get('attr', '') == "location":
- sqs = SearchQuerySet().using('autocomplete').filter(content__startswith=request.GET.get('q', ''))
+ elif attribut == "location" or attribut == "instruments":
+ sqs = SearchQuerySet().using('autocomplete')
+
+ if attribut == "location":
+ sqs = sqs.models(Location, LocationAlias)
+ else:
+ sqs = sqs.models(Instrument, InstrumentAlias)
+ sqs = sqs.filter(content__startswith=request.GET.get('q', ''))
suggestions = [obj.text for obj in sqs]
else:
suggestions = []