cleanup of supporter view

pull/1/head
eric 2013-10-17 12:44:47 -04:00
parent b9b5f9e389
commit 6910f1aa0c
5 changed files with 28 additions and 71 deletions

View File

@ -72,8 +72,8 @@ function highlightTarget(targetdiv) {
{% block topsection %}
<div id="locationhash">{{ activetab }}</div>
{% if library %}
<div class="launch_top pale">{{ supporter.username }} is a Library participating in Unglue.it. <a href="{% url join_library supporter.username %}">Click here</a> to use {{ supporter.username }}'s books.
{% if supporter.library %}
<div class="launch_top pale">{{ supporter.library }} is a Library participating in Unglue.it. <a href="{% url join_library supporter.username %}">Click here</a> to use {{ supporter.library }}'s books.
</div>
{% endif %}
@ -195,9 +195,9 @@ function highlightTarget(targetdiv) {
</div>
<div class="check-list" id="connectgr">
{% if user.profile.goodreads_user_id %}
<a href="{{goodreads_auth_url}}">Update your GoodReads connection</a> <br /> or disconnect GoodReads: {{ profile_form.clear_goodreads }}
<a href="{% url goodreads_auth %}">Update your GoodReads connection</a> <br /> or disconnect GoodReads: {{ profile_form.clear_goodreads }}
{% else %}
<a href="{{goodreads_auth_url}}">Connect your GoodReads account</a> to Unglue.it
<a href="{% url goodreads_auth %}">Connect your GoodReads account</a> to Unglue.it
{% endif %}
</div>
<div class="check-list" id="connectlt">
@ -208,7 +208,7 @@ function highlightTarget(targetdiv) {
</form>
<div class="block block3">
<h3 class="title">Import your books</h3>
{% if goodreads_id %}
{% if request.user.profile.goodreads_user_id %}
<form id="load_shelf_form" method="post" action="#">
{% csrf_token %}
<div class="fieldWrapper">
@ -220,7 +220,7 @@ function highlightTarget(targetdiv) {
{% else %}
<div id="loadgr" onclick="highlightTarget('#connectgr'); return false;"><div>Connect your GoodReads account to import from GoodReads.</div></div>
{% endif %}
{% if librarything_id %}
{% if request.user.profile.librarything_id %}
<form id="librarything_load" method="post" action="#">
{% csrf_token %}
<div id="loadlt"><input type="submit" id="librarything_input" value="Add your LibraryThing library" /></div>

View File

@ -48,7 +48,7 @@ urlpatterns = patterns(
url(r"^next/$", "next", name="next"),
url(r"^supporter/(?P<supporter_username>[^/]+)/$", "supporter", {'template_name': 'supporter.html'}, name="supporter"),
url(r"^supporter/(?P<userlist>[^/]+)/marc/$", "marc", name="user_marc"),
url(r"^library/(?P<supporter_username>[^/]+)/$", "supporter", {'template_name': 'libraryauth/library.html'}, name="library"),
url(r"^library/(?P<library>[^/]+)/$", "library", name="library"),
url(r"^accounts/manage/$", login_required(ManageAccount.as_view()), name="manage_account"),
url(r"^search/$", "search", name="search"),
url(r"^privacy/$", TemplateView.as_view(template_name="privacy.html"),

View File

@ -1756,7 +1756,7 @@ def campaign_admin(request):
return render(request, "campaign_admin.html", context)
def supporter(request, supporter_username, template_name):
def supporter(request, supporter_username, template_name, extra_context={}):
supporter = get_object_or_404(User, username=supporter_username)
wishlist = supporter.wishlist
works = []
@ -1836,29 +1836,10 @@ def supporter(request, supporter_username, template_name):
else:
profile_form= ProfileForm(instance=profile_obj)
if request.user.profile.goodreads_user_id is not None:
goodreads_id = request.user.profile.goodreads_user_id
else:
goodreads_id = None
if request.user.profile.librarything_id is not None:
librarything_id = request.user.profile.librarything_id
else:
librarything_id = None
else:
profile_form = ''
goodreads_id = None
librarything_id = None
process_kindle_email(request)
try:
# determine if the supporter is a library
authenticator = Authenticator(request,supporter.library)
library = supporter.library
except Library.DoesNotExist:
authenticator=None
library=None
context = {
"supporter": supporter,
"wishlist": wishlist,
@ -1872,16 +1853,24 @@ def supporter(request, supporter_username, template_name):
"wished": wished,
"profile_form": profile_form,
"ungluers": userlists.other_users(supporter, 5 ),
"goodreads_auth_url": reverse('goodreads_auth'),
"goodreads_id": goodreads_id,
"librarything_id": librarything_id,
"activetab": activetab,
"library":library,
"authenticator": authenticator
}
context.update(extra_context)
return render(request, template_name, context)
def library(request,library):
context={}
try:
# determine if the supporter is a library
authenticator = Authenticator(request,library)
context['authenticator'] = authenticator
context['library'] = authenticator.library
except Library.DoesNotExist:
raise Http404
return supporter(request,library,template_name='libraryauth/library.html', extra_context=context)
def edit_user(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('superlogin'))

View File

@ -1,37 +0,0 @@
'''import logging
from django.conf import settings
from django.http import HttpResponseRedirect
from .views import superlogin
from . import backends
logger = logging.getLogger(__name__)
class Authenticator:
request=None
library=None
def __init__(self, request, library):
self.request=request
self.library=library
def process(self, success_url, deny_url):
logger.info('authenticator for %s at %s.'%(self.request.user, self.library))
if self.library.has_user(self.request.user):
return HttpResponseRedirect(success_url)
backend_test= getattr(backends, self.library.backend + '_authenticate')
if backend_test(self.request, self.library):
if self.request.user.is_authenticated():
self.library.add_user(self.request.user)
return HttpResponseRedirect(success_url)
else:
return superlogin(self.request, extra_context={'library':self.library}, template_name='libraryauth/library_login.html')
else:
backend_authenticator= getattr(backends, self.library.backend + '_authenticator')
return backend_authenticator(self.request, self.library, success_url, deny_url)
def allowed(self):
backend_test= getattr(backends, self.library.backend + '_authenticate')
return backend_test(self.request, self.library)
'''

View File

@ -36,7 +36,12 @@ class Authenticator:
def __init__(self, request, library, *args, **kwargs):
self.request = request
self.library = library
if isinstance(library , basestring):
self.library = Library.objects.get(user__username=library)
elif isinstance(library , Library):
self.library=library
else:
raise Exception
try:
form_class = getattr(backends, self.library.backend + '_form')
self.form = form_class(request, library, *args, **kwargs)