Skip to content
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

Support ordering pages and articles when iterating in templates. #1348

Merged
merged 7 commits into from
Sep 18, 2014

Conversation

vjousse
Copy link
Contributor

@vjousse vjousse commented May 14, 2014

I've merged #836 from @davidmarble with current master and added the tests from @malept fork.

By default pages are sorted by filename and articles by slug. It can be changed with ARTICLE_ORDER_BY and PAGE_ORDER_BY settings.

davidmarble and others added 4 commits November 14, 2013 12:35
Order can be set to a metadata attribute or a sorting function.
Default to order by slug for articles and order by filename for pages.
…y' into davidmarble-page-order-by

Conflicts:
	docs/settings.rst
	pelican/generators.py
	pelican/tests/test_generators.py
@justinmayer
Copy link
Member

The page ordering behaved precisely as expected in my (admittedly limited) testing. Thank you for bringing this up-to-date, Vincent!

@davidmarble
Copy link
Contributor

Very cool. Thanks for pulling this together! Sorry I couldn't find the time to help out with this.

the articles_page.object_list template variable is
ordered by slug. If you modify this, make sure all
articles contain the attribute you specify. You can
also specify a sorting function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the call signature of the sorting function should be described

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood the code below correctly, the function is supposed to be a key getter, not an actual sorting function, so calling it a sorting function is confusing.

@malept
Copy link
Contributor

malept commented May 20, 2014

If @vjousse could pull from my branch, I believe that I have addressed all of the code review comments.

@vjousse
Copy link
Contributor Author

vjousse commented May 21, 2014

Here you are!

@vjousse
Copy link
Contributor Author

vjousse commented May 27, 2014

@smartass101 @justinmayer hey guys, what do you think of the changes ? It would be great if this pull request could be merged.

elif order_by == 'basename':
index.sort(key=lambda x: os.path.basename(x.source_path or ''))
elif order_by != 'slug':
index.sort(key=attrgetter(order_by))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a try/except in case an invalid attribute is given.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avaris so something like:

try:
    index.sort(key=attrgetter(order_by))
except AttributeError:
    logger.error('There is no "{}" attribute in the metadata for "{}"'.format(order_by, slug))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malept maybe warning is more appropriate since it'll fall back to slug. Which reminds me, pages with garbage order_by falls back to slug, not basename.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@malept
Copy link
Contributor

malept commented May 27, 2014

@vjousse I updated my branch again.

@vjousse
Copy link
Contributor Author

vjousse commented May 28, 2014

@malept thanks I've updated the PR

@vjousse
Copy link
Contributor Author

vjousse commented Jun 4, 2014

@smartass101 @justinmayer @avaris is everything fine for you?

@justinmayer justinmayer added this to the 3.5 milestone Sep 16, 2014
@justinmayer
Copy link
Member

Very sorry for the long delay, Vincent. I've marked your pull request with the 3.5 milestone, so we'll be sure to review it before we issue the next release. Thanks for your patience!

@vjousse
Copy link
Contributor Author

vjousse commented Sep 17, 2014

Better late than never ;)

@justinmayer
Copy link
Member

Looks good. Thanks to everyone for their contributions and their patience. Nice to finally deliver a feature that was requested two years ago. (^_^)

justinmayer added a commit that referenced this pull request Sep 18, 2014
 Support ordering pages and articles when iterating in templates.
@justinmayer justinmayer merged commit 1d9981b into getpelican:master Sep 18, 2014
@justinmayer
Copy link
Member

@vjousse: Looks like there's a test failure after merging this pull request. Would you do us a favor and see if you could determine and submit an appropriate fix?

avaris added a commit to avaris/pelican that referenced this pull request Sep 19, 2014
justinmayer added a commit that referenced this pull request Sep 19, 2014
@vjousse
Copy link
Contributor Author

vjousse commented Sep 19, 2014

@justinmayer it seems that @avaris has already fixed the test :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants