google-code-export / django-page-cms

Automatically exported from code.google.com/p/django-page-cms
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

haystack and LANGUAGE_PREFIX do not work together #206

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set PAGE_USE_LANGUAGE_PREFIX  = True in settings.py
2. Use haystack as search backend for your site
3. After filling some content try to perform a search

What is the expected output? What do you see instead?
I expected that get_url_path will return to haystack something like 
http://example.com/en/some-content

Instead this is what I get: http://example.com/None/some-content

Original issue reported on code.google.com by jozef.ma...@gmail.com on 24 Jul 2010 at 12:39

GoogleCodeExporter commented 9 years ago
I created a fix for your issue:

http://github.com/batiste/django-page-cms/commit/0f6e7de935d9f2cddf1980b56eb9e17
fc0a8827d

Could check if it works?

Original comment by batiste....@gmail.com on 13 Sep 2010 at 10:34

GoogleCodeExporter commented 9 years ago
Unfortunately still not work.

Relevant sections from settings.py

DEFAULT_LANGUAGE  = 'en'
PAGE_LANGUAGES = (
     ('sk', gettext_noop('Slovak')),
     ('en', gettext_noop('English')),
)
PAGE_USE_LANGUAGE_PREFIX  = True

Relevant sections from urls.py:
urlpatterns += patterns('',
  (r'^authority/',  include('authority.urls')),
  (r'^i18n/',       include('django.conf.urls.i18n')),
  (r'^search/',     include('haystack.urls')),
  (r'^',            include('pages.urls')),
)

Template code in pages/templates/search/search.html
{% for result in page.object_list %}
<a href="{{ result.object.get_url_path }}">{{ result.object.title }}</a>
{% endfor %}

Patch was applied correctly.

What is happening now:
as default language is set to 'en' search is performed in English. Every result 
now have language prefix '/en/'.
I think this is because in search logic (not sure if Haystack or in Pages) do 
not push language parameter. 

In get_url_path we have this:
 if not language:
   language = settings.PAGE_DEFAULT_LANGUAGE
 url = reverse('pages-root')
 if settings.PAGE_USE_LANGUAGE_PREFIX:
   url += str(language) + '/'
 return url + self.get_complete_slug(language)

We are not getting language parameter so pages will apply 'if not language' 
condition.

Original comment by jozef.ma...@gmail.com on 13 Sep 2010 at 1:16

GoogleCodeExporter commented 9 years ago
The issue is that {{ result.object.get_url_path }} doesn't not pass any 
language parameter.

If you want the current language passed there is a special tag provided by the 
CMS:

{% show_absolute_url page_object %}...

More infos here:

http://packages.python.org/django-page-cms/display-content.html#show-absolute-ur
l

Original comment by batiste....@gmail.com on 24 Sep 2010 at 8:14