-
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
Conversation
|
||
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 = [] |
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.
For better extensibilité, the alogrithm should be exported into a reusable function.
Example:
for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) :
metadata_status = get_metadata_status_for(page)
self.stdout.write("{:3.0f}% : {}".format(
metadata_status.complete_percent,
page.path.relative_to(page.content_page_dir)
)
if not metadata_status.is_complete():
print [...]
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 added a last suggested (but not required) improvment. You decide if you merge like this or if you implement the suggestion then merge.
self.missing.append(required_metadata) | ||
elif page.metadata[required_metadata] == "" : | ||
self.empty.append(required_metadata) | ||
self.complete = self.missing == [] and self.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:
self.complete = self.missing == [] and self.empty == []
self.complete = (self.missing == [] and self.empty == [])
self.complete = (self.missing == []) and (self.empty == [])
Note that in the second line, black
will remove parenthesis
|
||
metadata_status = MetadataStatus() | ||
metadata_status.get_metadata_status_for(page) |
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.
According to the way you implement it, I suggest to rename get_metadata_status_for()
to process()
So you use it like:
metadata_status = MetadataStatus()
metadata_status.process(page)
Another way would be to implement get_metadata_status_for()
as a class method returning a MetadataStatus instance:
metadata_status = MetadataStatus.get_metadata_status_for(page)
Note: this is not required for merge but it would make the code more readable for future maintainance
…A setting is empty
|
||
class MetadataStatus : | ||
|
||
def get_metadata_status_for(page) : |
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:
@classmethod
def get_metadata_status_for(cls, page) :
[...]
PR for issue #15