From 1e4177766ba9e04105e5d83a090273074b90504c Mon Sep 17 00:00:00 2001
From: eric
Date: Mon, 21 Sep 2015 15:01:45 -0400
Subject: [PATCH] Enable subject editing on editions
---
frontend/forms.py | 7 ++++-
frontend/templates/new_edition.html | 48 +++++++++++++++++++++--------
frontend/views.py | 10 ------
3 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/frontend/forms.py b/frontend/forms.py
index 654b65c0..c854b0aa 100644
--- a/frontend/forms.py
+++ b/frontend/forms.py
@@ -86,7 +86,12 @@ bisac_headings = BisacHeading.objects.all()
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 = forms.CharField(max_length=200, required=False)
+ add_subject = AutoCompleteSelectField(
+ SubjectLookup,
+ widget=AutoCompleteSelectWidget(SubjectLookup,allow_new=True),
+ label='Keyword',
+ required =False
+ )
bisac = forms.ModelChoiceField( bisac_headings, required=False )
publisher_name = AutoCompleteSelectField(
diff --git a/frontend/templates/new_edition.html b/frontend/templates/new_edition.html
index a195bf98..69dcfa66 100644
--- a/frontend/templates/new_edition.html
+++ b/frontend/templates/new_edition.html
@@ -51,7 +51,31 @@ ul.fancytree-container {
return true;
});
- });
+ $j().ready(function(){
+ var contentblock = $j('#content-block');
+ contentblock.on("click", "span.deletebutton", function () {
+ var kw = $j(this).attr('data');
+ var li = $j(this).parent();
+
+ // perform action
+ jQuery.post('{% url 'kw_edit' edition.work.id %}', {'remove_kw': kw, 'csrfmiddlewaretoken': '{{ csrf_token }}' }, function(data) {
+ li.html('kw removed');
+ });
+ });
+ // this is the id of the submit button
+
+ $j('#add_subject_submit').click(function(event) {
+ data= $j('#id_add_subject_0').attr('value')
+ if (data == 'xxbadform'){
+ alert("bad keyword");
+ } else {
+ $j('#kw_list').append('' + data + 'x ')
+ }; // data will be the added kw.
+ });
+
+ });
+});
+
{{ form.media.js }}
@@ -72,7 +96,7 @@ ul.fancytree-container {
{% if admin %}
Title and ISBN 13 are required; the rest is optional, though a cover image is strongly recommended.
-
Publication Date (four-digit year ): {{ form.publication_date.errors }}{{ form.publication_date }}
-
- {% comment %}
- this has been removed since there's no point in exposing subject functionality when we're not doing anything with it -- will just confuse people.
-
Subjects :
-
+
{% if edition.work.pk and edition.work.subjects %}
{% for subject in edition.work.subjects.all %}
- {{ subject.name }}
+ {{ subject.name }}
+ {% if subject.authority %}
+ ({{subject.authority}})
+ {% endif %}
+ x
{% endfor %}
{% endif %}
{% for new_subject in edition.new_subjects %}
{{ new_subject }}
{% endfor %}
+
Add a Subject : {{ form.add_subject.errors }}{{ form.add_subject }}
-
- {% endcomment %}
+ Add Subject
Add BISAC Subject :
- {% for bisacsh in edition.work.bisac_headings %}
- {{ bisacsh.name }}
- {% endfor %}add headings :
+
Cover Image :
diff --git a/frontend/views.py b/frontend/views.py
index 5eb9c78c..8a6a0deb 100755
--- a/frontend/views.py
+++ b/frontend/views.py
@@ -570,16 +570,6 @@ def new_edition(request, work_id, edition_id, by=None):
author=models.Author.objects.create(name=new_author_name)
edition.new_authors.append((new_author_name,new_author_relation))
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
- elif request.POST.has_key('add_subject_submit') and admin:
- new_subject = request.POST['add_subject'].strip()
- try:
- subject= models.Subject.objects.get(name=new_subject)
- except models.Subject.DoesNotExist:
- subject=models.Subject.objects.create(name=new_subject)
- edition.new_subjects.append(subject)
- form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
- edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
-
elif edition.id and request.POST.has_key('ebook_%d-edition' % edition.id):
edition.ebook_form= EbookForm( data = request.POST, prefix = 'ebook_%d'%edition.id)
if edition.ebook_form.is_valid():