I can harvest files from the db instead of tempting error by entering them twice

pull/1/head
Andromeda Yelton 2013-07-18 16:36:01 -04:00
parent c3349ef5eb
commit 516c8c768a
5 changed files with 40 additions and 35 deletions

View File

@ -16,7 +16,7 @@ from django.core.files.storage import default_storage
from regluit.core import models
def makemarc(marcfile, isbn, license, ebooks, edition):
def makemarc(marcfile, isbn, license, edition):
"""
if we're going to suck down LOC records directly:
parse_xml_to_array takes a file, so we need to faff about with file writes
@ -159,17 +159,19 @@ def makemarc(marcfile, isbn, license, ebooks, edition):
content_types = settings.CONTENT_TYPES
for format_tuple in settings.FORMATS:
format = format_tuple[0]
if ebooks[format]:
field856 = pymarc.Field(
tag='856',
indicators = ['4', '0'],
subfields = [
'3', format + ' version',
'q', content_types[format],
'u', ebooks[format],
]
)
record.add_ordered_field(field856)
ebooks = edition.ebooks.filter(format=format)
if ebooks:
for book in ebooks:
field856 = pymarc.Field(
tag='856',
indicators = ['4', '0'],
subfields = [
'3', format + ' version',
'q', content_types[format],
'u', format,
]
)
record.add_ordered_field(field856)
# strip any 9XX fields (they're for local use)
for i in range(900, 1000):

View File

@ -579,20 +579,14 @@ class MARCUngluifyForm(forms.Form):
file = forms.FileField(label='Download a MARCXML file from Library of Congress; then upload it here.')
license = forms.ChoiceField(choices=settings.CCCHOICES)
def __init__(self, *args, **kwargs):
super(MARCUngluifyForm, self).__init__(*args, **kwargs)
for format_tuple in settings.FORMATS:
key = format_tuple[0]
self.fields[key] = forms.URLField(required=False, label='Link to ' + key + ' file')
# insist that at least 1 ebook link is nonempty
# insist that there is at least one ebook to link to
def clean(self):
if not (
self.cleaned_data['pdf'] or
self.cleaned_data['epub'] or
self.cleaned_data['html'] or
self.cleaned_data['text'] or
self.cleaned_data['mobi']
):
raise forms.ValidationError('You must enter a URL for at least one filetype.')
ebooks = False
for format_tuple in settings.FORMATS:
format = format_tuple[0]
if self.cleaned_data['edition'].ebooks.filter(format=format):
ebooks = True
break
if not ebooks:
raise forms.ValidationError('Please add at least one unglued ebook link to THIS EDITION through the work or admin page before creating a MARC record.')
return self.cleaned_data

View File

@ -27,6 +27,10 @@
<p>Go ahead: add unglued ebooks to your library catalog!</p>
{% if request.user.is_staff %}
<p>Hi, {{ request.user.username }}. Unglue.it staffers can also <a href="{% url MARCUngluify %}">add new records</a>.</p>
{% endif %}
<div class="marc">
{% for record in records %}
<div>
@ -34,6 +38,7 @@
<a class="fakeinput" href="{{ record.mrc_record }}">Download .mrc</a>
<a href="{% url work record.edition.work.id %}" class="title clearfix">{{ record.edition.work.title }}</a>
</div>
<br />
{% endfor %}
</div>
{% endblock %}

View File

@ -12,9 +12,6 @@
{% block doccontent %}
<h2>Make your unglued MARC records here</h2>
<p>
For unglued ebooks which have existing print editions cataloged in the Library of Congress, we can automatically convert those to unglued ebook MARC records, which will then be automatically affixed to the ebook edition in our database and <a href="{% url marc %}">provided to ungluers</a>.
</p>
{% if messages %}
<ul class="messages">
{% for message in messages %}
@ -22,6 +19,18 @@
{% endfor %}
</ul>
{% endif %}
<p>
For unglued ebooks which have existing print editions cataloged in the Library of Congress, we can automatically convert those to unglued ebook MARC records, which will then be automatically affixed to the ebook edition in our database and <a href="{% url marc %}">provided to ungluers</a>.
</p>
<p>
<b>This does not perform validation</b> of either XML or ISBNs. Ensure that you have a MARCXML file from Library of Congress and that you have the proper ISBN (or leave that field blank). This is a staff-only function.
</p>
<p>
The robot cataloger will automatically add links to all the unglued ebook files known to the Unglue.it database. <I>Make sure you have added those links to the database before creating the record.</i>
</p>
<form action="" enctype="multipart/form-data" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add record" />

View File

@ -2624,16 +2624,11 @@ class MARCUngluifyView(FormView):
isbn = form.cleaned_data['isbn']
license = form.cleaned_data['license']
edition = form.cleaned_data['edition']
ebooks = {}
for format in settings.FORMATS:
key = format[0]
ebooks[key] = form.cleaned_data[key]
ungluify_record.makemarc(
marcfile=self.request.FILES['file'],
isbn=isbn,
license=license,
ebooks=ebooks,
edition=edition
)
messages.success(