basic stub records
parent
b4f94e60c1
commit
fbe96bcfc7
|
@ -5,8 +5,8 @@ Consider it a catalogolem: http://commons.wikimedia.org/wiki/File:Arcimboldo_Lib
|
||||||
Use the MARCXML file for the non-unglued edition from Library of Congress.
|
Use the MARCXML file for the non-unglued edition from Library of Congress.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
|
||||||
import pymarc
|
import pymarc
|
||||||
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
@ -18,6 +18,10 @@ from django.core.urlresolvers import reverse
|
||||||
import regluit.core.cc as cc
|
import regluit.core.cc as cc
|
||||||
from regluit.core import models
|
from regluit.core import models
|
||||||
|
|
||||||
|
def makestub(edition):
|
||||||
|
return makemarc(None, edition)
|
||||||
|
|
||||||
|
|
||||||
def makemarc(marcfile, edition):
|
def makemarc(marcfile, edition):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -26,28 +30,34 @@ def makemarc(marcfile, edition):
|
||||||
ebf = None
|
ebf = None
|
||||||
except IndexError:
|
except IndexError:
|
||||||
license = None
|
license = None
|
||||||
ebf = edition.ebook_files.all()[0]
|
try:
|
||||||
|
ebf = edition.ebook_files.all()[0]
|
||||||
|
except IndexError:
|
||||||
|
# no record if no ebooks
|
||||||
|
return None
|
||||||
|
|
||||||
logger.info("Making MARC records for edition %s " % edition)
|
logger.info("Making MARC records for edition %s " % edition)
|
||||||
|
|
||||||
record = pymarc.parse_xml_to_array(marcfile)[0]
|
|
||||||
|
|
||||||
# save lccn for later (if there is one) before deleting it
|
# save lccn for later (if there is one) before deleting it
|
||||||
print_lccn = None
|
print_lccn = None
|
||||||
for lccn in record.get_fields('010'):
|
if marcfile:
|
||||||
for validlccn in lccn.get_subfields('a'):
|
record = pymarc.parse_xml_to_array(marcfile)[0]
|
||||||
print_lccn = validlccn
|
for lccn in record.get_fields('010'):
|
||||||
|
for validlccn in lccn.get_subfields('a'):
|
||||||
|
print_lccn = validlccn
|
||||||
|
fields_to_delete = []
|
||||||
|
fields_to_delete += record.get_fields('001')
|
||||||
|
fields_to_delete += record.get_fields('003')
|
||||||
|
fields_to_delete += record.get_fields('005')
|
||||||
|
fields_to_delete += record.get_fields('006')
|
||||||
|
fields_to_delete += record.get_fields('007')
|
||||||
|
fields_to_delete += record.get_fields('010')
|
||||||
|
fields_to_delete += record.get_fields('040')
|
||||||
|
for field in fields_to_delete:
|
||||||
|
record.remove_field(field)
|
||||||
|
else:
|
||||||
|
record = pymarc.Record()
|
||||||
|
|
||||||
fields_to_delete = []
|
|
||||||
fields_to_delete += record.get_fields('001')
|
|
||||||
fields_to_delete += record.get_fields('003')
|
|
||||||
fields_to_delete += record.get_fields('005')
|
|
||||||
fields_to_delete += record.get_fields('006')
|
|
||||||
fields_to_delete += record.get_fields('007')
|
|
||||||
fields_to_delete += record.get_fields('010')
|
|
||||||
fields_to_delete += record.get_fields('040')
|
|
||||||
for field in fields_to_delete:
|
|
||||||
record.remove_field(field)
|
|
||||||
|
|
||||||
# create accession number and write 001 field
|
# create accession number and write 001 field
|
||||||
# (control field syntax is special)
|
# (control field syntax is special)
|
||||||
|
@ -81,12 +91,15 @@ def makemarc(marcfile, edition):
|
||||||
)
|
)
|
||||||
record.add_ordered_field(field007)
|
record.add_ordered_field(field007)
|
||||||
|
|
||||||
field008 = record.get_fields('008')[0]
|
try:
|
||||||
record.remove_field(field008)
|
field008 = record.get_fields('008')[0]
|
||||||
old_field_value = field008.value()
|
record.remove_field(field008)
|
||||||
new_field_value = old_field_value[:23] + 'o' + old_field_value[24:]
|
old_field_value = field008.value()
|
||||||
field008 = pymarc.Field(tag='008', data=new_field_value)
|
new_field_value = old_field_value[:23] + 'o' + old_field_value[24:]
|
||||||
record.add_ordered_field(field008)
|
field008 = pymarc.Field(tag='008', data=new_field_value)
|
||||||
|
record.add_ordered_field(field008)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
# add IBSN for ebook where applicable; relegate print ISBN to $z
|
# add IBSN for ebook where applicable; relegate print ISBN to $z
|
||||||
isbn = ''
|
isbn = ''
|
||||||
|
@ -125,24 +138,37 @@ def makemarc(marcfile, edition):
|
||||||
pass # if no 082 field, don't need to change indicator
|
pass # if no 082 field, don't need to change indicator
|
||||||
|
|
||||||
# add subfield to 245 indicating format
|
# add subfield to 245 indicating format
|
||||||
field245 = record.get_fields('245')[0]
|
try:
|
||||||
field245.add_subfield('h', '[electronic resource]')
|
field245 = record.get_fields('245')[0]
|
||||||
|
except IndexError:
|
||||||
|
field245 = pymarc.Field(
|
||||||
|
tag='245',
|
||||||
|
indicators = ['1', '0'],
|
||||||
|
subfields = [
|
||||||
|
'a', edition.title,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
record.add_ordered_field(field245)
|
||||||
|
field245.add_subfield('a', '[electronic resource]')
|
||||||
|
|
||||||
# modify 300 field (physical description)
|
# modify 300 field (physical description)
|
||||||
field300 = record.get_fields('300')[0]
|
try:
|
||||||
subfield_a = field300.get_subfields('a')[0]
|
field300 = record.get_fields('300')[0]
|
||||||
if (
|
subfield_a = field300.get_subfields('a')[0]
|
||||||
subfield_a[-2:] == ' ;' or
|
if (
|
||||||
subfield_a[-2:] == ' :' or
|
subfield_a[-2:] == ' ;' or
|
||||||
subfield_a[-2:] == ' +'
|
subfield_a[-2:] == ' :' or
|
||||||
):
|
subfield_a[-2:] == ' +'
|
||||||
subfield_a = subfield_a[:-2]
|
):
|
||||||
new300a = '1 online resource (' + subfield_a + ')'
|
subfield_a = subfield_a[:-2]
|
||||||
if field300.get_subfields('b'):
|
new300a = '1 online resource (' + subfield_a + ')'
|
||||||
new300a += ' :'
|
if field300.get_subfields('b'):
|
||||||
field300.delete_subfield('a')
|
new300a += ' :'
|
||||||
field300.add_subfield('a', new300a)
|
field300.delete_subfield('a')
|
||||||
field300.delete_subfield('c')
|
field300.add_subfield('a', new300a)
|
||||||
|
field300.delete_subfield('c')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if license:
|
if license:
|
||||||
# add 536 field (funding information)
|
# add 536 field (funding information)
|
||||||
|
@ -290,4 +316,5 @@ def makemarc(marcfile, edition):
|
||||||
writer = pymarc.MARCWriter(mrc_file)
|
writer = pymarc.MARCWriter(mrc_file)
|
||||||
writer.write(record)
|
writer.write(record)
|
||||||
mrc_file.close()
|
mrc_file.close()
|
||||||
|
|
||||||
|
return marc_record.pk
|
|
@ -39,10 +39,16 @@
|
||||||
{% if edition.googlebooks_id %}
|
{% if edition.googlebooks_id %}
|
||||||
See <a href="https://encrypted.google.com/books?id={{ edition.googlebooks_id }}">this edition on Google Books</a><br />
|
See <a href="https://encrypted.google.com/books?id={{ edition.googlebooks_id }}">this edition on Google Books</a><br />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if edition.MARCrecords.all %}
|
||||||
{% for record in edition.MARCrecords.all %}
|
{% for record in edition.MARCrecords.all %}
|
||||||
Download {{record.link_target}} MARC record for this edition: (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&format=xml">XML</a>) (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&format=mrc">mrc</a>)<br />
|
Download {{record.link_target}} MARC record for this edition: (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&format=xml">XML</a>) (<a href="{% url marc_concatenate %}?record_{{ record.id }}=on&format=mrc">mrc</a>)<br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% if edition.ebooks.all %}
|
||||||
|
Download {{record.link_target}} MARC record for this edition: (<a href="{% url marc_concatenate %}?edition_{{ edition.id }}=on&format=xml">XML</a>) (<a href="{% url marc_concatenate %}?edition_{{ edition.id }}=on&format=mrc">mrc</a>)<br />
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% if user.is_staff %}{% if edition.ebooks.0 or edition.ebook_files.0 %}
|
{% 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 />
|
<a href="{% url MARCUngluify %}?edition={{ edition.id }}">Upload</a> a MARC record for this edition. <br />
|
||||||
{% endif %} {% endif %}
|
{% endif %} {% endif %}
|
||||||
|
|
|
@ -47,7 +47,7 @@ urlpatterns = patterns(
|
||||||
url(r"^landing/$", "home", {'landing': True}, name="landing"),
|
url(r"^landing/$", "home", {'landing': True}, name="landing"),
|
||||||
url(r"^next/$", "next", name="next"),
|
url(r"^next/$", "next", name="next"),
|
||||||
url(r"^supporter/(?P<supporter_username>[^/]+)/$", "supporter", {'template_name': 'supporter.html'}, name="supporter"),
|
url(r"^supporter/(?P<supporter_username>[^/]+)/$", "supporter", {'template_name': 'supporter.html'}, name="supporter"),
|
||||||
url(r"^supporter/(?P<userlist>[^/]+)/marc/$", "marc", name="user_marc"),
|
url(r"^supporter/(?P<userlist>[^/]+)/marc/$", "marc_admin", name="user_marc"),
|
||||||
url(r"^library/(?P<library_name>[^/]+)/$", "library", name="library"),
|
url(r"^library/(?P<library_name>[^/]+)/$", "library", name="library"),
|
||||||
url(r"^accounts/manage/$", login_required(ManageAccount.as_view()), name="manage_account"),
|
url(r"^accounts/manage/$", login_required(ManageAccount.as_view()), name="manage_account"),
|
||||||
url(r"^search/$", "search", name="search"),
|
url(r"^search/$", "search", name="search"),
|
||||||
|
@ -150,7 +150,7 @@ urlpatterns = patterns(
|
||||||
url(r"^accounts/edit/kindle_config/$", "kindle_config", name="kindle_config"),
|
url(r"^accounts/edit/kindle_config/$", "kindle_config", name="kindle_config"),
|
||||||
url(r"^accounts/edit/kindle_config/(?P<work_id>\d+)/$", "kindle_config", name="kindle_config_download"),
|
url(r"^accounts/edit/kindle_config/(?P<work_id>\d+)/$", "kindle_config", name="kindle_config_download"),
|
||||||
url(r"^send_to_kindle/(?P<work_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"),
|
url(r"^send_to_kindle/(?P<work_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"),
|
||||||
url(r"^marc/$", "marc", name="marc"),
|
url(r"^marc/$", "marc_admin", name="marc"),
|
||||||
url(r"^marc/ungluify/$", staff_member_required(MARCUngluifyView.as_view()), name="MARCUngluify"),
|
url(r"^marc/ungluify/$", staff_member_required(MARCUngluifyView.as_view()), name="MARCUngluify"),
|
||||||
url(r"^marc/concatenate/$", "marc_concatenate", name="marc_concatenate"),
|
url(r"^marc/concatenate/$", "marc_concatenate", name="marc_concatenate"),
|
||||||
url(r"^accounts/edit/marc_config/$", login_required(MARCConfigView.as_view()), name="marc_config"),
|
url(r"^accounts/edit/marc_config/$", login_required(MARCConfigView.as_view()), name="marc_config"),
|
||||||
|
|
|
@ -72,7 +72,7 @@ from regluit.core import (
|
||||||
librarything,
|
librarything,
|
||||||
userlists,
|
userlists,
|
||||||
goodreads,
|
goodreads,
|
||||||
ungluify_record
|
marc
|
||||||
)
|
)
|
||||||
import regluit.core.cc as cc
|
import regluit.core.cc as cc
|
||||||
from regluit.core.bookloader import merge_works, detach_edition
|
from regluit.core.bookloader import merge_works, detach_edition
|
||||||
|
@ -3090,7 +3090,7 @@ def send_to_kindle(request, work_id, javascript='0'):
|
||||||
return local_response(request, javascript, context, 2)
|
return local_response(request, javascript, context, 2)
|
||||||
|
|
||||||
|
|
||||||
def marc(request, userlist=None):
|
def marc_admin(request, userlist=None):
|
||||||
link_target = 'UNGLUE'
|
link_target = 'UNGLUE'
|
||||||
libpref = {'marc_link_target': settings.MARC_CHOICES[1]}
|
libpref = {'marc_link_target': settings.MARC_CHOICES[1]}
|
||||||
try:
|
try:
|
||||||
|
@ -3133,7 +3133,7 @@ class MARCUngluifyView(FormView):
|
||||||
edition = form.cleaned_data['edition']
|
edition = form.cleaned_data['edition']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ungluify_record.makemarc(
|
marc.makemarc(
|
||||||
marcfile=self.request.FILES['file'],
|
marcfile=self.request.FILES['file'],
|
||||||
edition=edition
|
edition=edition
|
||||||
)
|
)
|
||||||
|
@ -3203,7 +3203,15 @@ def marc_concatenate(request):
|
||||||
if format == 'xml':
|
if format == 'xml':
|
||||||
outfile.write(preamble)
|
outfile.write(preamble)
|
||||||
for record in selected_records:
|
for record in selected_records:
|
||||||
record_id = long(record[7:])
|
if record.startswith('edition_'):
|
||||||
|
record_id = long(record[8:])
|
||||||
|
try:
|
||||||
|
edition = models.Edition.objects.get(pk=record_id)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
record_id = marc.makestub(edition)
|
||||||
|
else:
|
||||||
|
record_id = long(record[7:])
|
||||||
if format == 'xml':
|
if format == 'xml':
|
||||||
record_url = models.MARCRecord.objects.get(
|
record_url = models.MARCRecord.objects.get(
|
||||||
pk=record_id
|
pk=record_id
|
||||||
|
|
|
@ -48,7 +48,7 @@ paramiko==1.7.7.2
|
||||||
postmonkey==1.0a4
|
postmonkey==1.0a4
|
||||||
pyasn1==0.1.4
|
pyasn1==0.1.4
|
||||||
pycrypto==2.6
|
pycrypto==2.6
|
||||||
pymarc==2.8.8
|
pymarc==3.0.2
|
||||||
python-dateutil==2.1
|
python-dateutil==2.1
|
||||||
python-openid==2.2.5
|
python-openid==2.2.5
|
||||||
pytz==2012d
|
pytz==2012d
|
||||||
|
@ -57,7 +57,7 @@ redis==2.6.2
|
||||||
reportlab==3.1.8
|
reportlab==3.1.8
|
||||||
requests==0.14.0
|
requests==0.14.0
|
||||||
selenium==2.43.0
|
selenium==2.43.0
|
||||||
six==1.7.3
|
six==1.8.0
|
||||||
ssh==1.7.14
|
ssh==1.7.14
|
||||||
stevedore==0.4
|
stevedore==0.4
|
||||||
stripe==1.9.1
|
stripe==1.9.1
|
||||||
|
|
|
@ -384,7 +384,7 @@ CONTENT_TYPES = {
|
||||||
'mobi': 'application/x-mobipocket-ebook'
|
'mobi': 'application/x-mobipocket-ebook'
|
||||||
}
|
}
|
||||||
|
|
||||||
# if you add more of these, make sure core/ungluify_record.py can deal
|
# if you add more of these, make sure core/marc.py can deal
|
||||||
MARC_CHOICES = (
|
MARC_CHOICES = (
|
||||||
('DIRECT', 'Raw link'),
|
('DIRECT', 'Raw link'),
|
||||||
('UNGLUE', 'Unglue.it link'),
|
('UNGLUE', 'Unglue.it link'),
|
||||||
|
|
Loading…
Reference in New Issue