implement related works
parent
95fd91e283
commit
b3cefc2d3c
|
@ -73,20 +73,21 @@ from regluit.core.signals import (
|
|||
watermarker = BooXtream()
|
||||
|
||||
from .bibmodels import (
|
||||
Work,
|
||||
Author,
|
||||
Ebook,
|
||||
EbookFile,
|
||||
Edition,
|
||||
Identifier,
|
||||
Author,
|
||||
Relation,
|
||||
Relator,
|
||||
Subject,
|
||||
path_for_file,
|
||||
Publisher,
|
||||
PublisherName,
|
||||
WasWork,
|
||||
EbookFile,
|
||||
Ebook,
|
||||
path_for_file,
|
||||
Relation,
|
||||
Relator,
|
||||
safe_get_work,
|
||||
Subject,
|
||||
WasWork,
|
||||
Work,
|
||||
WorkRelation,
|
||||
)
|
||||
|
||||
pm = PostMonkey(settings.MAILCHIMP_API_KEY)
|
||||
|
|
|
@ -15,7 +15,12 @@ AGE_LEVEL_CHOICES = (
|
|||
('15-18', 'Teen - Grade 10-12, Age 15-18'),
|
||||
('18-', 'Adult/Advanced Reader')
|
||||
)
|
||||
TEXT_RELATION_CHOICES = (('translation', ''), ('revision', ''), ('sequel', ''), ('compilation', ''))
|
||||
TEXT_RELATION_CHOICES = (
|
||||
('translation', 'translation'),
|
||||
('revision', 'revision'),
|
||||
('sequel', 'sequel'),
|
||||
('compilation', 'compilation')
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -49,7 +49,14 @@ from regluit.core.models import (
|
|||
UNGLUEITAR
|
||||
)
|
||||
from regluit.libraryauth.models import Library
|
||||
from regluit.core.parameters import LIBRARY, REWARDS, BUY2UNGLUE, THANKS, AGE_LEVEL_CHOICES
|
||||
from regluit.core.parameters import (
|
||||
LIBRARY,
|
||||
REWARDS,
|
||||
BUY2UNGLUE,
|
||||
THANKS,
|
||||
AGE_LEVEL_CHOICES,
|
||||
TEXT_RELATION_CHOICES,
|
||||
)
|
||||
from regluit.core.lookups import (
|
||||
OwnerLookup,
|
||||
WorkLookup,
|
||||
|
@ -105,20 +112,32 @@ class EditionForm(forms.ModelForm):
|
|||
add_author = forms.CharField(max_length=500, required=False)
|
||||
add_author_relation = forms.ChoiceField(choices=CREATOR_RELATIONS, initial=('aut', 'Author'))
|
||||
add_subject = AutoCompleteSelectField(
|
||||
SubjectLookup,
|
||||
widget=AutoCompleteSelectWidget(SubjectLookup,allow_new=True),
|
||||
label='Keyword',
|
||||
required =False
|
||||
SubjectLookup,
|
||||
widget=AutoCompleteSelectWidget(SubjectLookup, allow_new=True),
|
||||
label='Keyword',
|
||||
required=False,
|
||||
)
|
||||
add_related_work = AutoCompleteSelectField(
|
||||
WorkLookup,
|
||||
widget=AutoCompleteSelectWidget(WorkLookup, allow_new=False, attrs={'size': 40}),
|
||||
label='Related Work',
|
||||
required=False,
|
||||
)
|
||||
add_work_relation = forms.ChoiceField(
|
||||
choices=TEXT_RELATION_CHOICES,
|
||||
initial=('translation', 'translation'),
|
||||
required=False,
|
||||
)
|
||||
|
||||
bisac = forms.ModelChoiceField( bisac_headings, required=False )
|
||||
|
||||
publisher_name = AutoCompleteSelectField(
|
||||
PublisherNameLookup,
|
||||
label='Publisher Name',
|
||||
widget=AutoCompleteSelectWidget(PublisherNameLookup,allow_new=True),
|
||||
required=False,
|
||||
allow_new=True,
|
||||
)
|
||||
PublisherNameLookup,
|
||||
label='Publisher Name',
|
||||
widget=AutoCompleteSelectWidget(PublisherNameLookup,allow_new=True),
|
||||
required=False,
|
||||
allow_new=True,
|
||||
)
|
||||
|
||||
isbn = ISBNField(
|
||||
label=_("ISBN"),
|
||||
|
@ -189,7 +208,7 @@ class EditionForm(forms.ModelForm):
|
|||
}
|
||||
)
|
||||
language = forms.ChoiceField(choices=LANGUAGES)
|
||||
age_level = forms.ChoiceField(choices=AGE_LEVEL_CHOICES)
|
||||
age_level = forms.ChoiceField(choices=AGE_LEVEL_CHOICES, required=False)
|
||||
description = forms.CharField( required=False, widget=CKEditorWidget())
|
||||
coverfile = forms.ImageField(required=False)
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ ul.fancytree-container {
|
|||
{% csrf_token %}
|
||||
{{ form.work }}
|
||||
{{ form.non_field_errors }}
|
||||
<!--{{ form.errors }}-->
|
||||
<div>
|
||||
<p><b>Title</b>: {{ form.title.errors }}{{ form.title }}</p>
|
||||
<p><b>Publisher Name</b> : {{ form.publisher_name.errors }}{{ form.publisher_name }}<br />(If you change this, click another form element before submitting)</p>
|
||||
|
@ -122,6 +123,23 @@ ul.fancytree-container {
|
|||
<input type="submit" name="add_author_submit" value="Add Author" id="submit_author"></p>
|
||||
|
||||
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
|
||||
{% if edition.pk %}
|
||||
<p><b>Add a Related Work</b>: {{ form.add_work_relation.errors }}{{ form.add_work_relation }} of {{ form.add_related_work.errors }}{{ form.add_related_work }}</p>
|
||||
<ul>{% for work_rel in edition.work.works_related_to.all %}
|
||||
<li>
|
||||
This work is a {{ work_rel.relation }} of <a href="{% url 'work' work_rel.from_work.id %}">{{ work_rel.from_work }}</a>.
|
||||
<input type="submit" name="delete_work_rel_{{ work_rel.id }}" value="x" class="deletebutton" title="delete work relation">
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% for work_rel in edition.work.works_related_from.all %}
|
||||
<li>
|
||||
<a href="{% url 'work' work_rel.to_work.id %}">{{ work_rel.to_work }}</a> is a {{ work_rel.relation }} of this work.
|
||||
<input type="submit" name="delete_work_rel_{{ work_rel.id }}" value="x" class="deletebutton" title="delete work relation">
|
||||
</li>
|
||||
{% endfor %}</ul>
|
||||
|
||||
|
||||
{% endif %}
|
||||
<p><b>Age Level</b>: {{ form.age_level.errors }}{{ form.age_level }}</p>
|
||||
<h4> Identifiers </h4>
|
||||
{% if id_msg %} <span class="errorlist">{{ id_msg }} </span>{% endif %}
|
||||
|
|
|
@ -278,6 +278,18 @@
|
|||
{{ work.last_campaign.description|safe }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
{% for work_rel in work.works_related_to.all %}
|
||||
<p>
|
||||
This work is a {{ work_rel.relation }} of <a href="{% url 'work' work_rel.from_work.id %}">{{ work_rel.from_work }}</a>.
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% for work_rel in work.works_related_from.all %}
|
||||
<p>
|
||||
<a href="{% url 'work' work_rel.to_work.id %}">{{ work_rel.to_work }}</a> is a {{ work_rel.relation }} of this work.
|
||||
</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="tabs-2" class="tabs {% if activetab == '2' %}active{% endif %}">
|
||||
|
|
|
@ -549,6 +549,13 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
edition.remove_author(author)
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
break
|
||||
work_rels = models.WorkRelation.objects.filter(Q(to_work=work) | Q(from_work=work))
|
||||
for work_rel in work_rels:
|
||||
if request.POST.has_key('delete_work_rel_%s' % work_rel.id):
|
||||
work_rel.delete()
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
break
|
||||
|
||||
if request.POST.has_key('add_author_submit') and admin:
|
||||
new_author_name = request.POST['add_author'].strip()
|
||||
new_author_relation = request.POST['add_author_relation']
|
||||
|
@ -561,7 +568,6 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
elif not form and admin:
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
if form.is_valid():
|
||||
print 'form is valid'
|
||||
form.save()
|
||||
if not work:
|
||||
work = models.Work(
|
||||
|
@ -599,6 +605,13 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
if request.POST.has_key('change_relator_%s' % relator.id):
|
||||
new_relation = request.POST['change_relator_%s' % relator.id]
|
||||
relator.set(new_relation)
|
||||
related_work = form.cleaned_data['add_related_work']
|
||||
if related_work:
|
||||
models.WorkRelation.objects.get_or_create(
|
||||
to_work=work,
|
||||
from_work=related_work,
|
||||
relation=form.cleaned_data['add_work_relation'],
|
||||
)
|
||||
for (author_name, author_relation) in edition.new_authors:
|
||||
edition.add_author(author_name, author_relation)
|
||||
if form.cleaned_data.has_key('bisac'):
|
||||
|
|
Loading…
Reference in New Issue