-
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
Changes from 1 commit
ff89fd9
aa81512
2e7e990
c186f93
3ebdb19
7842c92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,22 @@ | |
from jssg.models import Page | ||
from pathlib import Path | ||
|
||
class MetadataStatus : | ||
|
||
def get_metadata_status_for(self, page) : | ||
self.missing = [] | ||
self.empty = [] | ||
for required_metadata in settings.JFME_CONTENT_REQUIRED_METADATA : | ||
if required_metadata not in page.metadata : | ||
self.missing.append(required_metadata) | ||
elif page.metadata[required_metadata] == "" : | ||
self.empty.append(required_metadata) | ||
self.complete = self.missing == [] and self.empty == [] | ||
if len(settings.JFME_CONTENT_REQUIRED_METADATA) > 0 : | ||
self.progression = (len(settings.JFME_CONTENT_REQUIRED_METADATA) - len(self.missing) - len(self.empty)) * 100 / len(settings.JFME_CONTENT_REQUIRED_METADATA) | ||
else : | ||
self.progression = 100 | ||
|
||
class Command(BaseCommand): | ||
help = "Check if metadata in JFME_CONTENT_REQUIRED_METADATA setting are specified in pages." | ||
|
||
|
@@ -22,20 +38,18 @@ def add_arguments(self, parser): | |
|
||
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) | ||
|
||
metadata_status = MetadataStatus() | ||
metadata_status.get_metadata_status_for(page) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the way you implement it, I suggest to rename So you use it like:
Another way would be to implement
Note: this is not required for merge but it would make the code more readable for future maintainance |
||
|
||
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), | ||
metadata_status.progression, | ||
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)) | ||
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) |
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.
I suggest addind parenthesis for readability
self.complete = (self.missing == []) and (self.empty == [])
For readability comparison:
Note that in the second line,
black
will remove parenthesis