diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2013-05-22 16:40:21 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2013-05-22 16:40:21 -0600 |
commit | 81a67db76140249b20063ae8c81928489b4c02c6 (patch) | |
tree | 0ba788de1d1621f0552f2b39b62f0aee6ccba65f | |
parent | c408358465c09b91a41e03b78305273d0c2c23f7 (diff) | |
download | askbot-81a67db76140249b20063ae8c81928489b4c02c6.tar.gz askbot-81a67db76140249b20063ae8c81928489b4c02c6.tar.bz2 askbot-81a67db76140249b20063ae8c81928489b4c02c6.zip |
fixed router issue
-rw-r--r-- | askbot/search/haystack/__init__.py | 29 | ||||
-rw-r--r-- | askbot/search/haystack/routers.py | 19 |
2 files changed, 48 insertions, 0 deletions
diff --git a/askbot/search/haystack/__init__.py b/askbot/search/haystack/__init__.py index e4563fa2..aab0966c 100644 --- a/askbot/search/haystack/__init__.py +++ b/askbot/search/haystack/__init__.py @@ -43,6 +43,35 @@ class UserIndex(indexes.SearchIndex, indexes.Indexable): class AskbotSearchQuerySet(SearchQuerySet): + def _determine_backend(self): + '''This is a hack somehow connection_router got wrong values + from setting and did not loaded the LanguageRouter''' + + from haystack import connections, connection_router + # A backend has been manually selected. Use it instead. + if self._using is not None: + self.query = connections[self._using].get_query() + return + + # No backend, so rely on the routers to figure out what's right. + hints = {} + + if self.query: + hints['models'] = self.query.models + + backend_alias = connection_router.for_read(**hints) + + if isinstance(backend_alias, (list, tuple)) and len(backend_alias): + # We can only effectively read from one engine. + backend_alias = backend_alias[0] + + # The ``SearchQuery`` might swap itself out for a different variant + # here. + if self.query: + self.query = self.query.using(backend_alias) + else: + self.query = connections[backend_alias].get_query() + def get_django_queryset(self, model_klass=Thread): '''dirty hack because models() method from the SearchQuerySet does not work </3''' diff --git a/askbot/search/haystack/routers.py b/askbot/search/haystack/routers.py new file mode 100644 index 00000000..f015d954 --- /dev/null +++ b/askbot/search/haystack/routers.py @@ -0,0 +1,19 @@ +from django.utils.translation import get_language +from django.conf import settings + +from haystack.routers import BaseRouter +from haystack.constants import DEFAULT_ALIAS + +class LanguageRouter(BaseRouter): + + def for_read(self, **hints): + if getattr(settings, 'ASKBOT_MULTILINGUAL'): + return 'default_' + get_language() + else: + return DEFAULT_ALIAS + + def for_write(self, **hints): + if getattr(settings, 'ASKBOT_MULTILINGUAL'): + return 'default_' + get_language() + else: + return DEFAULT_ALIAS |