implement age_level

pull/1/head
eric 2016-08-15 13:47:00 -04:00
parent abedff089c
commit 9b0c91a439
6 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import datetime import datetime
import pytz import pytz
import re
from lxml import etree from lxml import etree
from regluit.core import models from regluit.core import models
from regluit.core.cc import ccinfo from regluit.core.cc import ccinfo
@ -134,6 +135,19 @@ def product(edition, facet=None):
subj_node.append(text_node("SubjectSchemeIdentifier", "20")) subj_node.append(text_node("SubjectSchemeIdentifier", "20"))
subj_node.append(text_node("SubjectHeadingText", subject.name)) subj_node.append(text_node("SubjectHeadingText", subject.name))
# audience range composite
if work.age_level:
range_match = re.search(r'(\d?\d?)-(\d?\d?)', work.age_level)
if range_match:
audience_range_node = etree.SubElement(descriptive_node, "AudienceRange")
audience_range_node.append(text_node("AudienceRangeQualifier", "17")) #Interest age, years
if range_match.group(1):
audience_range_node.append(text_node("AudienceRangePrecision", "03")) #from
audience_range_node.append(text_node("AudienceRangeValue", range_match.group(1)))
if range_match.group(2):
audience_range_node.append(text_node("AudienceRangePrecision", "04")) #from
audience_range_node.append(text_node("AudienceRangeValue", range_match.group(2)))
# Collateral Detail Block # Collateral Detail Block
coll_node = etree.SubElement(product_node, "CollateralDetail") coll_node = etree.SubElement(product_node, "CollateralDetail")
desc_node = etree.SubElement(coll_node, "TextContent") desc_node = etree.SubElement(coll_node, "TextContent")

View File

@ -163,6 +163,16 @@ def work_node(work, facet=None):
# caused by control chars in subject.name # caused by control chars in subject.name
logger.warning('Deleting subject: %s' % subject.name) logger.warning('Deleting subject: %s' % subject.name)
subject.delete() subject.delete()
# age level
# <category term="15-18" scheme="http://schema.org/typicalAgeRange" label="Teen - Grade 10-12, Age 15-18"/>
if work.age_level:
category_node = etree.Element("category")
category_node.attrib["scheme"] = 'http://schema.org/typicalAgeRange'
category_node.attrib["term"] = work.age_level
category_node.attrib["label"] = work.get_age_level_display()
node.append(category_node)
# rating # rating
rating_node = etree.Element("{http://schema.org/}Rating") rating_node = etree.Element("{http://schema.org/}Rating")

View File

@ -58,7 +58,7 @@ from regluit.core.models import (
UNGLUEITAR UNGLUEITAR
) )
from regluit.libraryauth.models import Library from regluit.libraryauth.models import Library
from regluit.core.parameters import LIBRARY, REWARDS, BUY2UNGLUE, THANKS from regluit.core.parameters import LIBRARY, REWARDS, BUY2UNGLUE, THANKS, AGE_LEVEL_CHOICES
from regluit.core.lookups import ( from regluit.core.lookups import (
OwnerLookup, OwnerLookup,
WorkLookup, WorkLookup,
@ -199,6 +199,7 @@ class EditionForm(forms.ModelForm):
} }
) )
language = forms.ChoiceField(choices=LANGUAGES) language = forms.ChoiceField(choices=LANGUAGES)
age_level = forms.ChoiceField(choices=AGE_LEVEL_CHOICES)
description = forms.CharField( required=False, widget=CKEditorWidget()) description = forms.CharField( required=False, widget=CKEditorWidget())
coverfile = forms.ImageField(required=False) coverfile = forms.ImageField(required=False)

View File

@ -122,6 +122,7 @@ ul.fancytree-container {
<input type="submit" name="add_author_submit" value="Add Author" id="submit_author"></p> <input type="submit" name="add_author_submit" value="Add Author" id="submit_author"></p>
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p> <p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
<p><b>Age Level</b>: {{ form.age_level.errors }}{{ form.age_level }}</p>
<h4> Identifiers </h4> <h4> Identifiers </h4>
{% if id_msg %} <span class="errorlist">{{ id_msg }} </span>{% endif %} {% if id_msg %} <span class="errorlist">{{ id_msg }} </span>{% endif %}
<p> Enter 'delete' to remove the identifier. </p> <p> Enter 'delete' to remove the identifier. </p>

View File

@ -102,6 +102,8 @@
<span itemprop="publisher"><a href="{% url 'bypubname_list' work.last_campaign.publisher.name.id %}">{{ work.last_campaign.publisher }}</a></span> <span itemprop="publisher"><a href="{% url 'bypubname_list' work.last_campaign.publisher.name.id %}">{{ work.last_campaign.publisher }}</a></span>
{% endif %} {% endif %}
<span itemprop="datePublished">{{ work.publication_date }}</span> <span itemprop="datePublished">{{ work.publication_date }}</span>
<meta itemprop="inLanguage" content="work.language" />
<meta itemprop="typicalAgeRange" content="work.age_range" />
</h3> </h3>
</div> </div>
</div> </div>

View File

@ -514,11 +514,15 @@ def new_edition(request, work_id, edition_id, by=None):
language='en' language='en'
description='' description=''
title='' title=''
age_level = ''
description = ''
title = ''
if work_id: if work_id:
work = safe_get_work(work_id) work = safe_get_work(work_id)
language=work.language language=work.language
description=work.description description=work.description
title=work.title title=work.title
age_level = work.age_level
else: else:
work=None work=None
@ -533,6 +537,7 @@ def new_edition(request, work_id, edition_id, by=None):
edition.work = work edition.work = work
language=edition.work.language language=edition.work.language
description=edition.work.description description=edition.work.description
age_level = edition.work.age_level
else: else:
edition = models.Edition() edition = models.Edition()
if work: if work:
@ -552,6 +557,7 @@ def new_edition(request, work_id, edition_id, by=None):
'doi': edition.id_for('doi'), 'doi': edition.id_for('doi'),
} }
if request.method == 'POST' : if request.method == 'POST' :
'age_level': age_level,
form = None form = None
edition.new_authors=zip(request.POST.getlist('new_author'),request.POST.getlist('new_author_relation')) edition.new_authors=zip(request.POST.getlist('new_author'),request.POST.getlist('new_author_relation'))
edition.new_subjects=request.POST.getlist('new_subject') edition.new_subjects=request.POST.getlist('new_subject')
@ -577,6 +583,7 @@ def new_edition(request, work_id, edition_id, by=None):
form.save() form.save()
if not work: if not work:
work= models.Work(title=form.cleaned_data['title'],language=form.cleaned_data['language'],description=form.cleaned_data['description']) work= models.Work(title=form.cleaned_data['title'],language=form.cleaned_data['language'],description=form.cleaned_data['description'])
age_level=form.cleaned_data['age_level'],
work.save() work.save()
edition.work=work edition.work=work
edition.save() edition.save()
@ -585,6 +592,7 @@ def new_edition(request, work_id, edition_id, by=None):
work.title=form.cleaned_data['title'] work.title=form.cleaned_data['title']
work.publication_range = None # will reset on next access work.publication_range = None # will reset on next access
work.language = form.cleaned_data['language'] work.language = form.cleaned_data['language']
work.age_level = form.cleaned_data['age_level']
work.save() work.save()
id_msg="" id_msg=""