made logic less awful, cached work.id to speed things up as it's used many times

pull/1/head
Andromeda Yelton 2012-05-31 13:25:19 -04:00
parent cfa12dd228
commit 90ece3a2b0
1 changed files with 104 additions and 104 deletions

View File

@ -6,6 +6,7 @@
{% with work.last_campaign as last_campaign %} {% with work.last_campaign as last_campaign %}
{% with work.last_campaign.status as status %} {% with work.last_campaign.status as status %}
{% with work.last_campaign.deadline as deadline %} {% with work.last_campaign.deadline as deadline %}
{% with work.id as workid %}
<div class="thewholebook listview tabs {% if first_ebook %}tabs-1{% else %}{% if status == 'SUCCESSFUL' or status == 'ACTIVE' %}tabs-2{% else %}tabs-3{% endif %}{% endif %}"> <div class="thewholebook listview tabs {% if first_ebook %}tabs-1{% else %}{% if status == 'SUCCESSFUL' or status == 'ACTIVE' %}tabs-2{% else %}tabs-3{% endif %}{% endif %}">
<div class="listview book-list"> <div class="listview book-list">
<div class="listview panelback side2"> <div class="listview panelback side2">
@ -13,90 +14,81 @@
<div class="greenpanel_top"> <div class="greenpanel_top">
<div class="unglued_white"> <div class="unglued_white">
{% if not is_preview %}
{% comment %}top section: campaign info + optional action button. Varies by campaign status.{% endcomment %} {% comment %}top section: campaign info + optional action button. Varies by campaign status.{% endcomment %}
{% if first_ebook %} {% if status == 'SUCCESSFUL' %}
<b>AVAILABLE!</b>
</div>
<a href="{{ work.ebooks.0.url }}"><div class="read_itbutton"><span>Read it Now</span></div></a>
{% else %}{% if status == 'SUCCESSFUL' %}
<b>UNGLUED!</b> <b>UNGLUED!</b>
<p><b>On:</b> {{ deadline|date:"M d, Y" }}</p> <p><b>On:</b> {{ deadline|date:"M d, Y" }}</p>
<p><b>Raised:</b> {{ work.last_campaign.current_total|floatformat:0|intcomma }}</p> <p><b>Raised:</b> {{ work.last_campaign.current_total|floatformat:0|intcomma }}</p>
</div> {% if first_ebook %}
{% if first_ebook %}<a href="{{ work.ebooks.0.url }}"><div class="read_itbutton"><span>Read it Now</span></div></a>{% else %}<div class="read_itbutton"><span>Coming Soon</span></div>{% endif %} <a href="{{ work.ebooks.0.url }}"><div class="read_itbutton"><span>Read it Now</span></div></a>
{% else %}
<div class="read_itbutton"><span>Coming Soon</span></div>
{% endif %}
{% else %}{% if status == 'ACTIVE' %} {% else %}{% if status == 'ACTIVE' %}
<b>UNGLUE IT!</b> <b>UNGLUE IT!</b>
<p><b>${{ work.last_campaign.current_total|floatformat:0|intcomma }}</b> raised</p><p><b>${{ work.last_campaign.target|floatformat:0|intcomma }}</b> needed</p> <p><b>${{ work.last_campaign.current_total|floatformat:0|intcomma }}</b> raised</p>
<p><b>${{ work.last_campaign.target|floatformat:0|intcomma }}</b> needed</p>
<p>by {{ deadline|date:"M d, Y" }}</p> <p>by {{ deadline|date:"M d, Y" }}</p>
</div> <a href="/pledge/{{workid}}"><div class="read_itbutton pledge"><span>Support</span></div></a>
<a href="/pledge/{{work.id}}"><div class="read_itbutton pledge"><span>Support</span></div></a>
{% else %}{% if status == 'INITIALIZED' %} {% else %}{% if status == 'INITIALIZED' %}
<p>Campaign coming soon!</p> <p>Campaign coming soon!</p>
</div>
{% else %}{% if status == 'SUSPENDED' %} {% else %}{% if status == 'SUSPENDED' %}
<p>This campaign has been suspended.</p><br /><p>See the <a href="{{faqurl}}">FAQ</a> for details.</p> <p>This campaign has been suspended.</p><br /><p>See the <a href="{{faqurl}}">FAQ</a> for details.</p>
</div>
{% else %}{% if status == 'WITHDRAWN' %} {% else %}{% if status == 'WITHDRAWN' %}
<p>This campaign has been withdrawn.</p><br /><p>See the <a href="{{faqurl}}">FAQ</a> for details.</p> <p>This campaign has been withdrawn.</p><br /><p>See the <a href="{{faqurl}}">FAQ</a> for details.</p>
</div>
{% else %}{% if status == 'UNSUCCESSFUL' %} {% else %}{% if status == 'UNSUCCESSFUL' %}
<p>{{ deadline }}</p> <p>{{ deadline }}</p>
<p>Watch for a new campaign.</p> <p>Watch for a new campaign.</p>
</div>
{% else %} {% else %}
<p>No campaign yet.</p><br /><p>But if lots of ungluers wishlist this book, maybe there will be!</p> {% if first_ebook %}
</div> <b>AVAILABLE!</b>
<a href="{{ work.ebooks.0.url }}"><div class="read_itbutton"><span>Read it Now</span></div></a>
{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}
{% else %} {% else %}
<p>No campaign yet.</p><br /><p>But if lots of ungluers wishlist this book, maybe there will be!</p> <p>No campaign yet.</p><br /><p>But if lots of ungluers wishlist this book, maybe there will be!</p>
</div>
{% endif %} {% endif %}
{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}
</div>
</div> </div>
{% comment %}link to work page{% endcomment %} {% comment %}link to work page{% endcomment %}
<div class="moreinfo"> <div class="moreinfo">
<a href="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}" target="_top">More Info</a> <a href="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}" target="_top">More Info</a>
</div> </div>
{% comment %}bibliographic data{% endcomment %} {% comment %}bibliographic data{% endcomment %}
<div class="white_text"> <div class="white_text">
<p><a href="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">{{ work.title }}</a></p> <p><a href="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">{{ work.title }}</a></p>
<p>{{ author }}</p> <p>{{ author }}</p>
</div> </div>
{% comment %}status of book vis-a-vis user's wishlist{% endcomment %} {% comment %}
{% if works and activetab %} status of book vis-a-vis user's wishlist.
<div class="moreinfo add-wishlist"> Non-logged-in users should see login to add option.
{% if on_search_page %} Logged-in users, book on wishlist:
<span class="gb_id" id="p{{ googlebooks_id }}">Add&nbsp;to&nbsp;Wishlist</span> If they've pledged, that should be displayed, with no removal option.
{% else %} If they're on their supporter page, they should have the option to remove it (except when pledged).
<span class="work_id" id="p{{ work.id }}">Add&nbsp;to&nbsp;Wishlist</span> Elsewhere, they should see that it's on their wishlist.
{% endif %} Everyone else should have add-to-wishlist option.
(Needed ID for wishlist.js varies on search & supporter page.)
{% endcomment %}
{% if request.user.is_anonymous %}
<div class="moreinfo create-account">
<span title="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">Login to Add</span>
</div> </div>
{% else %} {% else %}{% if request.user.id in supporters %}
{% if request.user.id in supporters %}
<div class="moreinfo on-wishlist"> <div class="moreinfo on-wishlist">
<span>Pledged!</span> <span>Pledged!</span>
</div> </div>
{% else %} {% else %}{% ifequal supporter request.user %}
{% ifequal supporter request.user %}
<div class="moreinfo remove-wishlist"> <div class="moreinfo remove-wishlist">
<span id="p{{ work.id }}">Remove This</span> <span id="p{{ workid }}">Remove This</span>
</div>
{% else %}{% if request.user.is_anonymous %}
<div class="moreinfo create-account">
<span title="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">Login to Add</span>
</div> </div>
{% else %}{% if work in request.user.wishlist.works.all %} {% else %}{% if work in request.user.wishlist.works.all %}
<div class="moreinfo on-wishlist"> <div class="moreinfo on-wishlist">
@ -107,34 +99,35 @@
{% if on_search_page %} {% if on_search_page %}
<span class="gb_id" id="p{{ googlebooks_id }}">Add&nbsp;to&nbsp;Wishlist</span> <span class="gb_id" id="p{{ googlebooks_id }}">Add&nbsp;to&nbsp;Wishlist</span>
{% else %} {% else %}
<span class="work_id" id="p{{ work.id }}">Add&nbsp;to&nbsp;Wishlist</span> <span class="work_id" id="p{{ workid }}">Add&nbsp;to&nbsp;Wishlist</span>
{% endif %} {% endif %}
</div> </div>
{% endif %}{% endif %}{% endifequal %}{% endif %}{% endif %} {% endif %}{% endifequal %}{% endif %}{% endif %}
</div> </div>
</div> </div>
<div class="listview panelfront side1 book-thumb"> <div class="listview panelfront side1 book-thumb">
<a href="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}" target="_top"><img src="{% if thumbnail %}{{ thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="Book cover" title="book cover" /></a> <a href="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}" target="_top"><img src="{% if thumbnail %}{{ thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="Book cover" title="book cover" /></a>
</div> </div>
<div class="listview panelfront side1 book-name"> <div class="listview panelfront side1 book-name">
<div class="title"> <div class="title">
<a href="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">{{ work.title }}</a> <a href="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">{{ work.title }}</a>
</div> </div>
<div class="listview author {{ author }}">{{ author }}</div> <div class="listview author {{ author }}">{{ author }}</div>
</div> </div>
{% if request.user.id in supporters %}
{% comment %}same logic as above{% endcomment %}
{% if request.user.is_anonymous %}
<div class="listview panelfront side1 create-account">
<span title="{% if workid %}{% url work workid %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">Login to Add</span>
</div>
{% else %}{% if request.user.id in supporters %}
<div class="listview panelfront side1 on-wishlist"> <div class="listview panelfront side1 on-wishlist">
<span>Pledged!</span> <span>Pledged!</span>
</div> </div>
{% else %} {% else %}{% ifequal supporter request.user %}
{% ifequal supporter request.user %}
<div class="listview panelfront side1 remove-wishlist"> <div class="listview panelfront side1 remove-wishlist">
<span id="l{{ work.id }}">Remove This</span> <span id="l{{ workid }}">Remove This</span>
</div>
{% else %}{% if request.user.is_anonymous %}
<div class="listview panelfront side1 create-account">
<span title="{% if work.id %}{% url work work.id %}{% else %}{% url googlebooks googlebooks_id %}{% endif %}">Login to Add</span>
</div> </div>
{% else %}{% if work in request.user.wishlist.works.all %} {% else %}{% if work in request.user.wishlist.works.all %}
<div class="listview panelfront side1 on-wishlist"> <div class="listview panelfront side1 on-wishlist">
@ -145,37 +138,43 @@
{% if on_search_page %} {% if on_search_page %}
<span class="gb_id" id="l{{ googlebooks_id }}">Add to Wishlist</span> <span class="gb_id" id="l{{ googlebooks_id }}">Add to Wishlist</span>
{% else %} {% else %}
<span class="work_id" id="l{{ work.id }}">Add to Wishlist</span> <span class="work_id" id="l{{ workid }}">Add to Wishlist</span>
{% endif %} {% endif %}
</div> </div>
{% endif %}{% endif %}{% endifequal %}{% endif %} {% endif %}{% endifequal %}{% endif %}{% endif %}
<div class="listview panelfront side1 booklist-status"> <div class="listview panelfront side1 booklist-status">
{% if not is_preview %}
{% ifequal status "ACTIVE" %} {% ifequal status "ACTIVE" %}
<span class="booklist-status-text" style="width: 190px"><b>${{ work.last_campaign.current_total|floatformat:0|intcomma }}</b>/<b>${{ work.last_campaign.target|floatformat:0|intcomma }}</b></span> <span class="booklist-status-text" style="width: 190px"><b>${{ work.last_campaign.current_total|floatformat:0|intcomma }}</b>/<b>${{ work.last_campaign.target|floatformat:0|intcomma }}</b></span>
{% else %}{% if status == "INITIALIZED" %} {% else %}{% ifequal status "INITIALIZED" %}
<span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">Coming soon!</span> <span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">Coming soon!</span>
{% else %} {% else %}
<span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">{{ status }}</span> <span class="booklist-status-label"></span>
{% endif %}{% endifequal %} {% endifequal %}{% endifequal %}
{% endif %}
</div> </div>
<div class="listview panelfront side1 icons"> <div class="listview panelfront side1 icons">
{% comment %}
For status icons, we should display...
If there is an ebook: options to get it
If no ebook but there is an active or successful campaign: progress toward goal
Otherwise: number of wishes
{% endcomment %}
{% if first_ebook %} {% if first_ebook %}
<span class="listview boolist-ebook"> <span class="listview boolist-ebook">
{% for ebook in work.ebooks|slice:":3" %} {% for ebook in work.ebooks|slice:":3" %}
<a href="{{ ebook.url }}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.rights}} {{ ebook.format }} at {{ebook.provider}}" title="{{ ebook.rights}} {{ ebook.format }} at {{ebook.provider}}" /></a> <a href="{{ ebook.url }}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.rights}} {{ ebook.format }} at {{ebook.provider}}" title="{{ ebook.rights}} {{ ebook.format }} at {{ebook.provider}}" /></a>
{% endfor %} {% endfor %}
</span> </span>
{% else %}{% if last_campaign == None or status == 'No campaign yet' or status == 'INITIALIZED' %} {% else %}{% if status == 'ACTIVE' or status == 'SUCCESSFUL' %}
<a href="{% url work work.id %}?tab=3" class="nobold"><span class="rounded"><span class="grey"><span class="panelnope">Wished by&nbsp;</span>{{ work.num_wishes }}</span></span></a>
{% else %}
<div class="booklist-status-img"> <div class="booklist-status-img">
<img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" /> <img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" />
</div> </div>
{% if status == 'ACTIVE' or status == 'SUCCESSFUL' %}<div class="booklist-status-label panel">{{ work.percent_of_goal }}%</div>{% endif %} <div class="booklist-status-label panel">{{ work.percent_of_goal }}%</div>
{% else %}
<a href="{% url work workid %}?tab=3" class="nobold"><span class="rounded"><span class="grey"><span class="panelnope">Wished by&nbsp;</span>{{ work.num_wishes }}</span></span></a>
{% endif %}{% endif %} {% endif %}{% endif %}
</div> </div>
<div class="listview panelfront side1 ebooks"> <div class="listview panelfront side1 ebooks">
</div> </div>
@ -194,3 +193,4 @@
{% endwith %} {% endwith %}
{% endwith %} {% endwith %}
{% endwith %} {% endwith %}
{% endwith %}