Displaying some of the books from user shelf.
parent
2f81b8cebd
commit
a4dd33b047
|
@ -142,27 +142,38 @@ class GoodreadsClient(object):
|
|||
|
||||
request_url = urljoin(GoodreadsClient.url, path)
|
||||
|
||||
r = request(method,request_url,params=params)
|
||||
# loop through all the pages starting with page
|
||||
|
||||
if r.status_code != httplib.OK:
|
||||
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))
|
||||
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,
|
||||
'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}
|
||||
})
|
||||
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))
|
||||
raise GoodreadsException('Error in review_list: %s %s ' % (r.headers, r.content))
|
||||
else:
|
||||
#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.strip(),
|
||||
'isbn13':review.find('book/isbn13').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"
|
||||
|
|
|
@ -105,28 +105,28 @@ class Work(models.Model):
|
|||
return self.editions.all()[0].cover_image_small()
|
||||
|
||||
def last_campaign_status(self):
|
||||
try:
|
||||
last = self.campaigns.order_by('-created')[0].status
|
||||
except:
|
||||
last = "No campaign yet"
|
||||
return last
|
||||
try:
|
||||
last = self.campaigns.order_by('-created')[0].status
|
||||
except:
|
||||
last = "No campaign yet"
|
||||
return last
|
||||
|
||||
def percent_unglued(self):
|
||||
if(self.last_campaign_status() == 'SUCCESSFUL'):
|
||||
return 6;
|
||||
elif(self.last_campaign_status() == 'ACTIVE'):
|
||||
target = float(self.campaigns.order_by('-created')[0].target)
|
||||
if target <= 0:
|
||||
return 6
|
||||
else:
|
||||
total = float(self.campaigns.order_by('-created')[0].current_total)
|
||||
percent = int(total*6/target)
|
||||
if percent >= 6:
|
||||
return 6
|
||||
else:
|
||||
return percent;
|
||||
else:
|
||||
return 0;
|
||||
if(self.last_campaign_status() == 'SUCCESSFUL'):
|
||||
return 6;
|
||||
elif(self.last_campaign_status() == 'ACTIVE'):
|
||||
target = float(self.campaigns.order_by('-created')[0].target)
|
||||
if target <= 0:
|
||||
return 6
|
||||
else:
|
||||
total = float(self.campaigns.order_by('-created')[0].current_total)
|
||||
percent = int(total*6/target)
|
||||
if percent >= 6:
|
||||
return 6
|
||||
else:
|
||||
return percent;
|
||||
else:
|
||||
return 0;
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
|
|
@ -21,15 +21,20 @@
|
|||
{% endif %}
|
||||
{% if shelves_info %}
|
||||
<p>You have {{shelves_info.total}} shelves. </p>
|
||||
{% for shelf in shelves_info.user_shelves %}
|
||||
<p>{{shelf.name}}: {{shelf.book_count}} book(s)</p>
|
||||
{% endfor %}
|
||||
{% if shelves_info.user_shelves %}
|
||||
<ul>
|
||||
{% for shelf in shelves_info.user_shelves %}
|
||||
<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 %}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue