Skip to content

Commit

Permalink
implement EditionNote
Browse files Browse the repository at this point in the history
  • Loading branch information
eshellman committed Aug 16, 2016
1 parent aafbd7c commit 363c86f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 14 deletions.
13 changes: 11 additions & 2 deletions core/lookups.py
Expand Up @@ -3,7 +3,7 @@

from django.contrib.auth.models import User
from django.db.models import Count
from regluit.core.models import Work, PublisherName, Edition, Subject
from regluit.core.models import Work, PublisherName, Edition, Subject, EditionNote

class OwnerLookup(ModelLookup):
model = User
Expand Down Expand Up @@ -54,8 +54,17 @@ class SubjectLookup(ModelLookup):
def get_query(self, request, term):
return super(SubjectLookup, self).get_query( request, term).annotate(Count('works')).order_by('-works__count')

class EditionNoteLookup(ModelLookup):
model = EditionNote
search_fields = ('note__icontains',)
def create_item(self, value):
new_note, created = EditionNote.objects.get_or_create(note=value)
new_note.save()
return new_note

registry.register(OwnerLookup)
registry.register(WorkLookup)
registry.register(PublisherNameLookup)
registry.register(EditionLookup)
registry.register(SubjectLookup)
registry.register(SubjectLookup)
registry.register(EditionNoteLookup)
Expand Up @@ -11,23 +11,25 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='EditionNote',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('note', models.CharField(max_length=64, unique=True, null=True, blank=True)),
],
),
migrations.CreateModel(
name='WorkRelation',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('relation', models.CharField(max_length=15, choices=[(b'translation', b''), (b'revision', b''), (b'sequel', b''), (b'compilation', b'')])),
('relation', models.CharField(max_length=15, choices=[(b'translation', b'translation'), (b'revision', b'revision'), (b'sequel', b'sequel'), (b'compilation', b'compilation')])),
],
),
migrations.AddField(
model_name='ebook',
name='version',
field=models.CharField(max_length=255, null=True),
),
migrations.AddField(
model_name='edition',
name='note',
field=models.CharField(max_length=64, null=True),
),
migrations.AddField(
model_name='work',
name='age_level',
Expand All @@ -43,9 +45,14 @@ class Migration(migrations.Migration):
name='to_work',
field=models.ForeignKey(related_name='works_related_to', to='core.Work'),
),
migrations.AddField(
model_name='edition',
name='note',
field=models.ForeignKey(to='core.EditionNote', null=True),
),
migrations.AddField(
model_name='work',
name='related',
field=models.ManyToManyField(to='core.Work', null=True, through='core.WorkRelation'),
field=models.ManyToManyField(related_name='reverse_related', null=True, through='core.WorkRelation', to='core.Work'),
),
]
2 changes: 1 addition & 1 deletion core/migrations/0004_auto_20160808_1548.py
Expand Up @@ -36,7 +36,7 @@ def doi_to_url(apps, schema_editor):


dependencies = [
('core', '0003_auto_20160805_1550'),
('core', '0003_auto_20160816_1645'),
]

operations = [
Expand Down
1 change: 1 addition & 0 deletions core/models/__init__.py
Expand Up @@ -77,6 +77,7 @@
Ebook,
EbookFile,
Edition,
EditionNote,
Identifier,
path_for_file,
Publisher,
Expand Down
6 changes: 5 additions & 1 deletion core/models/bibmodels.py
Expand Up @@ -763,7 +763,7 @@ class Edition(models.Model):
work = models.ForeignKey("Work", related_name="editions", null=True)
cover_image = models.URLField(null=True, blank=True)
unglued = models.BooleanField(default=False)
note = models.CharField(max_length=64, null=True, blank=True)
note = models.ForeignKey("EditionNote", null=True)

def __unicode__(self):
if self.isbn_13:
Expand Down Expand Up @@ -942,6 +942,10 @@ def funding_info(self):
def description(self):
return self.work.description

class EditionNote(models.Model):
note = models.CharField(max_length=64, null=True, blank=True, unique=True)
def __unicode__(self):
return self.note

class Publisher(models.Model):
created = models.DateTimeField(auto_now_add=True)
Expand Down
10 changes: 8 additions & 2 deletions frontend/forms.py
Expand Up @@ -62,6 +62,7 @@
WorkLookup,
PublisherNameLookup,
SubjectLookup,
EditionNoteLookup,
)
from regluit.utils.localdatetime import now
from regluit.utils.fields import ISBNField
Expand Down Expand Up @@ -211,7 +212,13 @@ class EditionForm(forms.ModelForm):
age_level = forms.ChoiceField(choices=AGE_LEVEL_CHOICES, required=False)
description = forms.CharField( required=False, widget=CKEditorWidget())
coverfile = forms.ImageField(required=False)

note = AutoCompleteSelectField(
EditionNoteLookup,
widget=AutoCompleteSelectWidget(EditionNoteLookup, allow_new=True),
label='Edition Note',
required=False,
allow_new=True,
)
def __init__(self, *args, **kwargs):
super(EditionForm, self).__init__(*args, **kwargs)
self.relators = []
Expand All @@ -238,7 +245,6 @@ def clean(self):
if not has_isbn and not has_oclc and not has_goog and not has_http and not has_doi:
raise forms.ValidationError(_("There must be either an ISBN, a DOI, a URL or an OCLC number."))
return self.cleaned_data

class Meta:
model = Edition
exclude = ('created', 'work')
Expand Down
3 changes: 3 additions & 0 deletions frontend/templates/edition_display.html
Expand Up @@ -16,6 +16,9 @@
{% endfor %}
<br />
{% endif %}
{% if edition.note %}
{{ edition.note }}.<br />
{% endif %}
{% if edition.publisher %}
Publisher: <a href="{% url 'bypubname_list' edition.publisher_name.id %}">{{edition.publisher}}</a><br />
{% endif %}
Expand Down
1 change: 1 addition & 0 deletions frontend/templates/new_edition.html
Expand Up @@ -141,6 +141,7 @@ <h2>Create New Edition</h2>

{% endif %}
<p><b>Age Level</b>: {{ form.age_level.errors }}{{ form.age_level }}</p>
<p><b>Edition Note</b>: {{ form.note.errors }}{{ form.note }}</p>
<h4> Identifiers </h4>
{% if id_msg %} <span class="errorlist">{{ id_msg }} </span>{% endif %}
<p> Enter 'delete' to remove the identifier. </p>
Expand Down
13 changes: 12 additions & 1 deletion marc/load.py
Expand Up @@ -89,6 +89,17 @@ def stub(edition):
)
record.add_ordered_field(field245)

#edition statement
if edition.note:
field250 = pymarc.Field(
tag='250',
indicators = [' ', ' '],
subfields = [
'a', unicode(edition.note),
]
)
record.add_ordered_field(field250)

# publisher, date
if edition.publisher:
field260 = pymarc.Field(
Expand All @@ -101,7 +112,7 @@ def stub(edition):
if edition.publication_date:
field260.add_subfield('c', unicode(edition.publication_date))
record.add_ordered_field(field260)

if edition.description:
#add 520 field (description)
field520 = pymarc.Field(
Expand Down
1 change: 1 addition & 0 deletions marc/models.py
Expand Up @@ -56,6 +56,7 @@ class AbstractEdition:
publisher = ''
title = ''
publication_date = ''
note = ''

# the edition should be able to report ebook downloads, with should have format and url attributes
def downloads(self):
Expand Down

0 comments on commit 363c86f

Please sign in to comment.