revamp edition display and editing

1. created editions display view (work(action=editions))
2. moved split function to new editions page (staff only)
3. added edition selector (staff only)
4. moved ebook link addition to edit edition page
5. standard work display shows only 10 newest editions (much faster!)
6. campaign managers should be able to edit editions
7. ebook links can’t be added when there’s a campaign.
8. more room for edition description editing
pull/1/head
eric 2014-03-11 17:34:27 -04:00
parent ebc3a1a02a
commit cce7c43d8f
12 changed files with 301 additions and 270 deletions

View File

@ -300,7 +300,6 @@
"title": "Pro Web 2.0 Mashups",
"work": 1,
"created": "2012-10-12T23:27:53",
"public_domain": null,
"cover_image": null,
"publication_date": "2008-03-07",
"unglued": false
@ -321,7 +320,6 @@
"title": "Moby Dick",
"work": 2,
"created": "2012-10-14T09:54:17",
"public_domain": null,
"cover_image": null,
"publication_date": "1902",
"unglued": false
@ -342,7 +340,6 @@
"title": "Mass in B Minor in Full Score",
"work": 3,
"created": "2012-10-14T10:01:54",
"public_domain": null,
"cover_image": null,
"publication_date": "1989-06-01",
"unglued": false

View File

@ -1154,12 +1154,12 @@ class Work(models.Model):
self.selected_edition = self.last_campaign().edition
self.save()
return self.last_campaign().edition
if self.editions.all() == self.editions.none():
return None
else:
try:
self.selected_edition = self.editions.all()[0]
self.save()
return self.editions.all()[0]
return self.selected_edition
except IndexError:
return None
def last_campaign_status(self):
campaign = self.last_campaign()

View File

@ -127,7 +127,7 @@ class EditionForm(forms.ModelForm):
}
)
language = forms.ChoiceField(choices=LANGUAGES)
description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 2}))
description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 10}))
coverfile = forms.ImageField(required=False)
def clean(self):

View File

@ -0,0 +1,48 @@
<div class="clearfix">
<div class="editions">
{% if edition.googlebooks_id %}
<div class="image">
<img src="{{ edition.cover_image_small }}" title="edition cover" alt="edition cover" />
</div>
{% endif %}
<div class="metadata" id="edition_{{edition.id}}">
{% ifnotequal edition.title work.title %}
Title: {{edition.title}}<br />
{% endifnotequal %}
{% if edition.authors.all.0 %}
Contributors:
{% for author in edition.authors.all %}
{{author}},
{% endfor %}
<br />
{% endif %}
{% if edition.publisher %}
Publisher: <a href="{% url bypubname_list edition.publisher_name.id %}">{{edition.publisher}}</a><br />
{% endif %}
{% if edition.publication_date %}
Published: {{ edition.publication_date }}<br />
{% endif %}
{% if edition.isbn_13 %}
ISBN: <span itemprop="isbn">{{ edition.isbn_13 }}</span><br />
{% endif %}
{% if edition.oclc %}
OCLC: <a href="http://www.worldcat.org/oclc/{{ edition.oclc }}">{{ edition.oclc }}</a><br />
{% endif %}
{% if user.is_staff %}
<a href="{% url new_edition work_id edition.id %}">Edit this edition/Add ebook</a><br />
{% else %}{% if user in work.last_campaign.managers.all %}
<a href="{% url new_edition work_id edition.id %}">Edit this edition/Add ebook</a><br />
{% endif %}{% endif %}
{% if edition.googlebooks_id %}
See <a href="https://encrypted.google.com/books?id={{ edition.googlebooks_id }}">this edition on Google Books</a><br />
{% endif %}
{% for record in edition.MARCrecords.all %}
Download {{record.link_target}} MARC record for this edition: (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&amp;format=xml">XML</a>) (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&amp;format=mrc">mrc</a>)<br />
{% endfor %}
{% if user.is_staff %}{% if edition.ebooks.0 or edition.ebook_files.0 %}
<a href="{% url MARCUngluify %}?edition={{ edition.id }}">Upload</a> a MARC record for this edition. <br />
{% endif %} {% endif %}
</div>
</div>
</div>

View File

@ -0,0 +1,31 @@
<div class="clearfix">
{% if edition.ebook_form %}
{% ifnotequal status 'ACTIVE' %}
<div id="add_ebook">
{% if edition.ebooks.all.0 %}
<h2>eBooks for this Edition</h2>
{% if alert %}<div class="yikes">{{alert}}</div>{% endif %}
{% for ebook in edition.ebooks.all %}
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }}</a> {{ebook.rights}} at {{ebook.provider}}. Downloaded {{ ebook.download_count }} times.<br />
{% endfor %}
{% endif %}
<h2>Add an eBook for this Edition:</h2>
<span>If you know that this edition is available as a public domain or Creative Commons ebook, you can enter the link here and "unglue" it. Right now, we're only accepting URLs that point to Internet Archive, Wikisources, Hathitrust, Project Gutenberg, or Google Books.</span>
<form method="POST" action="#add_ebook">
{% csrf_token %}{{ edition.ebook_form.edition.errors }}{{ edition.ebook_form.edition }}{{ edition.ebook_form.user.errors }}{{ edition.ebook_form.user }}{{ edition.ebook_form.provider.errors }}{{ edition.ebook_form.provider }}
{{ edition.ebook_form.url.errors }}<span>URL: {{ edition.ebook_form.url }}</span><br />
{{ edition.ebook_form.format.errors }}<span>File Format: {{ edition.ebook_form.format }}</span>&nbsp;&nbsp;&nbsp;
{{ edition.ebook_form.rights.errors }}<span>License: {{ edition.ebook_form.rights }}</span><br />
<input type="submit" name="add_ebook" value="add ebook" />
</form>
</div>
{% else %}
<div> Uploads are disabled for this work.</div>
{% endifnotequal %}
{% endif %}
</div>

View File

@ -36,7 +36,7 @@
{% endif %}
<h2>More Edition Management</h2>
<div><a href="{% url split work.id %}">Remove editions from this work</a><br /><br /></div>
<div><a href="{% url work_editions work.id %}">Remove editions from this work</a><br /><br /></div>
<div><a href="{% url new_edition work.id '' %}">Create a new edition for this work</a><br /><br /></div>
{% endblock %}

View File

@ -9,12 +9,17 @@
{% endblock %}
{% block doccontent %}
{% if edition.pk %}
<h2>Edit Edition</h2>
{% if admin %}
{% if edition.pk %}
<h2>Edit Edition / Add Ebook Links</h2>
{% else %}
<h2>Create New Edition</h2>
{% endif %}
{% else %}
<h2>Create New Edition</h2>
<h2>Add Ebook Links</h2>
{% endif %}
{% if admin %}
<p>Title and ISBN 13 are required; the rest is optional, though a cover image link is strongly recommended.</p>
<form enctype="multipart/form-data" method="POST" action="#">
{% csrf_token %}
@ -22,7 +27,7 @@
{{ form.non_field_errors }}
<div>
<p><b>Title</b>: {{ form.title.errors }}{{ form.title }}</p>
<p><b>Publisher</b> : {{ form.publisher_name.errors }}{{ form.publisher_name }}<br />(If you change this, click another form element before submitting)</p>
<p><b>Publisher Name</b> : {{ form.publisher_name.errors }}{{ form.publisher_name }}<br />(If you change this, click another form element before submitting)</p>
<p>
<b>Authors</b>:
@ -59,11 +64,10 @@
{{ form.description.errors }}{{ form.description }}<br />
(<I>This will appear in the Description tab on the book page. If you create a campaign for this work, the campaign pitch will override this description</i>)</p>
<p><b>Publisher</b>: {{ form.publisher.errors }}{{ form.publisher }}</p>
<p><i>(Unglue.it participating publishers only.)</i><br /><b>Publisher</b>: {{ form.publisher.errors }}{{ form.publisher }}</p>
<p><b>Publication Date</b> (<I>four-digit year</I>): {{ form.publication_date.errors }}{{ form.publication_date }}</p>
<p><b>Public Domain?</b>: {{ form.public_domain.errors }}{{ form.public_domain }}</p>
{% comment %}
this has been removed since there's no point in exposing subject functionality when we're not doing anything with it -- will just confuse people.
@ -94,17 +98,25 @@
{{ form.coverfile.errors }}{{ form.coverfile }}{{ form.coverfile.help_text }}
(<i>upload a cover image file, ideally 120px wide. </i>)<br />
</p>
{% if request.user.is_staff %}
<p><b>Is this the unglued edition?</b> {{ form.unglued }}</p>
{% endif %}
</div>
<input type="submit" name="create_new_edition" value="{% if edition.pk %}Save Edits{% else %}Create Edition{% endif %}" id="submit">
</form>
{% if edition.work %}
<h2>More Edition Management</h2>
<div><a href="{% url merge edition.work.id %}">Merge other works into this one</a></div>
<div><a href="{% url split edition.work.id %}">Remove editions from this work</a><br /><br /></div>
<div><a href="{% url work_editions edition.work.id %}">Remove editions from this work</a><br /><br /></div>
{% endif %}
{% else %}
{% if edition.work %}
{% include 'edition_display.html' %}
{% else %}
Sorry, there's no work specified.
{% endif %}
{% endif %}
{% include 'edition_upload.html' %}
{% endblock %}

View File

@ -1,33 +1,14 @@
{% extends "basedocumentation.html" %}
{% block doccontent %}
<h2 class="book-name"><a href="{% url work work.id %}">{{ work.title }}</a></h2>
<h2>Split Editions</h2>
<form method="POST" action="#">
{% csrf_token %}
{{ formset.management_form }}
<dl>
{% for form in formset %}
<dt class="editionbox">
{{ form.instance.title }}, published by {{form.instance.publisher}} in {{ form.instance.publication_date }}
</dt>
<dd>with authors
{% for author in form.instance.authors.all %}
{{author}},
{% endfor %}
<br />
ISBN: {{ form.instance.isbn_13 }}
<br />
{{ form.id }}Split this Edition: {{form.DELETE.0}}
</dd>
{% endfor %}
</dl>
<input type="submit" value="Split Editions" name="submit" />
</form>
<h2>More Edition Management</h2>
<div><a href="{% url merge work.id %}">Merge other works into this one</a></div>
<div><a href="{% url new_edition work.id '' %}">Create a new edition for this work</a><br /><br /></div>
{% endblock %}
<form method="POST" action="#">
{% csrf_token %}
{{ formset.management_form }}
{% for form in formset %}
{% if request.user.is_staff %}
<div style="float:right;text-align:right">{{ form.id }}Split: {{form.DELETE.0}}<br /><br />
Select: <input type="radio" value="{{ form.instance.id }}" name="select_edition" /></div>
{% endif %}
{% with form.instance as edition %}
{% include 'edition_display.html' %}
{% endwith %}
{% endfor %}
{% if request.user.is_staff %}<input type="submit" value="Split/Select Editions" name="submit" />{% endif %}
</form>

View File

@ -242,6 +242,16 @@
</div>
</div>
{% get_comment_count for work as comment_count %}
{% ifequal action 'editions' %}
<div class="content-block-heading" id="tabs">
<ul class="tabs">
<li class="tabs1"><a href="{% url work work.id %}?tab=1">{% if status == 'ACTIVE' %}Campaign{% else %}Description{% endif %}</a></li>
<li class="tabs2"><a href="{% url work work.id %}?tab=2">Comments {% if comment_count > 0 %}({{ comment_count }}){% endif %}</a></li>
<li class="tabs3" id="supporters"><a href="{% url work work.id %}?tab=3">Ungluers {% if wishers > 0 %}<br />({{ wishers }}){% endif %}</a></li>
<li class="tabs4 active"><a href="#">Editions</a></li>
</ul>
</div>
{% else %}
<div class="content-block-heading" id="tabs">
<ul class="tabs">
<li class="tabs1 {% if activetab == '1' %}active{% endif %}"><a href="#">{% if status == 'ACTIVE' %}Campaign{% else %}Description{% endif %}</a></li>
@ -250,7 +260,7 @@
<li class="tabs4 {% if activetab == '4' %}active{% endif %}"><a href="#">More...</a></li>
</ul>
</div>
{% endifequal %}
<div id="content-block-content">
<div id="tabs-1" class="tabs {% if activetab == '1' %}active{% endif %}">
<div class="tabs-content">
@ -325,174 +335,124 @@
</div>
<div id="tabs-4" class="tabs {% if activetab == '4' %}active{% endif %}">
<div class="tabs-content">
{% if status == 'ACTIVE' %}
{% ifequal work.last_campaign.type 1 %}
<h3 class="tabcontent-title">A campaign is running to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) if ungluers can join together to raise ${{ work.last_campaign.target|floatformat:0|intcomma }} by {{ work.last_campaign.deadline }}.
You can help!</p>
{% endifequal %}
{% ifequal work.last_campaign.type 2 %}
<h3 class="tabcontent-title">A Buy-to-Unglue Campaign is running to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) on {{ work.last_campaign.cc_date }}. For every copy that ungluers purchase, that date gets sooner. ${{ work.last_campaign.left|floatformat:0|intcomma }} of sales will unglue the book <i>TODAY</i>.
You can help!</p>
{% endifequal %}
{% ifequal work.last_campaign.type 3 %}
<h3 class="tabcontent-title">A Thanks-for-Ungluing Campaign is running to reward the creators of <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has released <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) .
You can help us say "Thank You!" so that other creators will do the same.</p>
{% endifequal %}
<h4>Campaign details: the fine print</h4>
{{ work.last_campaign.details|safe }}
{% endif %}
{% ifequal action 'display' %}
{% if status == 'ACTIVE' %}
{% ifequal work.last_campaign.type 1 %}
<h3 class="tabcontent-title">A campaign is running to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) if ungluers can join together to raise ${{ work.last_campaign.target|floatformat:0|intcomma }} by {{ work.last_campaign.deadline }}.
You can help!</p>
{% endifequal %}
{% ifequal work.last_campaign.type 2 %}
<h3 class="tabcontent-title">A Buy-to-Unglue Campaign is running to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) on {{ work.last_campaign.cc_date }}. For every copy that ungluers purchase, that date gets sooner. ${{ work.last_campaign.left|floatformat:0|intcomma }} of sales will unglue the book <i>TODAY</i>.
You can help!</p>
{% endifequal %}
{% ifequal work.last_campaign.type 3 %}
<h3 class="tabcontent-title">A Thanks-for-Ungluing Campaign is running to reward the creators of <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has released <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) .
You can help us say "Thank You!" so that other creators will do the same.</p>
{% endifequal %}
<h4>Campaign details: the fine print</h4>
{{ work.last_campaign.details|safe }}
{% endif %}
{% if status == 'SUCCESSFUL' %}
<h3 class="tabcontent-title">A campaign has succeeded to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) thanks to the efforts of ungluers like you.</p>
<h4>Campaign details: the fine print</h4>
{{ work.last_campaign.details|safe }}
{% endif %}
{% if status != 'ACTIVE' and status != 'SUCCESSFUL' %}
<h4> Rights Information </h4>
{% if claimstatus == 'one_active' %}
<p>This work has been claimed by {{ rights_holder_name }}.</p>
{% else %}
{% if claimstatus == 'disputed' %}
<p>Rights claims are pending.</p>
{% if status == 'SUCCESSFUL' %}
<h3 class="tabcontent-title">A campaign has succeeded to unglue <i>{{work.title}}</i>!</h3>
<p>The rights holder, {% for claim in work.claim.all %}
{% if claim.status == 'active' %}
{{ claim.rights_holder.rights_holder_name }}
{% endif %}
{% endfor %}
, has agreed to release <i>{{work.title}}</i> to the world as a Creative Commons licensed ebook (<a href="{{ work.last_campaign.license_url }}">{{ work.last_campaign.license }}</a>) thanks to the efforts of ungluers like you.</p>
<h4>Campaign details: the fine print</h4>
{{ work.last_campaign.details|safe }}
{% endif %}
{% if status != 'ACTIVE' and status != 'SUCCESSFUL' %}
<h4> Rights Information </h4>
{% if claimstatus == 'one_active' %}
<p>This work has been claimed by {{ rights_holder_name }}.</p>
{% else %}
{% if claimstatus == 'one_pending' %}
<p>A claim for this work by {{ rights_holder_name }} is pending.</p>
{% if claimstatus == 'disputed' %}
<p>Rights claims are pending.</p>
{% else %}
{% if request.user.rights_holder.all.count %}
Is this work yours? Claim it: <br /><br />
{% if claimstatus == 'one_pending' %}
<p>A claim for this work by {{ rights_holder_name }} is pending.</p>
{% else %}
{% if request.user.rights_holder.all.count %}
Is this work yours? Claim it: <br /><br />
<form method="GET" action="{% url claim %}">
{% csrf_token %}
{{ claimform.user }}
{{ claimform.work }}
{{ claimform.rights_holder }}
<input type="submit" name="submit" value="Claim" />
</form><br />
<form method="GET" action="{% url claim %}">
{% csrf_token %}
{{ claimform.user }}
{{ claimform.work }}
{{ claimform.rights_holder }}
<input type="submit" name="submit" value="Claim" />
</form><br />
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
<p>If you'd like to contact us regarding rights for this work, please email <a href="mailto:rights@gluejar.com">rights@gluejar.com</a>.</p>
{% if work.first_ebook %}
<h4>Downloads</h4>
<div class="pledged-info">
This work has been downloaded {{ work.download_count }} times via unglue.it.
</div>
{% endif %}
{% if user.is_staff %}
<h4>Related Works</h4>
<div><a href="{% url merge work_id %}">Merge other works into this one</a></div>
<div><a href="{% url split work_id %}">Remove editions from this work</a><br /><br /></div>
{% endif %}
{% if work.subjects.all.count > 0 %}
<h4>Subjects</h4>
<ul>
{% for subject in work.subjects.all %}
<li itemprop="keywords">{{ subject.name }}</li>
{% endfor %}
</ul>
{% endif %}
<p>If you'd like to contact us regarding rights for this work, please email <a href="mailto:rights@gluejar.com">rights@gluejar.com</a>.</p>
{% if work.first_ebook %}
<h4>Downloads</h4>
<div class="pledged-info">
This work has been downloaded {{ work.download_count }} times via unglue.it.
</div>
{% endif %}
{% if user.is_staff %}
<h4>Related Works</h4>
<div><a href="{% url merge work_id %}">Merge other works into this one</a></div>
{% endif %}
{% if work.subjects.all.count > 0 %}
<h4>Subjects</h4>
<ul>
{% for subject in work.subjects.all %}
<li itemprop="keywords">{{ subject.name }}</li>
{% endfor %}
</ul>
{% endif %}
{% endifequal %}
<h4>Editions</h4>
{% if alert %}
<div class="yikes"><br />{{ alert }}</div>
{% endif %}
{% if user.is_staff %}
<div><a href="{% url new_edition work_id edition.id %}">Create a new edition for this work</a><br /><br /></div>
{% endif %}
{% if alert %}
<div class="alert"><b>Ebook Contribution:</b><br />{{ alert }}</div>
{% endif %}
{% for edition in editions %}
<div class="clearfix">
<div class="editions">
{% if edition.googlebooks_id %}
<div class="image">
<img src="{{ edition.cover_image_small }}" title="edition cover" alt="edition cover" />
</div>
{% endif %}
<div class="metadata" id="edition_{{edition.id}}">
{% if edition.publisher %}
Publisher: <a href="{% url bypubname_list edition.publisher_name.id %}">{{edition.publisher}}</a><br />
{% endif %}
{% if edition.publication_date %}
Published: {{ edition.publication_date }}<br />
{% endif %}
{% if edition.isbn_13 %}
ISBN: <span itemprop="isbn">{{ edition.isbn_13 }}</span><br />
{% endif %}
{% if edition.oclc %}
OCLC: <a href="http://www.worldcat.org/oclc/{{ edition.oclc }}">{{ edition.oclc }}</a><br />
{% endif %}
{% if user.is_staff %}
<a href="{% url new_edition work_id edition.id %}">Edit this edition</a><br />
{% endif %}
{% if edition.googlebooks_id %}
See <a href="https://encrypted.google.com/books?id={{ edition.googlebooks_id }}">this edition on Google Books</a><br />
{% endif %}
{% for record in edition.MARCrecords.all %}
Download {{record.link_target}} MARC record for this edition: (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&amp;format=xml">XML</a>) (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&amp;format=mrc">mrc</a>)<br />
{% endfor %}
{% if user.is_staff %}{% if edition.ebooks.count or edition.ebook_files.count %}
<a href="{% url MARCUngluify %}?edition={{ edition.id }}">Upload</a> a MARC record for this edition. <br />
{% endif %} {% endif %}
</div>
</div>
{% if edition.ebook_form %}
{% ifnotequal status 'ACTIVE' %}
{% if edition.hide_details %}
<div class="show_more_edition" >
more...
</div>
{% endif %}
<div {% if edition.hide_details %} class="more_edition" {% endif %}>
{% if edition.ebooks.count %}
<h5>eBooks for this Edition</h5>
{% for ebook in edition.ebooks.all %}
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }}</a> {{ebook.rights}} at {{ebook.provider}}. Downloaded {{ ebook.download_count }} times.<br />
{% endfor %}
{% endif %}
<h5>Add an eBook for this Edition:</h5>
<span>If you know that this edition is available as a public domain or Creative Commons ebook, you can enter the link here and "unglue" it. Right now, we're only accepting URLs that point to Internet Archive, Wikisources, Hathitrust, Project Gutenberg, or Google Books.</span>
<form method="POST" action="#edition_{{edition.id}}">
{% csrf_token %}{{ edition.ebook_form.edition.errors }}{{ edition.ebook_form.edition }}{{ edition.ebook_form.user.errors }}{{ edition.ebook_form.user }}{{ edition.ebook_form.provider.errors }}{{ edition.ebook_form.provider }}
{{ edition.ebook_form.url.errors }}<span>URL: {{ edition.ebook_form.url }}</span><br />
{{ edition.ebook_form.format.errors }}<span>File Format: {{ edition.ebook_form.format }}</span>&nbsp;&nbsp;&nbsp;
{{ edition.ebook_form.rights.errors }}<span>License: {{ edition.ebook_form.rights }}</span><br />
<input type="submit" name="add_ebook" value="add ebook" />
</form>
</div>
{% ifequal action 'editions' %}
{% include 'split.html' %}
{% else %}
{% with work.preferred_edition as edition %}
{% include 'edition_display.html' %}
{% endwith %}
{% if not campaign %}
{% for edition in editions %}
{% ifnotequal edition work.preferred_edition %}
{% include 'edition_display.html' %}
{% endifnotequal %}
{% endif %}
</div>
{% endfor %}
{% endfor %}
{% endif %}
<div><a href="{% url work_editions work_id %}">All editions for this work/Add downloads</a></div>
{% endifequal %}
</div>
</div>
</div>

View File

@ -95,7 +95,7 @@ urlpatterns = patterns(
url(r"^work/(?P<work_id>\d+)/borrow/$", "borrow", name="borrow"),
url(r"^work/(?P<work_id>\d+)/reserve/$", "reserve", name="reserve"),
url(r"^work/(?P<work_id>\d+)/merge/$", login_required(MergeView.as_view()), name="merge"),
url(r"^work/(?P<work_id>\d+)/split/$", "split_work", name="split"),
url(r"^work/(?P<work_id>\d+)/editions/$", "work",{'action': 'editions'}, name="work_editions"),
url(r"^work/\d+/acks/images/(?P<file_name>[\w\.]*)$", "static_redirect_view",{'dir': 'images'}),
url(r"^work/(?P<work_id>\d+)/librarything/$", "work_librarything", name="work_librarything"),
url(r"^work/(?P<work_id>\d+)/goodreads/$", "work_goodreads", name="work_goodreads"),

View File

@ -317,9 +317,29 @@ def social_auth_reset_password(request):
def work(request, work_id, action='display'):
work = safe_get_work(work_id)
alert=''
formset = None
if action == "acks":
return acks( request, work)
elif action == "editions":
EditionFormSet = inlineformset_factory(models.Work, models.Edition, fields=(), extra=0 )
if request.method == "POST" and (request.user.is_staff or user in work.last_campaign().managers.all()):
formset = EditionFormSet(data=request.POST, instance=work)
if formset.is_valid():
for form in formset.deleted_forms:
detach_edition(form.instance)
alert = 'editions have been split'
if request.POST.has_key('select_edition'):
selected_id=request.POST['select_edition']
try:
work.selected_edition= work.editions.get(id=selected_id)
work.save()
alert = alert + 'edition selected'
except models.Edition.DoesNotExist:
pass
formset = EditionFormSet(instance=work)
# process waiting add request
if not request.user.is_anonymous() and request.session.has_key("add_wishlist"):
add_url = request.session["add_wishlist"]
@ -331,6 +351,8 @@ def work(request, work_id, action='display'):
if request.method == 'POST' and not request.user.is_anonymous():
activetab = '4'
elif action == 'editions':
activetab = '4'
else:
try:
activetab = request.GET['tab']
@ -339,12 +361,8 @@ def work(request, work_id, action='display'):
except:
activetab = '1';
alert=''
campaign = work.last_campaign()
if campaign and campaign.edition and not request.user.is_staff:
editions = [campaign.edition]
else:
editions = work.editions.all().order_by('-publication_date')
editions = work.editions.all().order_by('-publication_date')[:10]
try:
pledged = campaign.transactions().filter(user=request.user, status="ACTIVE")
except:
@ -360,20 +378,6 @@ def work(request, work_id, action='display'):
if not request.user.is_anonymous():
claimform = UserClaimForm( request.user, data={'claim-work':work.pk, 'claim-user': request.user.id}, prefix = 'claim')
for edition in editions:
edition.hide_details = 1
if request.method == 'POST' and not request.user.is_anonymous():
if request.POST.has_key('ebook_%d-edition' % edition.id):
edition.ebook_form= EbookForm( data = request.POST, prefix = 'ebook_%d'%edition.id)
if edition.ebook_form.is_valid():
edition.ebook_form.save()
alert = 'Thanks for adding an ebook to unglue.it!'
else:
edition.hide_details = 0
alert = 'your submitted ebook had errors'
else:
#edition.ebook_form = EbookForm( data = {'user':request.user.id, 'edition':edition.pk })
edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
else:
claimform = None
@ -418,6 +422,7 @@ def work(request, work_id, action='display'):
'rights_holder_name': rights_holder_name,
'cover_width': cover_width_number,
'action': action,
'formset': formset,
})
def edition_uploads(request, edition_id):
@ -470,7 +475,7 @@ def edition_uploads(request, edition_id):
})
return render(request, 'edition_uploads.html', context )
@login_required
def new_edition(request, work_id, edition_id, by=None):
if not request.user.is_authenticated() :
return render(request, "admins_only.html")
@ -485,13 +490,14 @@ def new_edition(request, work_id, edition_id, by=None):
title=work.title
else:
work=None
if not request.user.is_staff :
if by == 'rh' and work is not None:
if not request.user in work.last_campaign().managers.all():
return render(request, "admins_only.html")
else:
return render(request, "admins_only.html")
alert = ''
admin = False
if request.user.is_staff :
admin = True
elif work and work.last_campaign():
if request.user in work.last_campaign().managers.all():
admin = True
if edition_id:
try:
edition = models.Edition.objects.get(id = edition_id)
@ -505,18 +511,29 @@ def new_edition(request, work_id, edition_id, by=None):
edition = models.Edition()
if work:
edition.work = work
initial={
'language':language,
'publisher_name':edition.publisher_name,
'isbn':edition.isbn_13,
'oclc':edition.oclc,
'description':description,
'title': title,
'goog': edition.googlebooks_id,
'gdrd': edition.goodreads_id,
'thng': edition.librarything_id,
}
if request.method == 'POST' :
form = None
edition.new_author_names=request.POST.getlist('new_author')
edition.new_subjects=request.POST.getlist('new_subject')
if edition.id:
if edition.id and admin:
for author in edition.authors.all():
if request.POST.has_key('delete_author_%s' % author.id):
edition.authors.remove(author)
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
break
if request.POST.has_key('add_author_submit'):
if request.POST.has_key('add_author_submit') and admin:
new_author_name = request.POST['add_author'].strip()
try:
author= models.Author.objects.get(name=new_author_name)
@ -524,7 +541,7 @@ def new_edition(request, work_id, edition_id, by=None):
author=models.Author.objects.create(name=new_author_name)
edition.new_author_names.append(new_author_name)
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
elif request.POST.has_key('add_subject_submit'):
elif request.POST.has_key('add_subject_submit') and admin:
new_subject = request.POST['add_subject'].strip()
try:
author= models.Subject.objects.get(name=new_subject)
@ -532,7 +549,17 @@ def new_edition(request, work_id, edition_id, by=None):
author=models.Subject.objects.create(name=new_subject)
edition.new_subjects.append(new_subject)
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
elif not form:
edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
elif request.POST.has_key('ebook_%d-edition' % edition.id):
edition.ebook_form= EbookForm( data = request.POST, prefix = 'ebook_%d'%edition.id)
if edition.ebook_form.is_valid():
edition.ebook_form.save()
alert = 'Thanks for adding an ebook to unglue.it!'
else:
alert = 'your submitted ebook had errors'
form = EditionForm(instance=edition, initial=initial)
elif not form and admin:
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
if form.is_valid():
form.save()
@ -585,20 +612,12 @@ def new_edition(request, work_id, edition_id, by=None):
edition.save()
return HttpResponseRedirect(work_url)
else:
form = EditionForm(instance=edition, initial={
'language':language,
'publisher_name':edition.publisher_name,
'isbn':edition.isbn_13,
'oclc':edition.oclc,
'description':description,
'title': title,
'goog': edition.googlebooks_id,
'gdrd': edition.goodreads_id,
'thng': edition.librarything_id,
})
if edition.pk:
edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
form = EditionForm(instance=edition, initial=initial)
return render(request, 'new_edition.html', {
'form': form, 'edition': edition,
'form': form, 'edition': edition, 'admin':admin, 'alert':alert
})
def campaign_results(request, campaign):
@ -924,22 +943,6 @@ class CampaignListView(FilterableListView):
context['facet'] =self.kwargs['facet']
return context
@login_required
def split_work(request,work_id):
if not request.user.is_staff:
return render(request, "admins_only.html")
work = safe_get_work(work_id)
EditionFormSet = inlineformset_factory(models.Work, models.Edition, fields=(), extra=0 )
if request.method == "POST":
formset = EditionFormSet(data=request.POST, instance=work)
if formset.is_valid():
for form in formset.deleted_forms:
detach_edition(form.instance)
formset = EditionFormSet(instance=work)
return render(request, "split.html", { "work":work, "formset": formset,})
class MergeView(FormView):
template_name="merge.html"
work=None

View File

@ -532,7 +532,6 @@ CREATE TABLE `core_edition` (
`title` varchar(1000) NOT NULL,
`publisher` varchar(255) DEFAULT NULL,
`publication_date` varchar(50) DEFAULT NULL,
`public_domain` tinyint(1) DEFAULT NULL,
`work_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `core_edition_50cafa73` (`work_id`),