-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Refactor/carousels #558
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
Refactor/carousels #558
Conversation
mekarpeles
left a comment
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.
self code review with changes required
openlibrary/core/lending.py
Outdated
|
|
||
| def get_available(limit=None, page=1, subject=None): | ||
| """Retrieves a list of available works for carousels from archive.org""" | ||
| url = "https://archive.org/advancedsearch.php?q=collection%3Ainlibrary" |
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.
should likely be move to a config, or at least use the archive.org variable
openlibrary/core/lending.py
Outdated
| limit = limit or MAX_IA_LIMIT | ||
| if subject: | ||
| url += "+AND+openlibrary_subject%3A" + subject | ||
| url += "+AND+loans__status__status%3AAVAILABLE&fl%5B%5D=identifier&fl%5B%5D=openlibrary_edition&fl%5B%5D=openlibrary_work&&fl%5B%5D=openlibrary_edition&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=" + str(limit) + "&page=" + str(page) + "&output=json" |
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.
consider moving params to a dict and urlencoding to make it a little more clear/readable what's going on here
openlibrary/core/lending.py
Outdated
| except Exception as e: | ||
| return {'error': 'request_timeout'} | ||
|
|
||
| def get_available(limit=None, page=1, subject=None): |
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.
Let's do better with docstrings
| } if books else {'error': 'out_of_range'} | ||
| return delegate.RawText(simplejson.dumps(result), | ||
| def GET(self): | ||
| i = web.input(limit=6, page=1) |
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.
6 should probably use a constant like ITEMS_PER_CAROUSEL_PAGE = 6
| return render_template( | ||
| page = render_template( | ||
| "home/index", stats=stats, | ||
| blog_posts=blog_posts, |
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.
unclear returncart_list is being used anywhere -- it's rendered from within the template.
| var elemTop = $(elem).offset().top; | ||
| var elemBottom = elemTop + $(elem).height(); | ||
| return ((docViewTop < elemTop) && (docViewBottom > elemBottom)); | ||
| if ($(elem).offset()) { |
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.
this shouldn't really be in this code review, it should be on the refactor/slick-carousels branch (which updated OL to be ready for slick carousels). The upgrade of jquery makes $(elem) undefined, hence this patch. We might as well add it here. Note: Other things like manage bookcovers breaks w/ latest jquery.
| @@ -0,0 +1,70 @@ | |||
|
|
|||
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.
XXX this should be in refactor/slick-carousels and removed from this branch
| @@ -0,0 +1,6 @@ | |||
| <!-- Add the slick-theme.css if you want default styling --> | |||
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.
XXX this should be removed from this branch and added to refactor/slick-carousels
openlibrary/templates/site.html
Outdated
| $def with (page) | ||
|
|
||
| $if not ctx.get("sent_head"): | ||
| $if False and objhas(page, 'homepage') is True: |
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.
These changes should have been rolled back and moved to refactor/slick-carousels
static/js/homepage.js
Outdated
| @@ -0,0 +1,85 @@ | |||
| var carousels; | |||
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.
This file should be on refactor/slick-carousels and removed from this branch
|
@bfalling ready for review. Will submit another branch shortly w/ migration of carousel ajax checking/painting from v1 to v2 in a bit. |
b73f135 to
9a95de5
Compare
bfalling
left a comment
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.
High-level review complete. Please see comments.
| def get_available(limit=None, page=1, subject=None): | ||
| """Experimental. Retrieves a list of available editions from | ||
| archive.org advancedsearch which are available, in the inlibrary | ||
| collection, and optionally apart of an `openlibrary_subject`. |
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.
"a part"?
| if item.get('openlibrary_work'): | ||
| results[item['openlibrary_work']] = item['openlibrary_edition'] | ||
|
|
||
| keys = web.ctx.site.things({"type": "/type/edition", "ocaid": results.values()}) |
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.
It's correct that the "ocaid" value is a list, right?
| d.daisy_url = book.url("/daisy") | ||
|
|
||
| if 'lendinglibrary' in collections: | ||
| if 'lendinglibrary' in collections or 'inlibrary' in collections: |
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.
lendinglibraryis deprecated. You can remove any references to it. Lendable books are only in inlibrary.
| "cover_url": "" | ||
| } | ||
| #assert book['title'] in self.render(book) | ||
| #assert self.link_count(self.render(book)) == 1 |
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.
Remove comments?
| assert len(soup.findAll("li")) == 1 | ||
| assert len(soup.findAll("a")) == 1 | ||
| #assert len(soup.findAll("li")) == 1 | ||
| #assert len(soup.findAll("a")) == 1 |
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.
Remove comments?
| <div class="coverEbook"> | ||
| <span class="actions read"> | ||
| <a href="$book.borrow_url" title="$_('Read this book')" class="borrow-link" | ||
| <a href="$(book.get('inlibrary_borrow_url') or book.get('borrow_url'))" title="$_('Borrow this book')" class="borrow-link" |
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.
book.get('inlibrary_borrow_url') or book.get('borrow_url') is also used up above. Seems brittle. What about extracting this out to a well-named helper variable, and using the variable in these locations instead?
| <div class="section"> | ||
| <form method="get" action="/search" class="siteSearch olform"> | ||
| <label for="q" class="hidden">Keywords</label> | ||
| <input type="text" name="q" id="q" value="" size="100" style="width:505px;"/> |
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.
Why the inline style?
| #del book['authors'] | ||
| #assert book['title'] in self.render(book) | ||
| #assert self.link_count(self.render(book)) == 1 | ||
|
|
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.
(Randomly placed comment) I see the tests that were removed to make this all work. But I didn't see any new tests added. Are we covered?
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 was looking for new tests too :) It would be great to have tests to describe and document the expected behaviour of new features.
01c657f to
ead1003
Compare
f9c6dfb to
8605cc4
Compare
|
Fixed click tracking + memcached, got lgtm from @bfalling |
[WIP] some obvious improvements need to be made, but should be feature complete and ready for QA