Skip to content

Conversation

@mekarpeles
Copy link
Member

[WIP] some obvious improvements need to be made, but should be feature complete and ready for QA

Copy link
Member Author

@mekarpeles mekarpeles left a 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


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"
Copy link
Member Author

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

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"
Copy link
Member Author

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

except Exception as e:
return {'error': 'request_timeout'}

def get_available(limit=None, page=1, subject=None):
Copy link
Member Author

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)
Copy link
Member Author

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,
Copy link
Member Author

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()) {
Copy link
Member Author

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 @@

Copy link
Member Author

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 -->
Copy link
Member Author

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

$def with (page)

$if not ctx.get("sent_head"):
$if False and objhas(page, 'homepage') is True:
Copy link
Member Author

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

@@ -0,0 +1,85 @@
var carousels;
Copy link
Member Author

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

@mekarpeles
Copy link
Member Author

@bfalling ready for review.
Please note, carousels (write large) are still painting "availability" using the v1 API and so some books which are actually available (such as those in the staff picks carousel) may appear checked out. We haven't pushed the enhanced editions code yet, so the editions page will appear to corroborate this story (that the book is checked out). Visiting archive.org will show the edition's true availability.

Will submit another branch shortly w/ migration of carousel ajax checking/painting from v1 to v2 in a bit.

Copy link
Collaborator

@bfalling bfalling left a 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`.
Copy link
Collaborator

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()})
Copy link
Collaborator

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:
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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"
Copy link
Collaborator

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;"/>
Copy link
Collaborator

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

Copy link
Collaborator

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?

Copy link
Collaborator

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.

@mekarpeles
Copy link
Member Author

Fixed click tracking + memcached, got lgtm from @bfalling

@mekarpeles mekarpeles merged commit 76ce8bb into master Sep 29, 2017
@mekarpeles mekarpeles deleted the refactor/carousels branch April 22, 2019 01:49
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.

4 participants