implement EditionNote

pull/1/head
eric 2016-08-16 17:16:44 -04:00
parent aafbd7c70b
commit 363c86fd94
10 changed files with 57 additions and 14 deletions

View File

@ -3,7 +3,7 @@ from selectable.registry import registry
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
@ -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)

View File

@ -11,11 +11,18 @@ 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(
@ -23,11 +30,6 @@ class Migration(migrations.Migration):
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',
@ -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'),
),
]

View File

@ -36,7 +36,7 @@ class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20160805_1550'),
('core', '0003_auto_20160816_1645'),
]
operations = [

View File

@ -77,6 +77,7 @@ from .bibmodels import (
Ebook,
EbookFile,
Edition,
EditionNote,
Identifier,
path_for_file,
Publisher,

View File

@ -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:
@ -942,6 +942,10 @@ class Edition(models.Model):
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)

View File

@ -62,6 +62,7 @@ from regluit.core.lookups import (
WorkLookup,
PublisherNameLookup,
SubjectLookup,
EditionNoteLookup,
)
from regluit.utils.localdatetime import now
from regluit.utils.fields import ISBNField
@ -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 = []
@ -238,7 +245,6 @@ class EditionForm(forms.ModelForm):
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')

View File

@ -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 %}

View File

@ -141,6 +141,7 @@ ul.fancytree-container {
{% 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>

View File

@ -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(
@ -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(

View File

@ -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):