First pass at integrating LT into the UI

pull/1/head
Raymond Yee 2011-11-16 10:20:10 -08:00
parent 27d162c9d7
commit 3be4e6fab4
5 changed files with 40 additions and 4 deletions

View File

@ -180,11 +180,14 @@ class LibraryThing(object):
# deal with page 1 first and then working on paging through the collection
rows = etree.xpath(rows_xpath)
i = -1 # have to account for the problem of style_parser(rows) returning nothing
for (i,row) in enumerate(style_parser(rows)):
yield row
# page size = 50, first page offset = 0, second page offset = 50 -- if total = 50 no need to go
offset += i + 1
if offset >= total:
next_page = False

View File

@ -55,3 +55,6 @@ class GoodreadsShelfLoadingForm(forms.Form):
goodreads_shelf_name_number = forms.CharField(widget=forms.Select(choices=(
('all','all'),
)))
class LibraryThingForm(forms.Form):
lt_username = forms.CharField(max_length=30, required=True)

View File

@ -5,7 +5,7 @@ from django.views.generic import ListView, DetailView
from django.contrib.auth.decorators import login_required
from regluit.core.models import Campaign
from regluit.frontend.views import CampaignFormView, GoodreadsDisplayView
from regluit.frontend.views import CampaignFormView, GoodreadsDisplayView, LibraryThingView
urlpatterns = patterns(
"regluit.frontend.views",
@ -37,6 +37,7 @@ urlpatterns = patterns(
url(r"^setup/work/(?P<work_id>\d+)/$", "work", {'action':'setup_campaign'}, name="setup_campaign"),
url(r"^pledge/(?P<work_id>\d+)/$", "pledge", name="pledge"),
url(r"^celery/clear/$","clear_celery_tasks", name="clear_celery_tasks"),
url(r"^subjects/$", "subjects", name="subjects")
url(r"^subjects/$", "subjects", name="subjects"),
url(r"^librarything/$", LibraryThingView.as_view(), name="librarything")
)

View File

@ -22,11 +22,11 @@ from itertools import islice
import re
from regluit.core import tasks
from regluit.core import models, bookloader
from regluit.core import models, bookloader, librarything
from regluit.core import userlists
from regluit.core.search import gluejar_search
from regluit.core.goodreads import GoodreadsClient
from regluit.frontend.forms import UserData, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm, RightsHolderForm, ClaimForm
from regluit.frontend.forms import UserData, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm, RightsHolderForm, ClaimForm, LibraryThingForm
from regluit.payment.manager import PaymentManager
from regluit.payment.parameters import TARGET_TYPE_CAMPAIGN
@ -443,6 +443,29 @@ def clear_wishlist(request):
return HttpResponse("Error in clearing wishlist: %s " % (e))
logger.info("Error in clearing wishlist for user %s: %s ", request.user, e)
class LibraryThingView(FormView):
template_name="librarything.html"
form_class = LibraryThingForm
def get_context_data(self, **kwargs):
context = super(LibraryThingView, self).get_context_data(**kwargs)
form = kwargs['form']
# get the books for the lt_username in the form
lt_username=self.request.GET.get("lt_username",None)
if lt_username is not None:
lt = librarything.LibraryThing(username=lt_username)
context.update({'books':list(lt.parse_user_catalog(view_style=5))})
else:
context.update({'books':None})
# pick up the LibraryThing api key
context.update({'lt_api_key':settings.LIBRARYTHING_API_KEY})
return context
def form_valid(self,form):
return super(LibraryThingView, self).form_valid(form)
@require_POST
@login_required

View File

@ -88,9 +88,15 @@ INSTALLED_APPS += ("djkombu",)
GOODREADS_API_KEY = ''
GOODREADS_API_SECRET = ''
# LibraryThing API
LIBRARYTHING_API_KEY = ''
# Freebase credentials
FREEBASE_USERNAME = ''
FREEBASE_PASSWORD = ''
# send celery log to Python logging
CELERYD_HIJACK_ROOT_LOGGER = False
#
MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES