diff --git a/core/facets.py b/core/facets.py index bde8116d..bb959112 100644 --- a/core/facets.py +++ b/core/facets.py @@ -86,8 +86,10 @@ class BaseFacet(object): class FacetGroup(object): # a FacetGroup should implement title, facets, has_facet(self, facet_name) and get_facet_class(self, facet_name) + def has_facet(self, facet_name): return facet_name in self.facets + def get_facets(self): for facet_name in self.facets: yield self.get_facet_class(facet_name)(None) @@ -104,7 +106,7 @@ class FormatFacetGroup(FacetGroup): super(FacetGroup,self).__init__() self.title = 'Format' self.facets = ['pdf', 'epub', 'mobi'] - + self.label = '{} is ...'.format(self.title) def get_facet_class(self, facet_name): class FormatFacet(NamedFacet): @@ -126,6 +128,37 @@ class FormatFacetGroup(FacetGroup): def description(self): return "These eBooks available in %s format." % self.facet_name return FormatFacet + +idtitles = {'doab': 'indexed in DOAB', 'gtbg':'available in Project Gutenberg'} +idlabels = {'doab': 'DOAB', 'gtbg':'Project Gutenberg'} +class IdFacetGroup(FacetGroup): + def __init__(self): + super(FacetGroup,self).__init__() + self.title = 'Collection' + self.facets = idtitles.keys() + self.label = 'Included in ...' + + def get_facet_class(self, facet_name): + class IdFacet(NamedFacet): + def set_name(self): + self.facet_name=facet_name + def id_filter(query_set): + return query_set.filter(identifiers__type=facet_name) + model_filters = {} + def get_query_set(self): + return self._get_query_set().filter(identifiers__type=self.facet_name) + def template(self): + return 'facets/id.html' + @property + def label(self): + return idlabels[self.facet_name] + @property + def title(self): + return idtitles[self.facet_name] + @property + def description(self): + return "These eBooks are {}.".format(idtitles[self.facet_name]) + return IdFacet class LicenseFacetGroup(FacetGroup): @@ -134,6 +167,7 @@ class LicenseFacetGroup(FacetGroup): self.title = 'License' self.licenses = cc.LICENSE_LIST_ALL self.facets = cc.FACET_LIST + self.label = '{} is ...'.format(self.title) def get_facet_class(self, facet_name): @@ -175,6 +209,7 @@ class KeywordFacetGroup(FacetGroup): self.title = 'Keyword' # make facets in TOPKW available for display self.facets = [('kw.%s' % kw) for kw in TOPKW] + self.label = '{} is ...'.format(self.title) def has_facet(self, facet_name): @@ -209,7 +244,8 @@ class PublisherFacetGroup(FacetGroup): self.title = 'Publisher' # don't display facets self.facets = [] - + self.label = 'Published by ...' + def has_facet(self, facet_name): # recognize any facet_name that starts with "pub." as a valid facet name @@ -249,7 +285,7 @@ class PublisherFacetGroup(FacetGroup): return PublisherFacet # order of groups in facet_groups determines order of display on /free/ -facet_groups = [KeywordFacetGroup(), FormatFacetGroup(), LicenseFacetGroup(), PublisherFacetGroup()] +facet_groups = [KeywordFacetGroup(), FormatFacetGroup(), LicenseFacetGroup(), PublisherFacetGroup(), IdFacetGroup()] def get_facet(facet_name): for facet_group in facet_groups: diff --git a/core/models/bibmodels.py b/core/models/bibmodels.py index a758fdea..fe8e6c7b 100644 --- a/core/models/bibmodels.py +++ b/core/models/bibmodels.py @@ -45,9 +45,17 @@ from regluit.core.parameters import ( logger = logging.getLogger(__name__) good_providers = ('Internet Archive', 'Unglue.it', 'Github', 'OAPEN Library') +def id_for(obj, type): + if not obj.pk: + return '' + try: + return obj.identifiers.filter(type=type)[0].value + except IndexError: + return '' + class Identifier(models.Model): - # olib, ltwk, goog, gdrd, thng, isbn, oclc, olwk, doab, gute, glue, doi + # olib, ltwk, goog, gdrd, thng, isbn, oclc, olwk, doab, gtbg, glue, doi type = models.CharField(max_length=4, null=False) value = models.CharField(max_length=250, null=False) work = models.ForeignKey("Work", related_name="identifiers", null=False) @@ -110,6 +118,17 @@ class Work(models.Model): def __init__(self, *args, **kwargs): self._last_campaign = None super(Work, self).__init__(*args, **kwargs) + + def id_for(self, type): + return id_for(self, type) + + @property + def gtbg(self): + return id_for(self, 'gtbg') + + @property + def doab(self): + return id_for(self, 'doab') @property def googlebooks_id(self): @@ -149,10 +168,7 @@ class Work(models.Model): @property def librarything_id(self): - try: - return self.identifiers.filter(type='ltwk')[0].value - except IndexError: - return '' + return self.id_for('ltwk') @property def librarything_url(self): @@ -160,10 +176,7 @@ class Work(models.Model): @property def openlibrary_id(self): - try: - return self.identifiers.filter(type='olwk')[0].value - except IndexError: - return '' + return self.id_for('olwk') @property def openlibrary_url(self): @@ -820,12 +833,7 @@ class Edition(models.Model): return regluit.core.isbn.convert_13_to_10(self.isbn_13) def id_for(self, type): - if not self.pk: - return '' - try: - return self.identifiers.filter(type=type)[0].value - except IndexError: - return '' + return id_for(self, type) @property def isbn_13(self): diff --git a/frontend/templates/facets/id.html b/frontend/templates/facets/id.html new file mode 100644 index 00000000..65307609 --- /dev/null +++ b/frontend/templates/facets/id.html @@ -0,0 +1,11 @@ +
+

+ {{ facet.facet_name }} + {% if facet.facet_name == 'gtbg' %} + These books are included in Project Gutenberg. They are archived and can be improved at GITenberg. + {% endif %} + {% if facet.facet_name == 'doab' %} + These books are included in the Directory of Open Access Books. This means that they have been peer-reviewed and are of interest to scholars. + {% endif %} +

+
\ No newline at end of file diff --git a/frontend/templates/refine.html b/frontend/templates/refine.html index b346189f..c049890b 100644 --- a/frontend/templates/refine.html +++ b/frontend/templates/refine.html @@ -9,7 +9,7 @@ {% for group in vertex.get_other_groups %} diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 450f9898..c037bd96 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -289,6 +289,16 @@ {{ work_rel.to_work }} is a {{ work_rel.relation }} of this work.

{% endfor %} + {% if work.doab %} +

+ This book is included in DOAB. +

+ {% endif %} + {% if work.gtbg %} +

+ This book is included in Project Gutenberg. +

+ {% endif %} diff --git a/static/images/doab.png b/static/images/doab.png new file mode 100644 index 00000000..d72c2c22 Binary files /dev/null and b/static/images/doab.png differ diff --git a/static/images/doab32.png b/static/images/doab32.png new file mode 100644 index 00000000..00b7a0e0 Binary files /dev/null and b/static/images/doab32.png differ diff --git a/static/images/gtbg.png b/static/images/gtbg.png new file mode 100644 index 00000000..ab81b3ea Binary files /dev/null and b/static/images/gtbg.png differ diff --git a/static/images/gtbg32.png b/static/images/gtbg32.png new file mode 100644 index 00000000..0cac9616 Binary files /dev/null and b/static/images/gtbg32.png differ