add split works funtionality
parent
3c61e292d9
commit
31a1f46666
|
@ -488,6 +488,20 @@ def merge_works(w1, w2, user=None):
|
||||||
|
|
||||||
w2.delete()
|
w2.delete()
|
||||||
|
|
||||||
|
def detach_edition(e):
|
||||||
|
"""will detach edition from its work, creating a new stub work. if remerge=true, will see if there's another work to attach to
|
||||||
|
"""
|
||||||
|
logger.info("splitting edition %s from %s", e, e.work)
|
||||||
|
w = models.Work(title=e.title, language = e.work.language)
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
for identifier in e.identifiers.all():
|
||||||
|
identifier.work = w
|
||||||
|
identifier.save()
|
||||||
|
|
||||||
|
e.work = w
|
||||||
|
e.save()
|
||||||
|
|
||||||
def despam_description(description):
|
def despam_description(description):
|
||||||
""" a lot of descriptions from openlibrary have free-book promotion text; this removes some of it."""
|
""" a lot of descriptions from openlibrary have free-book promotion text; this removes some of it."""
|
||||||
if description.find("GeneralBooksClub.com")>-1 or description.find("AkashaPublishing.Com")>-1:
|
if description.find("GeneralBooksClub.com")>-1 or description.find("AkashaPublishing.Com")>-1:
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
{% 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 %}
|
|
@ -57,6 +57,7 @@ urlpatterns = patterns(
|
||||||
url(r"^lockss/(?P<year>\d+)/$", "lockss_manifest", name="lockss_manifest"),
|
url(r"^lockss/(?P<year>\d+)/$", "lockss_manifest", name="lockss_manifest"),
|
||||||
url(r"^work/(?P<work_id>\d+)/download/$", "download", name="download"),
|
url(r"^work/(?P<work_id>\d+)/download/$", "download", name="download"),
|
||||||
url(r"^work/(?P<work_id>\d+)/merge/$", login_required(MergeView.as_view()), name="merge"),
|
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/\d+/acks/images/(?P<file_name>[\w\.]*)$", "static_redirect_view",{'dir': 'images'}),
|
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+)/librarything/$", "work_librarything", name="work_librarything"),
|
||||||
url(r"^work/(?P<work_id>\d+)/goodreads/$", "work_goodreads", name="work_goodreads"),
|
url(r"^work/(?P<work_id>\d+)/goodreads/$", "work_goodreads", name="work_goodreads"),
|
||||||
|
|
|
@ -35,6 +35,7 @@ from django.core.urlresolvers import reverse
|
||||||
from django.db.models import Q, Count, Sum
|
from django.db.models import Q, Count, Sum
|
||||||
from django.forms import Select
|
from django.forms import Select
|
||||||
from django.forms.models import modelformset_factory
|
from django.forms.models import modelformset_factory
|
||||||
|
from django.forms.models import inlineformset_factory
|
||||||
from django.http import HttpResponseRedirect, Http404
|
from django.http import HttpResponseRedirect, Http404
|
||||||
from django.http import HttpResponse, HttpResponseNotFound
|
from django.http import HttpResponse, HttpResponseNotFound
|
||||||
from django.shortcuts import render, render_to_response, get_object_or_404
|
from django.shortcuts import render, render_to_response, get_object_or_404
|
||||||
|
@ -54,7 +55,7 @@ from regluit.core import tasks
|
||||||
from regluit.core import models, bookloader, librarything
|
from regluit.core import models, bookloader, librarything
|
||||||
from regluit.core import userlists
|
from regluit.core import userlists
|
||||||
from regluit.core import goodreads
|
from regluit.core import goodreads
|
||||||
from regluit.core.bookloader import merge_works
|
from regluit.core.bookloader import merge_works, detach_edition
|
||||||
from regluit.core.goodreads import GoodreadsClient
|
from regluit.core.goodreads import GoodreadsClient
|
||||||
from regluit.core.search import gluejar_search
|
from regluit.core.search import gluejar_search
|
||||||
from regluit.core.signals import supporter_message
|
from regluit.core.signals import supporter_message
|
||||||
|
@ -725,6 +726,22 @@ class CampaignListView(FilterableListView):
|
||||||
context['facet'] =self.kwargs['facet']
|
context['facet'] =self.kwargs['facet']
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def split_work(request,work_id):
|
||||||
|
if not request.user.is_staff:
|
||||||
|
return render(request, "admins_only.html")
|
||||||
|
work = get_object_or_404(models.Work, id=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):
|
class MergeView(FormView):
|
||||||
template_name="merge.html"
|
template_name="merge.html"
|
||||||
work=None
|
work=None
|
||||||
|
|
Loading…
Reference in New Issue