revamp sitemap priority, add to opds

pull/1/head
eric 2016-01-19 17:28:45 -05:00
parent 21d00f0020
commit f33cd6e487
4 changed files with 17 additions and 18 deletions

View File

@ -156,8 +156,10 @@ def work_node(work, facet=None):
logger.warning('Deleting subject: %s' % subject.name)
subject.delete()
# rating
rating_node = etree.Element("{http://schema.org}Rating")
rating_node.attrib.update({"{http://schema.org}ratingValue":"{:}".format(work.priority())})
node.append(rating_node)
return node
class Facet:
@ -231,8 +233,10 @@ def opds_feed_for_works(the_facet, page=None, order_by='newest'):
xmlns:opds="http://opds-spec.org/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:schema="http://schema.org"
xsi:noNamespaceSchemaLocation="http://www.kbcafe.com/rss/atom.xsd.xml"
xsi:schemaLocation="http://purl.org/dc/elements/1.1/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dc.xsd http://purl.org/dc/terms/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dcterms.xsd"/>"""
xsi:schemaLocation="http://purl.org/dc/elements/1.1/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dc.xsd
http://purl.org/dc/terms/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dcterms.xsd"/>"""
feed = etree.fromstring(feed_xml)

View File

@ -10,6 +10,7 @@ import urllib
import urllib2
from urlparse import urlparse
import unicodedata
import math
from ckeditor.fields import RichTextField
from datetime import timedelta, datetime
@ -1416,6 +1417,13 @@ class Work(models.Model):
self.num_wishes = Wishes.objects.filter(work=self).count()
self.save()
def priority(self):
if self.last_campaign():
return 5
freedom = 1 if self.is_free else 0
wishing = int(math.log(self.num_wishes )) + 1 if self.num_wishes else 0
return min( freedom + wishing, 5 )
def first_oclc(self):
if self.preferred_edition == None:
return ''

View File

@ -10,21 +10,7 @@ class WorkSitemap(Sitemap):
return Work.objects.all()
def priority(self,work):
if work.last_campaign():
return '1.0'
if work.num_wishes>1000:
return '0.8'
if work.num_wishes>100:
return '0.6'
if work.num_wishes>10:
return '0.4'
if work.num_wishes>1:
return '0.3'
if work.num_wishes==1:
return '0.2'
if work.num_wishes==0:
return '0.1'
return '0.1'
return '{:.1f}'.format(work.priority()/5.0)
class PublisherSitemap(Sitemap):
priority = 0.2

View File

@ -653,6 +653,7 @@ class WishlistTest(TestCase):
user.wishlist.remove_work(work)
self.assertEqual(user.wishlist.works.count(), 0)
self.assertEqual(work.num_wishes, num_wishes)
self.assertTrue(work.priority()==1)
class CeleryTaskTest(TestCase):