Merge pull request #348 from Gluejar/list_by_license

List by license [#70951010]
pull/1/head
Raymond Yee 2014-05-14 09:14:03 -07:00
commit 4d359b53c1
11 changed files with 164 additions and 92 deletions

100
core/cc.py Normal file
View File

@ -0,0 +1,100 @@
# mostly constants related to Creative Commons
# let's be DRY with these parameters
INFO_CC = (
('CC BY-NC-ND', 'by-nc-nd', 'Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY-NC-ND 3.0)', 'http://creativecommons.org/licenses/by-nc-nd/3.0/'),
('CC BY-NC-SA', 'by-nc-sa', 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)', 'http://creativecommons.org/licenses/by-nc-sa/3.0/'),
('CC BY-NC', 'by-nc', 'Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)', 'http://creativecommons.org/licenses/by-nc/3.0/'),
('CC BY-ND', 'by-nd', 'Creative Commons Attribution-NoDerivs 3.0 Unported (CC BY-ND 3.0)', 'http://creativecommons.org/licenses/by-nd/3.0/'),
('CC BY-SA', 'by-sa', 'Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)', 'http://creativecommons.org/licenses/by-sa/3.0/'),
('CC BY', 'by', 'Creative Commons Attribution 3.0 Unported (CC BY 3.0)', 'http://creativecommons.org/licenses/by/3.0/'),
('CC0', 'cc0', 'No Rights Reserved (CC0)', 'http://creativecommons.org/about/cc0'),
)
INFO_PD = (
('PD-US', 'pd-us', 'Public Domain, US', 'http://creativecommons.org/about/pdm'),
)
INFO_ALL = INFO_CC + INFO_PD
# CCHOICES, CCGRANTS, and FORMATS are all used in places that expect tuples
# CONTENT_TYPES will be easiest to manipulate in ungluify_record as a dict
CCCHOICES = tuple([(item[0],item[2]) for item in INFO_CC])
CHOICES = tuple([(item[0],item[2]) for item in INFO_ALL])
CCGRANTS = tuple([(item[0],item[3]) for item in INFO_CC])
GRANTS = tuple([(item[0],item[3]) for item in INFO_ALL])
LICENSE_LIST = [item[0] for item in INFO_CC]
LICENSE_LIST_ALL = [item[0] for item in INFO_ALL]
FACET_LIST = [item[1] for item in INFO_CC]
class CCLicense():
@staticmethod
def url(license):
if license in LICENSE_LIST_ALL:
return INFO_ALL[LICENSE_LIST_ALL.index(license)][3]
else:
return ''
@staticmethod
def badge(license):
if license == 'PD-US':
return 'https://i.creativecommons.org/p/mark/1.0/88x31.png'
elif license == 'CC0':
return 'https://i.creativecommons.org/p/zero/1.0/88x31.png'
elif license == 'CC BY':
return 'https://i.creativecommons.org/l/by/3.0/88x31.png'
elif license == 'CC BY-NC-ND':
return 'https://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png'
elif license == 'CC BY-NC-SA':
return 'https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png'
elif license == 'CC BY-NC':
return 'https://i.creativecommons.org/l/by-nc/3.0/88x31.png'
elif license == 'CC BY-SA':
return 'https://i.creativecommons.org/l/by-sa/3.0/88x31.png'
elif license == 'CC BY-ND':
return 'https://i.creativecommons.org/l/by-nd/3.0/88x31.png'
else:
return ''
def description(license):
if license == 'PD-US':
return 'Use of this material is not restricted by copyright in the US.'
elif license == 'CC0':
return 'The copyright owner has dedicated the material to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.'
elif license == 'CC BY':
return 'You are free to: copy and redistribute the material in any medium or format; remix, transform, and build upon the material; for any purpose, even commercially. Under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.'
elif license == 'CC BY-NC-ND':
return 'You are free to: copy and redistribute the material in any medium or format; under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.; you may not use the material for commercial purposes; if you remix, transform, or build upon the material, you may not distribute the modified material.'
elif license == 'CC BY-NC-SA':
return 'You are free to: copy and redistribute the material in any medium or format; remix, transform, and build upon the material; Under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. You may not use the material for commercial purposes. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.'
elif license == 'CC BY-NC':
return 'You are free to: copy and redistribute the material in any medium or format; remix, transform, and build upon the material; under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. You may not use the material for commercial purposes.'
elif license == 'CC BY-SA':
return 'You are free to: copy and redistribute the material in any medium or format; remix, transform, and build upon the material; for any purpose, even commercially. Under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.'
elif license == 'CC BY-ND':
return 'You are free to: copy and redistribute the material in any medium or format; for any purpose, even commercially. Under the following terms: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. If you remix, transform, or build upon the material, you may not distribute the modified material.'
else:
return ''
class ccinfo():
def __init__(self, license):
self.license=license
@property
def description(self):
return description(self.license)
@property
def badge(self):
return CCLicense.badge(self.license)
@property
def url(self):
return CCLicense.url(self.license)
@property
def title(self):
if license in LICENSE_LIST_ALL:
return INFO_ALL[LICENSE_LIST_ALL.index(license)][2]
else:
return ''

View File

@ -33,6 +33,7 @@ regluit imports
'''
import regluit
import regluit.core.isbn
import regluit.core.cc as cc
from regluit.core.epub import personalize, ungluify, test_epub
from regluit.core.signals import (
@ -220,52 +221,6 @@ class CampaignAction(models.Model):
type = models.CharField(max_length=15)
comment = models.TextField(null=True, blank=True)
campaign = models.ForeignKey("Campaign", related_name="actions", null=False)
class CCLicense():
CHOICES = settings.CHOICES
@staticmethod
def url(license):
if license == 'PD-US':
return 'http://creativecommons.org/publicdomain/mark/1.0/'
elif license == 'CC0':
return 'http://creativecommons.org/publicdomain/zero/1.0/'
elif license == 'CC BY':
return 'http://creativecommons.org/licenses/by/3.0/'
elif license == 'CC BY-NC-ND':
return 'http://creativecommons.org/licenses/by-nc-nd/3.0/'
elif license == 'CC BY-NC-SA':
return 'http://creativecommons.org/licenses/by-nc-sa/3.0/'
elif license == 'CC BY-NC':
return 'http://creativecommons.org/licenses/by-nc/3.0/'
elif license == 'CC BY-SA':
return 'http://creativecommons.org/licenses/by-sa/3.0/'
elif license == 'CC BY-ND':
return 'http://creativecommons.org/licenses/by-nd/3.0/'
else:
return ''
@staticmethod
def badge(license):
if license == 'PD-US':
return 'https://i.creativecommons.org/p/mark/1.0/88x31.png'
elif license == 'CC0':
return 'https://i.creativecommons.org/p/zero/1.0/88x31.png'
elif license == 'CC BY':
return 'https://i.creativecommons.org/l/by/3.0/88x31.png'
elif license == 'CC BY-NC-ND':
return 'https://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png'
elif license == 'CC BY-NC-SA':
return 'https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png'
elif license == 'CC BY-NC':
return 'https://i.creativecommons.org/l/by-nc/3.0/88x31.png'
elif license == 'CC BY-SA':
return 'https://i.creativecommons.org/l/by-sa/3.0/88x31.png'
elif license == 'CC BY-ND':
return 'https://i.creativecommons.org/l/by-nd/3.0/88x31.png'
else:
return ''
class Offer(models.Model):
CHOICES = ((INDIVIDUAL,'Individual license'),(LIBRARY,'Library License'))
@ -420,7 +375,7 @@ class Hold(models.Model):
return Hold.objects.filter(work=self.work,library=self.library,created__lt=self.created).count()
class Campaign(models.Model):
LICENSE_CHOICES = settings.CCCHOICES
LICENSE_CHOICES = cc.CCCHOICES
created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=500, null=True, blank=False)
description = RichTextField(null=True, blank=False)
@ -880,11 +835,11 @@ class Campaign(models.Model):
@property
def license_url(self):
return CCLicense.url(self.license)
return cc.CCLicense.url(self.license)
@property
def license_badge(self):
return CCLicense.badge(self.license)
return cc.CCLicense.badge(self.license)
@property
def success_date(self):
@ -1634,7 +1589,7 @@ class EbookFile(models.Model):
class Ebook(models.Model):
FORMAT_CHOICES = settings.FORMATS
RIGHTS_CHOICES = settings.CCCHOICES
RIGHTS_CHOICES = cc.CCCHOICES
url = models.URLField(max_length=1024)
created = models.DateTimeField(auto_now_add=True)
format = models.CharField(max_length=25, choices = FORMAT_CHOICES)
@ -1653,8 +1608,8 @@ class Ebook(models.Model):
@property
def rights_badge(self):
if self.rights is None :
return CCLicense.badge('PD-US')
return CCLicense.badge(self.rights)
return cc.CCLicense.badge('PD-US')
return cc.CCLicense.badge(self.rights)
@staticmethod
def infer_provider( url):

View File

@ -15,6 +15,7 @@ from django.conf import settings
from django.core.files.storage import default_storage
from django.core.urlresolvers import reverse
import regluit.core.cc as cc
from regluit.core import models
def makemarc(marcfile, edition):
@ -145,7 +146,7 @@ def makemarc(marcfile, edition):
if edition.unglued:
funding_info = 'The book is available as a free download thanks to the generous support of interested readers and organizations, who made donations using the crowd-funding website Unglue.it.'
else:
if edition.ebooks.all()[0].rights in ['CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA']:
if edition.ebooks.all()[0].rights in cc.LICENSE_LIST:
funding_info = 'The book is available as a free download thanks to a Creative Commons license.'
else:
funding_info = 'The book is available as a free download because it is in the Public Domain.'
@ -163,8 +164,8 @@ def makemarc(marcfile, edition):
tag='540',
indicators = [' ', ' '],
subfields = [
'a', dict(settings.CHOICES)[license],
'u', dict(settings.GRANTS)[license],
'a', dict(cc.CHOICES)[license],
'u', dict(cc.GRANTS)[license],
]
)
record.add_ordered_field(field540)

View File

@ -2,7 +2,7 @@
{% load endless %}
{% load lang_utils %}
{% block title %} Creative Commons Books {% if pub_lang %} in {{pub_lang|ez_lang_name}}{% endif %}{% endblock %}
{% block title %} Creative Commons {{license}} Books {% if pub_lang %} in {{pub_lang|ez_lang_name}}{% endif %}{% endblock %}
{% block extra_css %}
<link type="text/css" rel="stylesheet" href="/static/css/supporter_layout.css" />
<link type="text/css" rel="stylesheet" href="/static/css/book_list.css" />
@ -27,9 +27,11 @@
<div class="js-topnews3">
<div class="user-block">
<div id="user-block1">
<div id="block-intro-text"><span class="special-user-name">Ready to Read</span></div>
<div id="block-intro-text"><br /><span class="special-user-name">Ready to Read</span></div>
</div>
<div class="user-block2"><span class="user-short-info">These {% if pub_lang %}{{ pub_lang|ez_lang_name }} language {% endif %}<a href="http://creativecommons.org/">Creative Commons</a> licensed ebooks are ready to read - the people who created them want you to read and share them.</span>
<div class="user-block24"><p style="font-size: larger;"><span class="user-short-info">These {% if pub_lang %}{{ pub_lang|ez_lang_name }} language {% endif %}<a href="http://creativecommons.org/">Creative Commons</a> {% if license %}<a href="{{cc.url}}">{{ license }}</a>{% endif %} licensed ebooks are ready to read - the people who created them want you to read and share them.</span></p>
{% if license %}<p style="font-size: smaller;"><a href="{{cc.url}}"><img src="{{cc.badge}}" alt="badge for {{license}}" style="float:left;padding:0.5em" /></a> {{cc.description}}
</p>{% endif %}
</div>
<div class="user-block3">
</div>
@ -72,7 +74,7 @@
<div id="content-block-content">
<div id="books-go-here">
{% ifequal work_list.count 0 %}
There aren't any {{ pub_lang|ez_lang_name }} works in this list. Why don't you add some?
There aren't any {{ pub_lang|ez_lang_name }} Creative Commons {{ license }} works in this list. Why don't you add some? Use the "More" tab on a work, there are links there for adding CC ebooks.
{% else %}
{% lazy_paginate 20 work_list using "work_list" %}
{% for work in work_list %}

View File

@ -24,6 +24,17 @@
<!--<li><a href="{% url work_list 'recommended' %}"><span>Noteworthy</span></a></li>-->
<li><a href="{% url unglued_list '' %}"><span>Ready to Read</span></a></li>
<li class="last"><a href="{% url cc_list%}">Latest Creative Commons</a></li>
{% ifequal aspect 'cc' %}
<ul class="menu level3">
<li class="first"><a href="{% url cc_list_detail 'by' %}"><span{% ifequal facet 'by' %} style="font-weight: bold;"{% endifequal %}>CC BY</span></a></li>
<li><a href="{% url cc_list_detail 'by-nc-nd' %}"><span{% ifequal facet 'by-nc-nd' %} style="font-weight: bold;"{% endifequal %}>CC BY-NC-ND</span></a></li>
<li><a href="{% url cc_list_detail 'by-nc-sa' %}"><span{% ifequal facet 'by-nc-sa' %} style="font-weight: bold;"{% endifequal %}>CC BY-NC-SA</span></a></li>
<li><a href="{% url cc_list_detail 'by-nc' %}"><span{% ifequal facet 'by-nc' %} style="font-weight: bold;"{% endifequal %}>CC BY-NC</span></a></li>
<li><a href="{% url cc_list_detail 'by-sa' %}"><span{% ifequal facet 'by-sa' %} style="font-weight: bold;"{% endifequal %}>CC BY-SA</span></a></li>
<li><a href="{% url cc_list_detail 'by-nd' %}"><span{% ifequal facet 'by-nd' %} style="font-weight: bold;"{% endifequal %}>CC BY-ND</span></a></li>
<li><a href="{% url cc_list_detail 'cc0' %}"><span{% ifequal facet 'cc0' %} style="font-weight: bold;"{% endifequal %}>CC0</span></a></li>
</ul>
{% endifequal %}
{% if pubname %}
<li>{{ pubname }}...
<ul class="menu level3">
@ -37,7 +48,7 @@
{% if show_langs %}
<li class="parent">
<span class="show_langs">Languages...</span>
<ul class="menu level2" id="lang_list">
<ul class="menu level3" id="lang_list">
<li class="first{% ifequal pub_lang '' %} active_lang{% endifequal %}"><a href="?">ALL</a></li>
{% for wished_lang in WISHED_LANGS %}
<li{% ifequal pub_lang wished_lang %} class="active_lang"{% endifequal %}><a href="?pub_lang={{wished_lang}}">{{wished_lang|ez_lang_name_local}}</a></li>

View File

@ -88,6 +88,10 @@ class PageTests(TestCase):
self.assertEqual(r.status_code, 200)
r = anon_client.get("/marc/")
self.assertEqual(r.status_code, 200)
r = anon_client.get("/creativecommons/")
self.assertEqual(r.status_code, 200)
r = anon_client.get("/creativecommons/by")
self.assertEqual(r.status_code, 200)
class GoogleBooksTest(TestCase):

View File

@ -78,6 +78,7 @@ urlpatterns = patterns(
url(r"^bypub/(?P<facet>\w*)/(?P<pubname>.*)$", ByPubListView.as_view(), name='bypub_list'),
url(r"^unglued/(?P<facet>\w*)$", UngluedListView.as_view(), name='unglued_list'),
url(r"^creativecommons/$", CCListView.as_view(), name='cc_list'),
url(r"^creativecommons/(?P<facet>[\w\-]*)$", CCListView.as_view(), name='cc_list_detail'),
url(r"^goodreads/auth/$", "goodreads_auth", name="goodreads_auth"),
url(r"^goodreads/auth_cb/$", "goodreads_cb", name="goodreads_cb"),
url(r"^goodreads/flush/$","goodreads_flush_assoc", name="goodreads_flush_assoc"),

View File

@ -71,6 +71,7 @@ from regluit.core import (
goodreads,
ungluify_record
)
import regluit.core.cc as cc
from regluit.core.bookloader import merge_works, detach_edition
from regluit.core.goodreads import GoodreadsClient
from regluit.core.search import gluejar_search
@ -231,7 +232,7 @@ def home(request, landing=False):
cc_books = models.Work.objects.filter(
editions__ebooks__isnull=False,
editions__ebooks__rights__in=['CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA']
editions__ebooks__rights__in=cc.LICENSE_LIST
).distinct().order_by('-created')[:4]
"""
@ -875,17 +876,37 @@ class ByPubListView(ByPubView):
class CCListView(FilterableListView):
template_name = "cc_list.html"
context_object_name = "work_list"
licenses = cc.LICENSE_LIST
facets = cc.FACET_LIST
def get_queryset_all(self):
return models.Work.objects.filter(
facet = self.kwargs.get('facet','')
if facet in self.facets:
ccworks = models.Work.objects.filter(
editions__ebooks__isnull=False,
editions__ebooks__rights__in=['CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA']
).distinct().order_by('-created')
editions__ebooks__rights=self.licenses[self.facets.index(facet)]
)
notyet = models.Work.objects.filter(
campaigns__status="ACTIVE",
campaigns__license=self.licenses[self.facets.index(facet)]
)
return (notyet | ccworks).distinct().order_by('-created')
else:
return models.Work.objects.filter( editions__ebooks__isnull=False,
editions__ebooks__rights__in=self.licenses
).distinct().order_by('-created')
def get_context_data(self, **kwargs):
context = super(CCListView, self).get_context_data(**kwargs)
facet = self.kwargs.get('facet','')
qs=self.get_queryset()
context['ungluers'] = userlists.work_list_users(qs,5)
context['activetab'] = "#1"
context['tab_override'] = 'tabs-1'
context['facet'] = facet
context['aspect'] = 'cc'
context['license'] = self.licenses[self.facets.index(facet)] if facet in self.facets else ''
context['cc'] = cc.ccinfo(context['license'])
return context
class UngluedListView(FilterableListView):
@ -900,7 +921,7 @@ class UngluedListView(FilterableListView):
# assumes all ebooks have a PD or CC license. compare rights_badge property
return models.Work.objects.filter(
editions__ebooks__isnull=False,
editions__ebooks__rights__in=['CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA']
editions__ebooks__rights__in=cc.LICENSE_LIST
).exclude(campaigns__status="SUCCESSFUL").distinct().order_by('-num_wishes')
elif (facet == 'pd' or facet == 'publicdomain'):
return models.Work.objects.filter(

View File

@ -369,32 +369,6 @@ AWS_QUERYSTRING_AUTH = False
MAILCHIMP_API_KEY = '5f8e846a2bbc847807ed89086de4b4bf-us2'
MAILCHIMP_NEWS_ID = u'c5cce92fe1'
# let's be DRY with these parameters
# CCHOICES, CCGRANTS, and FORMATS are all used in places that expect tuples
# CONTENT_TYPES will be easiest to manipulate in ungluify_record as a dict
CCCHOICES = (
('CC BY','Creative Commons Attribution 3.0 Unported (CC BY 3.0)'),
('CC BY-SA','Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)'),
('CC BY-NC','Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)'),
('CC BY-NC-SA','Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)'),
('CC BY-NC-ND','Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY-NC-ND 3.0)'),
('CC BY-ND','Creative Commons Attribution-NoDerivs 3.0 Unported (CC BY-ND 3.0)'),
('CC0','No Rights Reserved (CC0)'),
)
CHOICES = CCCHOICES + (('PD-US', 'Public Domain, US'),)
CCGRANTS = (
('CC BY', 'http://creativecommons.org/licenses/by/3.0/'),
('CC BY-SA', 'http://creativecommons.org/licenses/by-sa/3.0/'),
('CC BY-NC', 'http://creativecommons.org/licenses/by-nc/3.0/'),
('CC BY-NC-SA', 'http://creativecommons.org/licenses/by-nc-sa/3.0/'),
('CC BY-NC-ND', 'http://creativecommons.org/licenses/by-nc-nd/3.0/'),
('CC BY-ND', 'http://creativecommons.org/licenses/by-nd/3.0/'),
('CC0', 'http://creativecommons.org/about/cc0'),
)
GRANTS = CCGRANTS + (('PD-US', ''),)
FORMATS = (
('pdf','PDF'),
('epub','EPUB'),

File diff suppressed because one or more lines are too long

View File

@ -621,6 +621,9 @@ a#readon {
.height(30px);
}
}
&.level3 li {
.utilitylinks(0px, 20px);
}
}
}