-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clément
committed
Jul 15, 2024
1 parent
1b67b84
commit ff89fd9
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
title Page1 | ||
slug page1 | ||
template_engine jinja2 | ||
description | ||
--- | ||
{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from jssg.models import Page | ||
from pathlib import Path | ||
|
||
class Command(BaseCommand): | ||
help = "Check if metadata in JFME_CONTENT_REQUIRED_METADATA setting are specified in pages." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--verbose", | ||
action = "store_true", | ||
help="Show missing or empty metadata in each page." | ||
) | ||
parser.add_argument( | ||
"content path", | ||
nargs = "*", | ||
type=str, | ||
default=settings.JFME_PAGES_DIRS, | ||
help="The paths where search the pages. Set to JFME_PAGES_DIRS by default." | ||
) | ||
|
||
def handle(self, *args, **options) : | ||
for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) : | ||
missing_metadata = [] | ||
empty_metadata = [] | ||
for required_metadata in settings.JFME_CONTENT_REQUIRED_METADATA : | ||
if required_metadata not in page.metadata : | ||
missing_metadata.append(required_metadata) | ||
elif page.metadata[required_metadata] == "" : | ||
empty_metadata.append(required_metadata) | ||
|
||
self.stdout.write("{:3.0f}% : {}".format( | ||
(len(settings.JFME_CONTENT_REQUIRED_METADATA) - len(missing_metadata) - len(empty_metadata)) * 100 / len(settings.JFME_CONTENT_REQUIRED_METADATA), | ||
page.path.relative_to(page.content_page_dir)) | ||
) | ||
if options["verbosity"]>1 or options["verbose"] : | ||
for missing in missing_metadata : | ||
self.stdout.write("\t- '{}' is missing".format(missing)) | ||
for empty in empty_metadata : | ||
self.stdout.write("\t- '{}' is empty".format(empty)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters