Displaying some of the books from user shelf.

pull/1/head
Raymond Yee 2011-10-25 16:07:44 -07:00
parent 2f81b8cebd
commit a4dd33b047
4 changed files with 63 additions and 46 deletions

View File

@ -142,27 +142,38 @@ class GoodreadsClient(object):
request_url = urljoin(GoodreadsClient.url, path)
# loop through all the pages starting with page
more_pages = True
while (more_pages):
r = request(method,request_url,params=params)
if r.status_code != httplib.OK:
logger.info('headers, content: %s | %s ' % (r.headers,r.content))
#logger.info('headers, content: %s | %s ' % (r.headers,r.content))
raise GoodreadsException('Error in review_list: %s %s ' % (r.headers, r.content))
else:
logger.info('headers, content: %s | %s ' % (r.headers,r.content))
#logger.info('headers, content: %s | %s ' % (r.headers,r.content))
doc = ET.fromstring(r.content)
# for the moment convert to a iterable of book data presented as dict -- one the way to paging through all results
reviews = doc.findall('reviews/review')
for review in reviews:
yield ({'id':review.find('id').text,
'book': {'id': review.find('book/id').text,
'book': {'id': review.find('book/id').text.strip(),
'isbn13':review.find('book/isbn13').text,
'title':review.find('book/title').text,
'text_reviews_count':review.find('book/text_reviews_count').text,
'link':review.find('book/link').text,
'small_image_url':review.find('book/small_image_url').text,
'ratings_count':review.find('book/ratings_count').text,
'description':review.find('book/description').text}
'title':review.find('book/title').text.strip(),
'text_reviews_count':review.find('book/text_reviews_count').text.strip(),
'link':review.find('book/link').text.strip(),
'small_image_url':review.find('book/small_image_url').text.strip(),
'ratings_count':review.find('book/ratings_count').text.strip(),
'description':review.find('book/description').text.strip()}
})
if len(reviews) == 0:
more_pages = False
else:
params["page"] += 1
def shelves_list(self,user_id,page=1):
path = "/shelf/list.xml"

View File

@ -21,15 +21,20 @@
{% endif %}
{% if shelves_info %}
<p>You have {{shelves_info.total}} shelves. </p>
{% if shelves_info.user_shelves %}
<ul>
{% for shelf in shelves_info.user_shelves %}
<p>{{shelf.name}}: {{shelf.book_count}} book(s)</p>
<li>{{shelf.name}}: {{shelf.book_count}} book(s)</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
<!-- list user's books -->
{% if reviews %}
<p>Here are some of your books that you've put on your Goodreads shelves:</p>
<ul id="id">
{% for review in reviews %}
<li>{{review.book.title}}</li>
{% for review in reviews|slice:":50" %}
<li><img src="{{review.book.small_image_url}}"/><a href="{{review.book.link}}">{{review.book.title}}</a></li>
{% endfor %}
</ul>
{% endif %}

View File

@ -15,6 +15,7 @@ from django.contrib.auth.decorators import login_required
from django.shortcuts import render, render_to_response, get_object_or_404
import oauth2 as oauth
from itertools import islice
from regluit.core import tasks
from regluit.core import models, bookloader
@ -251,7 +252,7 @@ class GoodreadsDisplayView(TemplateView):
# if we have a userid, grab info about the book shelves and books
if session.get("goodreads_userid") is not None:
context["shelves_info"] = gr_client.shelves_list(user_id=session["goodreads_userid"])
context["reviews"] = gr_client.review_list(user_id=session["goodreads_userid"],per_page=10)
context["reviews"] = list(islice(gr_client.review_list(user_id=session["goodreads_userid"],per_page=50),50))
# also, now grab the books on the user's shelves