A pass at making server side panels
parent
8d13aa20eb
commit
50d1f219ea
|
@ -0,0 +1,71 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>unglue.it: {% block title %}{% endblock %}</title>
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/layout.css" />
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/book-panel.css" />
|
||||
<link href="/static/css/book-panel.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="/static/js/jquery-1.6.3.min.js"></script>
|
||||
<script type="text/javascript" src="/static/js/book-panel.js"></script>
|
||||
<style type="text/css">
|
||||
.undefined {text-decoration:underline;}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!--- editions --->
|
||||
|
||||
{% if work %}
|
||||
<div class="book_panel" style="float: left;">
|
||||
<div class="book_panel_interior">
|
||||
<img src="http://covers.openlibrary.org/b/isbn/{{work.editions.all.0.isbn_10}}-M.jpg" width="120" height="182" />
|
||||
<b>{{ work.title }}</b>
|
||||
<p>{{ work.authors.all.0.name }}</p>
|
||||
<p><b>Genre:</b>{{work.subjects.all.0.name}}</p>
|
||||
<p class="status, undefined"><b>Status:</b> Unglued!</p>
|
||||
<div class="read">
|
||||
<img src="/static/images/book-panel/percent.png" />
|
||||
<p class="undefined">100%</p>
|
||||
<p class="right_add">
|
||||
<img src="/static/images/book-panel/add_gray.png" border="0" />
|
||||
</p>
|
||||
</div>
|
||||
<span style="display: none;">
|
||||
<div class="book_panel_back">
|
||||
<div class="unglued_white">
|
||||
<b class="undefined">Unglued?</b>
|
||||
<p>{{campaigns.0.deadline.date}}</p>
|
||||
<p class="undefined"><b>Raised:</b> $12,000</p>
|
||||
</div>
|
||||
<div class="read_itbutton">
|
||||
<a href="#">Read it Now</a>
|
||||
</div>
|
||||
<div id="add_towish">
|
||||
<a href="#">Add to Wishlist</a>
|
||||
</div>
|
||||
<div id="white_text">
|
||||
<b><a href="#">{{ work.title }}</a></b>
|
||||
<p><a href="#">{{ work.authors.all.0.name }}</a></p>
|
||||
<p><b>Genre:</b>{{work.subjects.all.0.name}}</p>
|
||||
<p class="undefined"><b>Status:</b> In Progress</p>
|
||||
</div>
|
||||
<div id="moreinfo">
|
||||
<a href="#">More Info</a>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="classname">No work corresponding to ISBN {{isbn}} available</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -14,5 +14,6 @@ v1_api.register(resources.SubjectResource())
|
|||
v1_api.register(resources.WishlistResource())
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^widget/(?P<isbn>\w+)/$','regluit.api.views.widget', name="widget"),
|
||||
(r'^', include(v1_api.urls)),
|
||||
)
|
||||
|
|
49
api/views.py
49
api/views.py
|
@ -1,5 +1,7 @@
|
|||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.db.models import Q
|
||||
|
||||
from regluit.core import models
|
||||
|
@ -20,3 +22,50 @@ def editions(request):
|
|||
{'editions':editions},
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
|
||||
def widget(request,isbn):
|
||||
"""
|
||||
Aim is to ultimately supply the following info:
|
||||
- campaign name
|
||||
- campaign description
|
||||
- rights holder
|
||||
- work title
|
||||
- work author
|
||||
- a link to an edition cover
|
||||
- a link to the campaign on unglue.it- the status, or progress of the ungluing
|
||||
- when the campaign is finished
|
||||
- whether the logged in user is a supporter
|
||||
- whether the logged in user is currently supporting the campaign
|
||||
Current implementation is to supply info for current book panel design
|
||||
"""
|
||||
|
||||
# presumably 0 or 1 Edition will match
|
||||
editions = models.Edition.objects.filter(Q(isbn_10 = isbn) | Q(isbn_13 = isbn))
|
||||
# if 1 edition: should be 0 or 1 corresponding Work
|
||||
# for 1 Work, there will be a Campaign or not
|
||||
assert len(editions) < 2
|
||||
|
||||
if len(editions):
|
||||
edition = editions[0]
|
||||
try:
|
||||
work = edition.work
|
||||
campaigns = work.campaigns.all()
|
||||
except Exception, e:
|
||||
work = None
|
||||
campaigns = []
|
||||
else:
|
||||
edition = None
|
||||
work = None
|
||||
campaigns = []
|
||||
|
||||
u = auth.get_user(request)
|
||||
if isinstance(u, User):
|
||||
logged_in_username = u.username
|
||||
else:
|
||||
logged_in_username = None
|
||||
|
||||
return render_to_response('widget.html',
|
||||
{'isbn':isbn,'edition':edition, 'work':work, 'campaigns':campaigns, 'logged_in_username':logged_in_username},
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
|
Loading…
Reference in New Issue