Skip to content

Commit 26b631b

Browse files
committed
Replace magic string weblog with constant.
1 parent 4fd3262 commit 26b631b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

docs/models.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
START_SEL,
3535
STOP_SEL,
3636
TSEARCH_CONFIG_LANGUAGES,
37+
DocumentationCategory,
3738
)
3839

3940

@@ -237,9 +238,12 @@ def _sync_blog_to_db(self):
237238
metadata={
238239
"body": entry.body_html,
239240
"breadcrumbs": [
240-
{"path": "weblog", "title": "News"},
241+
{
242+
"path": DocumentationCategory.WEBSITE.value,
243+
"title": "News",
244+
},
241245
],
242-
"parents": "weblog",
246+
"parents": DocumentationCategory.WEBSITE.value,
243247
"slug": entry.slug,
244248
"title": entry.headline,
245249
"toc": "",
@@ -279,9 +283,12 @@ def _sync_views_to_db(self):
279283
metadata={
280284
"body": body,
281285
"breadcrumbs": [
282-
{"path": "weblog", "title": "Website"},
286+
{
287+
"path": DocumentationCategory.WEBSITE.value,
288+
"title": "Website",
289+
},
283290
],
284-
"parents": "weblog",
291+
"parents": DocumentationCategory.WEBSITE.value,
285292
"slug": url_name,
286293
"title": title,
287294
"toc": "",
@@ -303,7 +310,7 @@ def _clean_document_path(path):
303310

304311

305312
def document_url(doc):
306-
if doc.metadata["parents"] == "weblog":
313+
if doc.metadata["parents"] == DocumentationCategory.WEBSITE.value:
307314
return doc.path
308315
elif doc.path:
309316
kwargs = {

docs/tests/test_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from releases.models import Release
1212

1313
from ..models import DOCUMENT_SEARCH_VECTOR, Document, DocumentRelease
14+
from ..search import DocumentationCategory
1415

1516

1617
class ModelsTests(TestCase):
@@ -480,7 +481,9 @@ def setUpTestData(cls):
480481
slug="a",
481482
body_html="<h1>Searchable Blog Post</h1>",
482483
)
483-
cls.docs_documents = cls.release.documents.exclude(metadata__parents="weblog")
484+
cls.docs_documents = cls.release.documents.exclude(
485+
metadata__parents=DocumentationCategory.WEBSITE.value
486+
)
484487

485488
def test_sync_to_db(self):
486489
self.release.sync_to_db(

0 commit comments

Comments
 (0)