diff options
| author | Tim Schilling <schillingt@better-simple.com> | 2025-09-01 14:10:16 -0500 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2025-11-07 21:52:48 +0100 |
| commit | 21e05b884677eefb701adc960ad1d66f9a4eff72 (patch) | |
| tree | 6bdbb51018fb804dfabcea5322e4442a94b180d3 /blog | |
| parent | 1bb7ff7782e24f7e4957a6f8cb611b3966fe0cd2 (diff) | |
Added support for searching ecosystem and blog entries.
The blog results should have a property of whether it is included in
the search results.
* Added is_searchable.
* Used Entry.get_absolute_url to encapsulate www host.
* Extracted get_search_config helper function.
Co-authored-by: Baptiste Mispelon <bmispelon@gmail.com>
Diffstat (limited to 'blog')
| -rw-r--r-- | blog/admin.py | 11 | ||||
| -rw-r--r-- | blog/migrations/0006_entry_is_searchable.py | 21 | ||||
| -rw-r--r-- | blog/models.py | 11 | ||||
| -rw-r--r-- | blog/tests.py | 20 |
4 files changed, 60 insertions, 3 deletions
diff --git a/blog/admin.py b/blog/admin.py index 04e29714..ceabd0ff 100644 --- a/blog/admin.py +++ b/blog/admin.py @@ -11,8 +11,15 @@ from .models import ContentFormat, Entry, Event, ImageUpload @admin.register(Entry) class EntryAdmin(admin.ModelAdmin): - list_display = ("headline", "pub_date", "is_active", "is_published", "author") - list_filter = ("is_active",) + list_display = ( + "headline", + "pub_date", + "is_active", + "is_published", + "is_searchable", + "author", + ) + list_filter = ("is_active", "is_searchable") exclude = ("summary_html", "body_html") prepopulated_fields = {"slug": ("headline",)} raw_id_fields = ["social_media_card"] diff --git a/blog/migrations/0006_entry_is_searchable.py b/blog/migrations/0006_entry_is_searchable.py new file mode 100644 index 00000000..72f9bab8 --- /dev/null +++ b/blog/migrations/0006_entry_is_searchable.py @@ -0,0 +1,21 @@ +# Generated by Django 5.2 on 2025-09-03 20:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("blog", "0005_entry_social_media_card"), + ] + + operations = [ + migrations.AddField( + model_name="entry", + name="is_searchable", + field=models.BooleanField( + default=False, + help_text="Tick to make this entry appear in the Django documentation search.", + ), + ), + ] diff --git a/blog/models.py b/blog/models.py index bceb067d..a5e629ad 100644 --- a/blog/models.py +++ b/blog/models.py @@ -37,6 +37,9 @@ class EntryQuerySet(models.QuerySet): def active(self): return self.filter(is_active=True) + def searchable(self): + return self.filter(is_searchable=True) + class ContentFormat(models.TextChoices): REST = "reST", "reStructuredText" @@ -126,6 +129,12 @@ class Entry(models.Model): ), default=False, ) + is_searchable = models.BooleanField( + default=False, + help_text=_( + "Tick to make this entry appear in the Django documentation search." + ), + ) pub_date = models.DateTimeField( verbose_name=_("Publication date"), help_text=_( @@ -168,7 +177,7 @@ class Entry(models.Model): "day": self.pub_date.strftime("%d").lower(), "slug": self.slug, } - return reverse("weblog:entry", kwargs=kwargs) + return reverse("weblog:entry", kwargs=kwargs, host="www") def is_published(self): """ diff --git a/blog/tests.py b/blog/tests.py index 9105e449..39cf4824 100644 --- a/blog/tests.py +++ b/blog/tests.py @@ -68,6 +68,26 @@ class EntryTestCase(DateTimeMixin, TestCase): transform=lambda entry: entry.headline, ) + def test_manager_searchable(self): + """ + Make sure that the Entry manager's `searchable` method works + """ + Entry.objects.create( + pub_date=self.yesterday, + is_searchable=False, + headline="not searchable", + slug="a", + ) + Entry.objects.create( + pub_date=self.yesterday, is_searchable=True, headline="searchable", slug="b" + ) + + self.assertQuerySetEqual( + Entry.objects.searchable(), + ["searchable"], + transform=lambda entry: entry.headline, + ) + def test_docutils_safe(self): """ Make sure docutils' file inclusion directives are disabled by default. |
