factor license URL and badge into one class [#29884981]

pull/1/head
eric 2012-05-20 00:10:56 -04:00
parent 62c1d80547
commit f72796acdf
1 changed files with 64 additions and 33 deletions

View File

@ -112,8 +112,9 @@ class CampaignAction(models.Model):
comment = models.TextField(null=True, blank=True) comment = models.TextField(null=True, blank=True)
campaign = models.ForeignKey("Campaign", related_name="actions", null=False) campaign = models.ForeignKey("Campaign", related_name="actions", null=False)
class Campaign(models.Model): class CCLicense():
LICENSE_CHOICES = (('CC BY-NC-ND','CC BY-NC-ND'), CCCHOICES = (
('CC BY-NC-ND','CC BY-NC-ND'),
('CC BY-ND','CC BY-ND'), ('CC BY-ND','CC BY-ND'),
('CC BY','CC BY'), ('CC BY','CC BY'),
('CC BY-NC','CC BY-NC'), ('CC BY-NC','CC BY-NC'),
@ -121,6 +122,53 @@ class Campaign(models.Model):
( 'CC BY-SA','CC BY-SA'), ( 'CC BY-SA','CC BY-SA'),
( 'CC0','CC0'), ( 'CC0','CC0'),
) )
CHOICES = CCCHOICES+(('PD-US', 'Public Domain, US'),)
@classmethod
def url(klass, 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 ''
@classmethod
def badge(klass,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 Campaign(models.Model):
LICENSE_CHOICES = CCLicense.CCCHOICES
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=500, null=True, blank=False) name = models.CharField(max_length=500, null=True, blank=False)
description = models.TextField(null=True, blank=False) description = models.TextField(null=True, blank=False)
@ -277,6 +325,15 @@ class Campaign(models.Model):
pass pass
return '' return ''
@property
def license_url(self):
return CCLicense.url(self.license)
@property
def license_badge(self):
return CCLicense.badge(self.license)
class Identifier(models.Model): class Identifier(models.Model):
# olib, ltwk, goog, gdrd, thng, isbn, oclc, olwk, olib, gute, glue # olib, ltwk, goog, gdrd, thng, isbn, oclc, olwk, olib, gute, glue
type = models.CharField(max_length=4, null=False) type = models.CharField(max_length=4, null=False)
@ -610,15 +667,7 @@ class WasWork(models.Model):
class Ebook(models.Model): class Ebook(models.Model):
FORMAT_CHOICES = (('pdf','PDF'),( 'epub','EPUB'), ('html','HTML'), ('text','TEXT'), ('mobi','MOBI')) FORMAT_CHOICES = (('pdf','PDF'),( 'epub','EPUB'), ('html','HTML'), ('text','TEXT'), ('mobi','MOBI'))
RIGHTS_CHOICES = (('PD-US', 'Public Domain, US'), RIGHTS_CHOICES = CCLicense.CHOICES
('CC BY-NC-ND','CC BY-NC-ND'),
('CC BY-ND','CC BY-ND'),
('CC BY','CC BY'),
('CC BY-NC','CC BY-NC'),
( 'CC BY-NC-SA','CC BY-NC-SA'),
( 'CC BY-SA','CC BY-SA'),
( 'CC0','CC0'),
)
url = models.URLField(max_length=1024) url = models.URLField(max_length=1024)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
format = models.CharField(max_length=25, choices = FORMAT_CHOICES) format = models.CharField(max_length=25, choices = FORMAT_CHOICES)
@ -635,27 +684,9 @@ class Ebook(models.Model):
@property @property
def rights_badge(self): def rights_badge(self):
my_rights=self.rights if self.rights is None :
if not my_rights: return CCLicense.badge('PD-US')
return 'https://i.creativecommons.org/p/mark/1.0/88x31.png' return CCLicense.badge(self.rights)
if my_rights == 'PD-US':
return 'https://i.creativecommons.org/p/mark/1.0/88x31.png'
elif my_rights == 'CC0':
return 'https://i.creativecommons.org/p/zero/1.0/88x31.png'
elif my_rights == 'CC BY':
return 'https://i.creativecommons.org/l/by/3.0/88x31.png'
elif my_rights == 'CC BY-NC-ND':
return 'https://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png'
elif my_rights == 'CC BY-NC-SA':
return 'https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png'
elif my_rights == 'CC BY-NC':
return 'https://i.creativecommons.org/l/by-nc/3.0/88x31.png'
elif my_rights == 'CC BY-SA':
return 'https://i.creativecommons.org/l/by-sa/3.0/88x31.png'
elif my_rights == 'CC BY-ND':
return 'https://i.creativecommons.org/l/by-nd/3.0/88x31.png'
else:
return ''
@classmethod @classmethod
def infer_provider(klass, url): def infer_provider(klass, url):