temp add kw
parent
a5c38d9354
commit
4f0cc87b48
|
@ -2,7 +2,7 @@ from selectable.base import ModelLookup
|
|||
from selectable.registry import registry
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from regluit.core.models import Work, PublisherName, Edition
|
||||
from regluit.core.models import Work, PublisherName, Edition, Subject
|
||||
|
||||
class OwnerLookup(ModelLookup):
|
||||
model = User
|
||||
|
@ -43,7 +43,12 @@ class EditionLookup(ModelLookup):
|
|||
item = None
|
||||
return item
|
||||
|
||||
class SubjectLookup(ModelLookup):
|
||||
model = Subject
|
||||
search_fields = ('name__icontains',)
|
||||
|
||||
registry.register(OwnerLookup)
|
||||
registry.register(WorkLookup)
|
||||
registry.register(PublisherNameLookup)
|
||||
registry.register(EditionLookup)
|
||||
registry.register(EditionLookup)
|
||||
registry.register(SubjectLookup)
|
|
@ -61,7 +61,8 @@ from regluit.core.lookups import (
|
|||
OwnerLookup,
|
||||
WorkLookup,
|
||||
PublisherNameLookup,
|
||||
EditionLookup
|
||||
EditionLookup,
|
||||
SubjectLookup,
|
||||
)
|
||||
from regluit.utils.localdatetime import now
|
||||
from regluit.utils.fields import EpubFileField, ISBNField
|
||||
|
@ -819,3 +820,10 @@ class LibModeForm(forms.ModelForm):
|
|||
class RegiftForm(forms.Form):
|
||||
give_to = forms.EmailField(label="email address of recipient")
|
||||
give_message = forms.CharField( max_length=512, label="your gift message", initial="Here's an ebook from unglue.it, I hope you like it! - me")
|
||||
|
||||
class SubjectSelectForm(forms.Form):
|
||||
add_kw = AutoCompleteSelectField(
|
||||
SubjectLookup,
|
||||
widget=AutoCompleteSelectWidget(SubjectLookup,allow_new=False),
|
||||
label='Keyword',
|
||||
)
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
{% block extra_css %}
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/campaign2.css" />
|
||||
{% if user.is_staff or user in work.last_campaign.managers.all %}
|
||||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen">
|
||||
{{ kwform.media.css }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
|
@ -22,6 +26,9 @@
|
|||
<script type="text/javascript" src="/static/js/widgets.js"></script>
|
||||
<script type="text/javascript" src="/static/js/counter.js"></script>
|
||||
<script type="text/javascript" src="/static/js/embed.js"></script>
|
||||
{% if user.is_staff or user in work.last_campaign.managers.all %}
|
||||
{{ kwform.media.js }}
|
||||
{% endif %}
|
||||
|
||||
<!-- needed for DeGruyter seed description hack
|
||||
makes template vars accessible in JS
|
||||
|
@ -424,7 +431,7 @@
|
|||
|
||||
{% endif %}
|
||||
{% if work.subjects.all.count > 0 %}
|
||||
<h4>Subjects</h4>
|
||||
<h4>Keywords</h4>
|
||||
<ul>
|
||||
{% for subject in work.subjects.all %}
|
||||
<li itemprop="keywords">{{ subject.name }}
|
||||
|
@ -434,6 +441,10 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if user.is_staff or user in work.last_campaign.managers.all %}
|
||||
<form method="POST" action="{% url kw_edit work.id %}" id="kw_add_form">{% csrf_token %}
|
||||
{{ kwform.add_kw }}<input type="submit" name="kw_add" value="add keyword" />
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endifequal %}
|
||||
<h4>Editions</h4>
|
||||
|
|
|
@ -119,6 +119,7 @@ from regluit.frontend.forms import (
|
|||
DateCalculatorForm,
|
||||
UserNamePass,
|
||||
RegiftForm,
|
||||
SubjectSelectForm
|
||||
)
|
||||
|
||||
from regluit.payment import baseprocessor, stripelib
|
||||
|
@ -434,6 +435,7 @@ def work(request, work_id, action='display'):
|
|||
'cover_width': cover_width_number,
|
||||
'action': action,
|
||||
'formset': formset,
|
||||
'kwform': SubjectSelectForm()
|
||||
})
|
||||
|
||||
def edition_uploads(request, edition_id):
|
||||
|
@ -2174,7 +2176,7 @@ def wishlist(request):
|
|||
def kw_edit(request, work_id):
|
||||
work = safe_get_work(work_id)
|
||||
remove_kw = request.POST.get('remove_kw', None)
|
||||
add_kw = request.POST.get('add_kw', None)
|
||||
add_form = request.POST.get('kw_add', False) # signal to process form
|
||||
if request.user.is_staff or request.user in work.last_campaign().managers.all():
|
||||
if remove_kw:
|
||||
try:
|
||||
|
@ -2183,14 +2185,21 @@ def kw_edit(request, work_id):
|
|||
return HttpResponse('invalid subject')
|
||||
work.subjects.remove(subject)
|
||||
return HttpResponse('removed ' + remove_kw )
|
||||
elif add_kw:
|
||||
try:
|
||||
subject = models.Subject.objects.get(name=add_kw)
|
||||
except models.Subject.DoesNotExist:
|
||||
return HttpResponse('invalid subject')
|
||||
work.subjects.add(subject)
|
||||
return HttpResponse('added ' + add_kw )
|
||||
return HttpResponse("nothing")
|
||||
elif add_form:
|
||||
form= SubjectSelectForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
add_kw = form.cleaned_data['add_kw']
|
||||
try:
|
||||
subject = models.Subject.objects.get(name=add_kw)
|
||||
except models.Subject.DoesNotExist:
|
||||
return HttpResponse('invalid subject')
|
||||
work.subjects.add(subject)
|
||||
return HttpResponse('added ' + add_kw.name )
|
||||
else:
|
||||
return HttpResponse('bad form ' )
|
||||
else:
|
||||
return HttpResponse(str(add_form))
|
||||
return HttpResponse(str(add_form))
|
||||
|
||||
|
||||
class InfoPageView(TemplateView):
|
||||
|
|
|
@ -113,4 +113,6 @@ $k(document).on("click", ".add-wishlist-workpage span", function() {
|
|||
newSpan.fadeIn('slow');
|
||||
newSpan.removeAttr("id");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//handle kw adding
|
||||
|
|
Loading…
Reference in New Issue