parametrizing formats and license choices, bugfixing

pull/1/head
Andromeda Yelton 2013-07-17 13:03:35 -04:00
parent 87c27cecee
commit 54e422e217
8 changed files with 104 additions and 70 deletions

View File

@ -110,7 +110,7 @@ class Claim(models.Model):
rights_holder = models.ForeignKey("RightsHolder", related_name="claim", null=False )
work = models.ForeignKey("Work", related_name="claim", null=False )
user = models.ForeignKey(User, related_name="claim", null=False )
status = models.CharField(max_length=7, choices= STATUSES, default='pending')
status = models.CharField(max_length=7, choices=STATUSES, default='pending')
@property
def can_open_new(self):
@ -175,16 +175,8 @@ class CampaignAction(models.Model):
campaign = models.ForeignKey("Campaign", related_name="actions", null=False)
class CCLicense():
CCCHOICES = (
('CC BY-NC-ND','CC BY-NC-ND'),
('CC BY-ND','CC BY-ND'),
('CC BY','CC BY'),
('CC BY-NC','CC BY-NC'),
( 'CC BY-NC-SA','CC BY-NC-SA'),
( 'CC BY-SA','CC BY-SA'),
( 'CC0','CC0'),
)
CHOICES = CCCHOICES+(('PD-US', 'Public Domain, US'),)
CCCHOICES = settings.CCCHOICES
CHOICES = CCCHOICES + (('PD-US', 'Public Domain, US'),)
@staticmethod
def url(license):
@ -230,7 +222,7 @@ class CCLicense():
class Campaign(models.Model):
LICENSE_CHOICES = CCLicense.CCCHOICES
LICENSE_CHOICES = settings.CCCHOICES
created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=500, null=True, blank=False)
description = RichTextField(null=True, blank=False)
@ -1036,8 +1028,8 @@ class WasWork(models.Model):
class Ebook(models.Model):
FORMAT_CHOICES = (('pdf','PDF'),( 'epub','EPUB'), ('html','HTML'), ('text','TEXT'), ('mobi','MOBI'))
RIGHTS_CHOICES = CCLicense.CHOICES
FORMAT_CHOICES = settings.FORMATS
RIGHTS_CHOICES = settings.CCCHOICES
url = models.URLField(max_length=1024)
created = models.DateTimeField(auto_now_add=True)
format = models.CharField(max_length=25, choices = FORMAT_CHOICES)

View File

@ -1,6 +1,7 @@
"""
This takes a MARCXML filename as an argument and converts it into
MARC records for the unglued edition (in .xml and .mrc formats).
Consider it a catalogolem: http://commons.wikimedia.org/wiki/File:Arcimboldo_Librarian_Stokholm.jpg
Use the MARCXML file for the non-unglued edition from Library of Congress.
"""
@ -10,13 +11,14 @@ import pymarc
from datetime import datetime
from StringIO import StringIO
from django.conf import settings
from django.core.files.storage import default_storage
from regluit.core import models
def makemarc(marcfile, isbn, license, ebooks):
"""
if we're going to suck down LOC records:
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
would be nice to have a suitable z39.50
can use LCCN to grab record with urllib, but file writes are inconsistent
@ -30,6 +32,7 @@ def makemarc(marcfile, isbn, license, ebooks):
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)
@ -74,6 +77,28 @@ def makemarc(marcfile, isbn, license, ebooks):
field008 = pymarc.Field(tag='008', data=new_field_value)
record.add_ordered_field(field008)
# add IBSN for ebook where applicable; relegate print ISBN to $z
field020 = record.get_fields('020')[0]
print_isbn = field020.get_subfields('a')[0]
field020.delete_subfield('a')
if isbn:
field020.add_subfield('a', isbn)
field020.add_subfield('z', print_isbn)
# change 050 and 082 indicators because LOC is no longer responsible for these
# no easy indicator change function, so we'll just reconstruct the fields
field050 = record.get_fields('050')[0]
field050_new = field050
field050_new.indicators = [' ', '4']
record.remove_field(field050)
record.add_ordered_field(field050_new)
field082 = record.get_fields('050')[0]
field082_new = field050
field082_new.indicators = [' ', '4']
record.remove_field(field082)
record.add_ordered_field(field082_new)
# add subfield to 245 indicating format
field245 = record.get_fields('245')[0]
field245.add_subfield('h', '[electronic resource]')
@ -87,7 +112,7 @@ def makemarc(marcfile, isbn, license, ebooks):
subfield_a[-2:] == ' +'
):
subfield_a = subfield_a[:-2]
new300a = 'online resource (' + subfield_a + ')'
new300a = '1 online resource (' + subfield_a + ')'
if field300.get_subfields('b'):
new300a += ' :'
field300.delete_subfield('a')
@ -105,28 +130,15 @@ def makemarc(marcfile, isbn, license, ebooks):
record.add_ordered_field(field536)
# add 540 field (terms governing use)
license_terms = {
'BY': 'Creative Commons Attribution 3.0 Unported (CC BY 3.0)',
'BY-SA': 'Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY 3.0)',
'BY-NC': 'Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY 3.0)',
'BY-NC-SA': 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY 3.0)',
'BY-NC-ND': 'Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY 3.0)',
'BY-ND': 'Creative Commons Attribution-NoDerivs 3.0 Unported (CC BY 3.0)',
}
license_grants = {
'BY': 'http://creativecommons.org/licenses/by/3.0/',
'BY-SA': 'http://creativecommons.org/licenses/by-sa/3.0/',
'BY-NC': 'http://creativecommons.org/licenses/by-nc/3.0/',
'BY-NC-SA': 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
'BY-NC-ND': 'http://creativecommons.org/licenses/by-nc-nd/3.0/',
'BY-ND': 'http://creativecommons.org/licenses/by-nd/3.0/'
}
license_terms = settings.CCCHOICES
license_grants = settings.CCGRANTS
field540 = pymarc.Field(
tag='540',
indicators = [' ', ' '],
subfields = [
'a', license_terms[license],
'u', license_grants[license],
'a', dict(license_terms)[license],
'u', dict(license_grants)[license],
]
)
record.add_ordered_field(field540)
@ -142,21 +154,16 @@ def makemarc(marcfile, isbn, license, ebooks):
record.add_ordered_field(field588)
# add 856 fields with links for each available file
content_types = {
'PDF': 'application/pdf',
'EPUB': 'application/epub+zip',
'HTML': 'text/html',
'TEXT': 'text/plain',
'MOBI': 'application/x-mobipocket-ebook'
}
for format in ebooks:
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.upper()],
'q', content_types[format],
'u', ebooks[format],
]
)

View File

@ -568,15 +568,6 @@ class KindleEmailForm(forms.Form):
kindle_email = forms.EmailField()
class MARCUngluifyForm(forms.Form):
LICENSE_CHOICES = (
('BY', 'Creative Commons Attribution 3.0 Unported (CC BY 3.0)'),
('BY-SA', 'Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY 3.0)'),
('BY-NC', 'Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY 3.0)'),
('BY-NC-SA', 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY 3.0)'),
('BY-NC-ND', 'Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY 3.0)'),
('BY-ND', 'Creative Commons Attribution-NoDerivs 3.0 Unported (CC BY 3.0)'),
)
edition = AutoCompleteSelectField(
EditionLookup,
label='Edition',
@ -584,16 +575,17 @@ class MARCUngluifyForm(forms.Form):
required=True,
error_messages={'required': 'Please specify an edition.'},
)
isbn = forms.CharField()
file = forms.FileField()
license = forms.ChoiceField(choices=LICENSE_CHOICES)
pdf = forms.URLField(required=False)
epub = forms.URLField(required=False)
html = forms.URLField(required=False)
text = forms.URLField(required=False)
mobi = forms.URLField(required=False)
# but custom validation should insist at least 1 nonempty
isbn = forms.CharField(label='ISBN of unglued edition (leave blank if no ISBN)', required=False)
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
def clean(self):
if not (
self.cleaned_data['pdf'] or

View File

@ -32,7 +32,7 @@
<dt>Stay in touch.</dt>
<dd>You can follow us on Twitter (<a href="http://twitter.com/unglueit">@unglueit</a>), <a href="http://facebook/com/unglueit">Facebook</a>, and our <a href="http://blog.unglue.it">blog</a>, and <a href="http://eepurl.com/fKLfI">subscribe to our newsletter</a> (1-2 emails per month).</dd>
<dt>Add unglued ebooks to your collection.</dt>
<dd>We strive to have OCLC and SkyRiver MARC records available for all unglued ebooks. They can live in the catalog in your ILS; they link to an epub file in the Internet Archive. Of course, because of unglued ebooks' Creative Commons licenses, you're free to shift that epub to other formats, host the file on your own servers, and edit the MARC record accordingly.</dd>
<dd>We provide <a href="{% url marc %}">MARC records for unglued ebooks</a> wherever we can. We also strive to have MARC records available in OCLC and SkyRiver for all unglued ebooks. They can live in the catalog in your ILS; they link to an epub file in the Internet Archive. Of course, because of unglued ebooks' Creative Commons licenses, you're free to shift that epub to other formats, host the file on your own servers, and edit the MARC record accordingly.</dd>
<dt>Join our <a href="http://goo.gl/lCTLI">catalogers list</a>.</dt>
<dd>We're able to get MARC records into OCLC and SkyRiver because of the support of catalogers like you. Want to help? <a href="http://goo.gl/lCTLI">Add yourself to the list.</a> Usually all you'll need to do is modify an existing record for an earlier edition and upload the record. We'll supply you with the link and the unglued edition. We'll only contact you when there's an unglued book to be cataloged.</dd>
<dt>Spread the word.</dt>

View File

@ -30,7 +30,8 @@
<div class="marc">
{% for record in records %}
<div>
<a class="fakeinput" href="{{ record.record.url }}">Download MARCXML</a>
<a class="fakeinput" href="{{ record.xml_record.url }}">Download MARCXML</a>
<a class="fakeinput" href="{{ record.mrc_record.url }}">Download .mrc</a>
<a href="{% url work record.edition.work.id %}" class="title clearfix">{{ record.edition.work.title }}</a>
</div>
{% endfor %}

View File

@ -11,6 +11,10 @@
{% endblock %}
{% 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 %}

View File

@ -2623,12 +2623,11 @@ class MARCUngluifyView(FormView):
def form_valid(self, form):
isbn = form.cleaned_data['isbn']
license = form.cleaned_data['license']
ebooks = { 'PDF': form.cleaned_data['pdf'],
'EPUB': form.cleaned_data['epub'],
'HTML': form.cleaned_data['html'],
'MOBI': form.cleaned_data['mobi'],
'TEXT': form.cleaned_data['text']
}
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,

View File

@ -343,3 +343,42 @@ AWS_STORAGE_BUCKET_NAME = ''
MAILCHIMP_API_KEY = '5f8e846a2bbc847807ed89086de4b4bf-us2'
MAILCHIMP_NEWS_ID = u'c5cce92fe1'
# let's be DRY with these parameters
# CCHOICES, CCGRANTS, and FORMATS are all used in places that expect tuples
# CONTENT_TYPES will be easiest to manipulate in ungluify_record as a dict
CCCHOICES = (
('CC BY','Creative Commons Attribution 3.0 Unported (CC BY 3.0)'),
('CC BY-SA','Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)'),
('CC BY-NC','Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)'),
('CC BY-NC-SA','Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)'),
('CC BY-NC-ND','Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY-NC-ND 3.0)'),
('CC BY-ND','Creative Commons Attribution-NoDerivs 3.0 Unported (CC BY-ND 3.0)'),
('CC0','No Rights Reserved (CC0)'),
)
CCGRANTS = (
('CC BY', 'http://creativecommons.org/licenses/by/3.0/'),
('CC BY-SA', 'http://creativecommons.org/licenses/by-sa/3.0/'),
('CC BY-NC', 'http://creativecommons.org/licenses/by-nc/3.0/'),
('CC BY-NC-SA', 'http://creativecommons.org/licenses/by-nc-sa/3.0/'),
('CC BY-NC-ND', 'http://creativecommons.org/licenses/by-nc-nd/3.0/'),
('CC BY-ND', 'http://creativecommons.org/licenses/by-nd/3.0/'),
('CC0', 'http://creativecommons.org/about/cc0'),
)
FORMATS = (
('pdf','PDF'),
('epub','EPUB'),
('html','HTML'),
('text','TEXT'),
('mobi','MOBI')
)
CONTENT_TYPES = {
'pdf': 'application/pdf',
'epub': 'application/epub+zip',
'html': 'text/html',
'text': 'text/plain',
'mobi': 'application/x-mobipocket-ebook'
}