-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a check-metadata command #36
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff89fd9
add a check-metadata command
aa81512
add check-metadata in doc
2e7e990
factorization of code for check-metadata command
c186f93
Improve lisibility and add a warning if JFME_CONTENT_REQUIRED_METADAT…
3ebdb19
Merge branch 'main' into feat__15_check_metadata_command
ClmntBcqt 7842c92
Standardization of MetadataStatus classmethod
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,62 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from jssg.models import Page | ||
from pathlib import Path | ||
|
||
class MetadataStatus : | ||
|
||
def get_metadata_status_for(page) : | ||
metadata_status = MetadataStatus() | ||
metadata_status.missing = [] | ||
metadata_status.empty = [] | ||
for required_metadata in settings.JFME_CONTENT_REQUIRED_METADATA : | ||
if required_metadata not in page.metadata : | ||
metadata_status.missing.append(required_metadata) | ||
elif page.metadata[required_metadata] == "" : | ||
metadata_status.empty.append(required_metadata) | ||
metadata_status.complete = (metadata_status.missing == []) and (metadata_status.empty == []) | ||
if len(settings.JFME_CONTENT_REQUIRED_METADATA) > 0 : | ||
metadata_status.progression = (len(settings.JFME_CONTENT_REQUIRED_METADATA) - len(metadata_status.missing) - len(metadata_status.empty)) * 100 / len(settings.JFME_CONTENT_REQUIRED_METADATA) | ||
else : | ||
metadata_status.progression = 100 | ||
return metadata_status | ||
|
||
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) : | ||
|
||
if settings.JFME_CONTENT_REQUIRED_METADATA == [] : | ||
self.stdout.write(self.style.WARNING( | ||
"Warning : no metadata specified in JFME_CONTENT_REQUIRED_METADATA setting." | ||
)) | ||
|
||
for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) : | ||
|
||
metadata_status = MetadataStatus.get_metadata_status_for(page) | ||
|
||
self.stdout.write("{:3.0f}% : {}".format( | ||
metadata_status.progression, | ||
page.path.relative_to(page.content_page_dir)) | ||
) | ||
|
||
if options["verbosity"] > 1 or options["verbose"] : | ||
if not metadata_status.complete : | ||
for missing in metadata_status.missing : | ||
self.stdout.write("\t- '%s' is missing" % missing) | ||
for empty in metadata_status.empty : | ||
self.stdout.write("\t- '%s' is empty" % 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard way to implement classmethod is: