18
18
from django .db import models , transaction
19
19
from django .db .models import Q
20
20
from django .db .models .fields .json import KeyTextTransform
21
+ from django .test import RequestFactory
22
+ from django .urls import resolve , reverse as reverse_path
21
23
from django .utils .functional import cached_property
22
24
from django .utils .html import strip_tags
23
25
from django_hosts .resolvers import reverse
@@ -218,6 +220,9 @@ def sync_to_db(self, decoded_documents):
218
220
)
219
221
document .save (update_fields = ("metadata" ,))
220
222
223
+ self ._sync_blog_to_db ()
224
+ self ._sync_views_to_db ()
225
+
221
226
def _sync_blog_to_db (self ):
222
227
"""
223
228
Sync the blog entries into search based on the release documents
@@ -244,6 +249,47 @@ def _sync_blog_to_db(self):
244
249
),
245
250
)
246
251
252
+ def _sync_views_to_db (self ):
253
+ """
254
+ Sync the blog entries into search based on the release documents
255
+ support end date.
256
+ """
257
+ if self .lang == "en" :
258
+ # The request needs to come through as a valid one, it's best if it
259
+ # matches the exact host we're looking for.
260
+ www_hosts = [
261
+ host for host in settings .ALLOWED_HOSTS if host .startswith ("www." )
262
+ ]
263
+ if not www_hosts or not (www_host := www_hosts [0 ]):
264
+ return
265
+ synced_views = [
266
+ # Page title, url name, url kwargs
267
+ ("Django's Ecosystem" , "community-ecosystem" , {}),
268
+ ]
269
+ for title , url_name , kwargs in synced_views :
270
+ absolute_url = reverse (url_name , kwargs = kwargs , host = "www" )
271
+ path = reverse_path (url_name , kwargs = kwargs )
272
+ request = RequestFactory ().get (path , HTTP_HOST = www_host )
273
+ body = resolve (path ).func (request ).render ().text
274
+ Document .objects .create (
275
+ release = self ,
276
+ path = absolute_url ,
277
+ title = title ,
278
+ metadata = {
279
+ "body" : body ,
280
+ "breadcrumbs" : [
281
+ {"path" : "weblog" , "title" : "Website" },
282
+ ],
283
+ "parents" : "weblog" ,
284
+ "slug" : url_name ,
285
+ "title" : title ,
286
+ "toc" : "" ,
287
+ },
288
+ config = TSEARCH_CONFIG_LANGUAGES .get (
289
+ self .lang [:2 ], DEFAULT_TEXT_SEARCH_CONFIG
290
+ ),
291
+ )
292
+
247
293
248
294
def _clean_document_path (path ):
249
295
# We have to be a bit careful to reverse-engineer the correct
0 commit comments