'URL': 'http://search:9200/',
'INDEX_NAME': 'haystack',
'INLUDE_SPELLING': True,
- 'EXCLUDED_INDEXES': ['telemeta.search_indexes.LocationIndex']
+ 'EXCLUDED_INDEXES': ['telemeta.search_indexes.LocationIndex', 'telemeta.search_indexes.LocationAliasIndex']
},
'autocomplete': {
# 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
]
},
}
-HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
+#HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
+HAYSTACK_SIGNAL_PROCESSOR = 'telemeta.util.search_signals.RealTimeCustomSignal'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 50
BOWER_COMPONENTS_ROOT = '/srv/bower/'
'django-environ',
'redis',
'Werkzeug',
+ 'django-dirtyfields'
],
tests_require=['pytest-django', 'pytest-cov', 'factory-boy'],
# Provide a test command through django-setuptest
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):
+class MediaResource(ModelCore, DirtyFieldsMixin):
"Base class of all media objects"
def public_access_label(self):
from haystack import indexes
from telemeta.models import *
+from haystack.query import SearchQuerySet
class KeywordField(indexes.CharField):
field_type = 'keyword'
def index_queryset(self, using=None):
return MediaItem.objects.all().locations()
+
+class LocationAliasIndex(indexes.SearchIndex, indexes.Indexable):
+
+ text = indexes.CharField(document=True, use_template=True)
+
+ def get_model(self):
+ return LocationAlias
+
+ def index_queryset(self, using=None):
+ l = MediaItem.objects.values('location')
+ return LocationAlias.objects.filter(location__in=l)
\ No newline at end of file
--- /dev/null
+{{ object.alias }}
\ No newline at end of file
--- /dev/null
+from django.db import models
+from haystack import signals
+from telemeta.models import *
+
+class RealTimeCustomSignal(signals.RealtimeSignalProcessor):
+
+ def __init__(self, *args, **kwargs):
+ super(RealTimeCustomSignal, self).__init__(*args, **kwargs)
+ self.update_list = []
+
+ def handle_pre_save(self, sender, instance, **kwargs):
+ import sys
+ if(sender == MediaItem):
+ print(sender, instance.is_dirty(check_relationship=True), instance.get_dirty_fields(check_relationship=True))
+ sys.stdout.flush()
+ if sender == MediaItem and instance.is_dirty(check_relationship=True) and instance.get_dirty_fields(check_relationship=True).has_key('location'):
+ self.update_list.append(Location)
+
+ def handle_save(self, sender, instance, **kwargs):
+ import sys
+ if sender == MediaItem and sender in self.update_list:
+ print("OKOK")
+ sys.stdout.flush()
+ del self.update_list[:]
+ print("okk")
+ sys.stdout.flush()
+ 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