From 9850f46087255c88b0e240e0ba328231e9ec445e Mon Sep 17 00:00:00 2001
From: Anselm Lingnau <anselm@anselms.net>
Date: Sat, 28 Mar 2020 02:05:06 +0100
Subject: [PATCH] feature: Do full-text search in the current user's language.

This should have been added the first time around but seems to have
been forgotten.
---
 blog/views.py                   |   6 +-
 locale/en/LC_MESSAGES/django.po | 120 +++++++++++++++++++++-----------
 2 files changed, 82 insertions(+), 44 deletions(-)

diff --git a/blog/views.py b/blog/views.py
index 01eb991..20d2da8 100644
--- a/blog/views.py
+++ b/blog/views.py
@@ -262,12 +262,14 @@ class SearchView(PrivilegedMixin, FormView):
 
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
+        user = self.request.user
+        language = user.profile.language
         text = self.request.GET.get('text', '')
         if text:
             context['results'] = Entry.objects.filter(
-                status='published', language='de',
+                status='published', language=language,
                 date_posted__year__gt=1900,
-                search=SearchQuery(text, config='de'))
+                search=SearchQuery(text, config=language))
         else:
             context['results'] = []
         return context
diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po
index d0af77b..bcbf787 100644
--- a/locale/en/LC_MESSAGES/django.po
+++ b/locale/en/LC_MESSAGES/django.po
@@ -6,8 +6,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Evas Blog 0.1\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-05-05 02:30+0200\n"
-"PO-Revision-Date: 2019-05-05 02:31+0200\n"
+"POT-Creation-Date: 2020-03-28 02:07+0100\n"
+"PO-Revision-Date: 2020-03-28 02:14+0100\n"
 "Last-Translator: Anselm Lingnau <anselm@anselms.net>\n"
 "Language-Team: Anselm Lingnau <anselm@anselms.net>\n"
 "Language: en\n"
@@ -16,39 +16,39 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
-#: blog/models.py:16 main/settings.py:140
+#: blog/models.py:23 main/settings.py:151
 msgid "Deutsch"
 msgstr "German"
 
-#: blog/models.py:17 main/settings.py:141
+#: blog/models.py:24 main/settings.py:152
 msgid "Englisch"
 msgstr "English"
 
-#: blog/models.py:29
+#: blog/models.py:41
 msgid "Entwurf (nur für Administratoren sichtbar)"
 msgstr "Draft (only visible to administrators)"
 
-#: blog/models.py:30
+#: blog/models.py:42
 msgid "Privat (nur für Administratoren sichtbar)"
 msgstr "Private (only visible to administrators)"
 
-#: blog/models.py:32
+#: blog/models.py:44
 msgid "Veröffentlicht (für alle Besucher der Seite sichtbar)"
 msgstr "Published (visible to all site visitors)"
 
-#: blog/models.py:36 blog/models.py:62
+#: blog/models.py:48 blog/models.py:130
 msgid "Sprache"
 msgstr "Language"
 
-#: blog/models.py:38
+#: blog/models.py:50
 msgid "Überschrift"
 msgstr "Title"
 
-#: blog/models.py:40
+#: blog/models.py:52
 msgid "Inhalt"
 msgstr "Content"
 
-#: blog/models.py:41
+#: blog/models.py:53
 #, python-format
 msgid ""
 "Erlaubt Textauszeichnung/Formatierung mit Markdown (siehe <a target=\"_blank"
@@ -57,11 +57,11 @@ msgstr ""
 "Allows highlighting/formatting using Markdown (see <a target=\"_blank\"\n"
 "href=\"%(url)s\">cheat sheet</a>)."
 
-#: blog/models.py:45
+#: blog/models.py:57
 msgid "Veröffentlichungszeitpunkt"
 msgstr "Publication Date"
 
-#: blog/models.py:46
+#: blog/models.py:58
 msgid ""
 "Der Beitrag ist ab diesem Zeitpunkt für Besucher der Seite sichtbar. "
 "Rückdatieren von Beiträgen ist möglich."
@@ -69,67 +69,84 @@ msgstr ""
 "The entry is visible to site visitors from this point in\n"
 "time. Backdating entries is possible."
 
-#: blog/models.py:51
+#: blog/models.py:63
+msgid "Bild"
+msgstr "Picture"
+
+#: blog/models.py:65
+msgid "Breite"
+msgstr "Width"
+
+#: blog/models.py:67
+msgid ""
+"Breite des Bildes in Prozent (100 = ganze Breite, negative Zahlen = "
+"linksbündig)"
+msgstr ""
+"Width of the picture in percent (100 = whole width, negative numbers =\n"
+"flush left)"
+
+#: blog/models.py:73
 msgid "Eintrag"
 msgstr "entry"
 
-#: blog/models.py:52
+#: blog/models.py:74
 msgid "Einträge"
 msgstr "entries"
 
-#: blog/models.py:63
+#: blog/models.py:131
 msgid "Bevorzugte Sprache des Benutzers"
 msgstr "User's Preferred Language"
 
-#: blog/models.py:65
+#: blog/models.py:133
 msgid "Neues per Mail?"
 msgstr "New Entries by Mail?"
 
-#: blog/models.py:66
+#: blog/models.py:134
 msgid "Legt fest, ob dieser Benutzer neue Beiträge per E-Mail bekommt."
 msgstr "Determines whether this user receives new entries by e-mail."
 
-#: blog/views.py:97
+#: blog/views.py:110
 msgid "Nicht jeder Eintrag ist in allen Sprachen verfügbar."
 msgstr "Not every entry is available in all languages."
 
-#: blog/views.py:99
+#: blog/views.py:112
 msgid "Maximal eine E-Mail am Tag."
 msgstr "At most one e-mail per day."
 
-#: blog/views.py:136
+#: blog/views.py:168
 msgid "Einstellungen gespeichert!"
 msgstr "Preferences saved!"
 
-#: blog/views.py:140
+#: blog/views.py:172
 msgid "Einstellungen konnten nicht gespeichert werden!"
 msgstr "Preferences could not be saved!"
 
-#: blog/views.py:312
+#: blog/views.py:446
 msgid "Betreffzeile"
 msgstr "Subject Line"
 
-#: blog/views.py:313
+#: blog/views.py:447
 msgid "Nachricht"
 msgstr "Message"
 
-#: blog/views.py:341
+#: blog/views.py:475
 msgid "Admin"
 msgstr "Admin"
 
-#: blog/views.py:344
+#: blog/views.py:478
 msgid "Eingeladen"
 msgstr "Invited"
 
-#: blog/views.py:346
+#: blog/views.py:480
 msgid "Aktiv"
 msgstr "Active"
 
-#: blog/views.py:347
+#: blog/views.py:481
 msgid "Inaktiv"
 msgstr "Inactive"
 
-#: templates/auth/admin_login.html:11 templates/blog/entry_list.html:37
+#: templates/auth/admin_login.html:11 templates/blog/entry_list.html:41
+#: templates/blog/staticpage.html:44
 msgid "Admin-Login"
 msgstr "Admin Login"
 
@@ -153,8 +170,8 @@ msgstr "Edit User"
 msgid "Neuer Benutzer"
 msgstr "New User"
 
-#: templates/auth/user_form.html:21 templates/blog/entry_form.html:21
-#: templates/blog/entry_list.html:54
+#: templates/auth/user_form.html:21 templates/blog/entry_form.html:22
+#: templates/blog/entry_list.html:58
 msgid "Speichern"
 msgstr "Save"
 
@@ -284,24 +301,25 @@ msgid "Eintrag bearbeiten"
 msgstr "Edit Entry"
 
 #: templates/blog/entry_form.html:13 templates/blog/entry_list.html:23
+#: templates/blog/staticpage.html:26
 msgid "Neuer Eintrag"
 msgstr "New Entry"
 
-#: templates/blog/entry_form.html:21 templates/blog/entry_form.html:37
+#: templates/blog/entry_form.html:22 templates/blog/entry_form.html:38
 msgid "Löschen"
 msgstr "Delete"
 
-#: templates/blog/entry_form.html:32
+#: templates/blog/entry_form.html:33
 msgid "Eintrag löschen"
 msgstr "Delete Entry"
 
-#: templates/blog/entry_form.html:34
+#: templates/blog/entry_form.html:35
 msgid ""
 "Soll dieser Eintrag wirklich gelöscht werden? Das kann nicht rückgängig "
 "gemacht werden."
 msgstr "Should this entry really be deleted? This cannot be undone."
 
-#: templates/blog/entry_form.html:37 templates/blog/entry_list.html:54
+#: templates/blog/entry_form.html:38 templates/blog/entry_list.html:58
 msgid "Schließen"
 msgstr "Close"
 
@@ -313,35 +331,53 @@ msgstr "← Newer Entries"
 msgid "Ältere Einträge →"
 msgstr "Older Entries →"
 
-#: templates/blog/entry_list.html:22
+#: templates/blog/entry_list.html:22 templates/blog/staticpage.html:25
 #, python-format
 msgid "<p>Hallo, <span>%(fn)s</span>!</p>"
 msgstr "<p>Hello, <span>%(fn)s</span>!</p>"
 
-#: templates/blog/entry_list.html:23
+#: templates/blog/entry_list.html:23 templates/blog/staticpage.html:26
 msgid "Benutzer verwalten"
 msgstr "Manage Users"
 
-#: templates/blog/entry_list.html:24 templates/blog/entry_list.html:48
+#: templates/blog/entry_list.html:24 templates/blog/search.html:11
+#: templates/blog/staticpage.html:27
+msgid "Suche"
+msgstr "Search"
+
+#: templates/blog/entry_list.html:25 templates/blog/entry_list.html:52
+#: templates/blog/staticpage.html:28
 msgid "Einstellungen"
 msgstr "Preferences"
 
-#: templates/blog/entry_list.html:26
+#: templates/blog/entry_list.html:30 templates/blog/staticpage.html:33
 msgid "Startseite"
 msgstr "Main Page"
 
-#: templates/blog/entry_list.html:31
+#: templates/blog/entry_list.html:35 templates/blog/staticpage.html:38
 msgid "Archiv"
 msgstr "Archive"
 
-#: templates/blog/item.html:28
+#: templates/blog/item.html:27 templates/blog/staticpage.html:18
 msgid "Bearbeiten"
 msgstr "Edit"
 
-#: templates/blog/item.html:34
+#: templates/blog/item.html:33 templates/blog/staticpage.html:19
 msgid "Veröffentlichen"
 msgstr "Publish"
 
+#: templates/blog/search.html:13
+msgid "Suchen"
+msgstr "Search"
+
+#: templates/blog/search.html:15
+msgid "Ergebnisse"
+msgstr "Results"
+
+#: templates/blog/toc.html:11
+msgid "Table of Contents"
+msgstr "Table of Contents"
+
 #: templates/blog/user_list.html:10
 msgid "Benutzer"
 msgstr "Users"
-- 
GitLab