Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Fix for #200 - missing slug in search index update. #201

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aldryn_faq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import unicode_literals

__version__ = '2.1.2'
__version__ = '2.2.0'

# TODO: Check if these are still required
request_faq_category_identifier = 'aldryn_faq_current_category'
Expand Down
32 changes: 32 additions & 0 deletions aldryn_faq/migrations/0016_auto_20200130_1618.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-01-30 16:18
from __future__ import unicode_literals

from django.db import migrations
import django.db.models.deletion
import parler.fields


class Migration(migrations.Migration):

dependencies = [
('aldryn_faq', '0015_auto_20180329_1324'),
]

operations = [
migrations.AlterField(
model_name='categorytranslation',
name='master',
field=parler.fields.TranslationsForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='translations', to='aldryn_faq.Category'),
),
migrations.AlterField(
model_name='faqconfigtranslation',
name='master',
field=parler.fields.TranslationsForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='translations', to='aldryn_faq.FaqConfig'),
),
migrations.AlterField(
model_name='questiontranslation',
name='master',
field=parler.fields.TranslationsForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='translations', to='aldryn_faq.Question'),
),
]
6 changes: 6 additions & 0 deletions aldryn_faq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def get_absolute_url(self, language=None, slug=None):
slug = self.known_translation_getter(
'slug', default=None, language_code=language)[0] or ''

if not slug:
slug = self.slug

kwargs = {}
try:
permalink_type = self.appconfig.permalink_type
Expand Down Expand Up @@ -198,6 +201,9 @@ def get_absolute_url(self, language=None):
question_slug = self.known_translation_getter(
'slug', default='', language_code=language)[0]

if not question_slug:
question_slug = self.slug

try:
namespace = self.category.appconfig.namespace
except AttributeError:
Expand Down
20 changes: 18 additions & 2 deletions aldryn_faq/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def get_search_data(self, obj, language, request):

return ' '.join(text_bits)

def get_index_kwargs(self, language):
return {'translations__language_code': language}

def get_language(self, obj):
if hasattr(obj, 'language_code'):
return obj.language_code
return None


class CategoryIndex(get_index_base()):

Expand All @@ -59,12 +67,20 @@ def get_title(self, obj):
return obj.safe_translation_getter('name')

def get_index_queryset(self, language):
categories = self.get_model().objects.language(language)
return categories.active_translations(language)
categories = self.get_model().objects.language(language).active_translations(language)
return categories

def get_model(self):
return Category

def get_search_data(self, obj, language, request):
with switch_language(obj):
return strip_tags(obj.safe_translation_getter('name'))

def get_index_kwargs(self, language):
return {'translations__language_code': language}

def get_language(self, obj):
if hasattr(obj, 'language_code'):
return obj.language_code
return None
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

REQUIREMENTS = [
'aldryn-apphooks-config>=0.4.0',
'aldryn-boilerplates>=0.7.4,<0.8',
'aldryn-boilerplates>=0.7.4',
'aldryn-search',
'aldryn-translation-tools>=0.2.1',
'django>=1.8,<2.0',
'django>=1.8', # TODO: Check Django 2.0+
'django-admin-sortable2>=0.5.2',
'django-cms>=3.4',
'djangocms-text-ckeditor',
Expand All @@ -34,6 +34,8 @@
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Application Frameworks',
Expand Down