Skip to content

Commit

Permalink
Merge pull request #266 from Connexions/featured-links-2
Browse files Browse the repository at this point in the history
Add featured tags and return featured books in extras API
  • Loading branch information
reedstrm committed Oct 8, 2014
2 parents 8c540e2 + 87c419b commit b171e27
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions cnxarchive/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _read_sql_file(name):
'get-tree-by-uuid-n-version': _read_sql_file('get-tree-by-uuid-n-version'),
'get-module-versions': _read_sql_file('get-module-versions'),
'get-subject-list': _read_sql_file('get-subject-list'),
'get-featured-links': _read_sql_file('get-featured-links'),
}


Expand Down
27 changes: 27 additions & 0 deletions cnxarchive/sql/get-featured-links.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- ###
-- Copyright (c) 2014, Rice University
-- This software is subject to the provisions of the GNU Affero General
-- Public License version 3 (AGPLv3).
-- See LICENCE.txt for details.
-- ###

-- arguments:

SELECT row_to_json(combined_rows) AS featured_links
FROM (SELECT
m.uuid AS id,
concat_ws('.', m.major_version, m.minor_version) AS version,
m.name AS title,
m.moduleid AS legacy_id,
m.version AS legacy_version,
a.html AS abstract,
'/resources/' || f.sha1 AS "resourcePath",
t.tag AS "type"
FROM modules m
LEFT JOIN moduletags mt ON m.module_ident = mt.module_ident
LEFT JOIN tags t ON mt.tagid = t.tagid
LEFT JOIN abstracts a ON m.abstractid = a.abstractid
LEFT JOIN module_files mf ON mf.module_ident = m.module_ident
LEFT JOIN files f ON f.fileid = mf.fileid
WHERE t.scheme = 'featured' AND mf.filename = 'featured-cover.png'
) combined_rows;
2 changes: 1 addition & 1 deletion cnxarchive/sql/get-subject-list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ SELECT t.tagid, t.tag, lm.portal_type, COUNT(lm.module_ident)
FROM moduletags mt
JOIN latest_modules lm ON mt.module_ident = lm.module_ident
RIGHT JOIN tags t ON mt.tagid = t.tagid
WHERE t.scheme != 'internal'
WHERE t.scheme = 'ISKME subject'
GROUP BY t.tagid, lm.portal_type
ORDER BY t.tag;
2 changes: 2 additions & 0 deletions cnxarchive/sql/schema/constant-tags.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ INSERT INTO tags VALUES (3, 'Humanities', 'ISKME subject');
INSERT INTO tags VALUES (4, 'Mathematics and Statistics', 'ISKME subject');
INSERT INTO tags VALUES (5, 'Science and Technology', 'ISKME subject');
INSERT INTO tags VALUES (6, 'Social Sciences', 'ISKME subject');
INSERT INTO tags VALUES (7, 'OpenStax Featured', 'featured');
INSERT INTO tags VALUES (8, 'CNX Featured', 'featured');
5 changes: 4 additions & 1 deletion cnxarchive/tests/data/data.sql

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions cnxarchive/tests/data/search_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@
"count": 2,
"value": "Mathematics and Statistics"
},
{
"count": 1,
"value": "OpenStax Featured"
},
{
"count": 1,
"value": "Science and Technology"
Expand Down
15 changes: 12 additions & 3 deletions cnxarchive/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

COLLECTION_METADATA = {
u'roles': None,
u'subjects': [u'Mathematics and Statistics', u'Science and Technology'],
u'subjects': [u'Mathematics and Statistics', u'Science and Technology', u'OpenStax Featured'],
u'abstract': u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:md="http://cnx.rice.edu/mdml" xmlns:c="http://cnx.rice.edu/cnxml" xmlns:qml="http://cnx.rice.edu/qml/1.0" xmlns:data="http://dev.w3.org/html5/spec/#custom" xmlns:bib="http://bibtexml.sf.net/" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mod="http://cnx.rice.edu/#moduleIds">This introductory, algebra-based, two-semester college physics book is grounded with real-world examples, illustrations, and explanations to help students grasp key, fundamental physics concepts. This online, fully editable and customizable title includes learning objectives, concept questions, links to labs and simulations, and ample practice opportunities to solve traditional physics application problems.</div>',
u'authors': [{u'id': u'e5a07af6-09b9-4b74-aa7a-b7510bee90b8',
u'fullname': u'OpenStax College',
Expand Down Expand Up @@ -1858,8 +1858,17 @@ def test_extras(self):
},
{u'id': 6, u'name': u'Social Sciences',
u'count': {u'module': 0, u'collection': 0},
},
]
}],
u'featuredLinks': [{
u'id': u'e79ffde3-7fb4-4af3-9ec8-df648b391597',
u'title': u'College Physics',
u'version': u'7.1',
u'legacy_id': u'col11406',
u'legacy_version': u'1.7',
u'resourcePath': u'/resources/6214e8dcdf2824dbf830b4a0d77a3fa2f53608d2',
u'type': u'OpenStax Featured',
u'abstract': u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:md="http://cnx.rice.edu/mdml" xmlns:c="http://cnx.rice.edu/cnxml" xmlns:qml="http://cnx.rice.edu/qml/1.0" xmlns:data="http://dev.w3.org/html5/spec/#custom" xmlns:bib="http://bibtexml.sf.net/" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mod="http://cnx.rice.edu/#moduleIds">This introductory, algebra-based, two-semester college physics book is grounded with real-world examples, illustrations, and explanations to help students grasp key, fundamental physics concepts. This online, fully editable and customizable title includes learning objectives, concept questions, links to labs and simulations, and ample practice opportunities to solve traditional physics application problems.</div>',
}],
})


Expand Down
9 changes: 8 additions & 1 deletion cnxarchive/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,20 @@ def _get_subject_list(cursor):
yield subject


def _get_featured_links(cursor):
"""Return featured books for the front page"""
cursor.execute(SQL['get-featured-links'])
return [i[0] for i in cursor.fetchall()]

def extras(environ, start_response):
"""Return a dict with archive metadata for webview
"""
settings = get_settings()
with psycopg2.connect(settings[config.CONNECTION_STRING]) as db_connection:
with db_connection.cursor() as cursor:
metadata = {'subjects': list(_get_subject_list(cursor)),
metadata = {
'subjects': list(_get_subject_list(cursor)),
'featuredLinks': _get_featured_links(cursor),
}

status = '200 OK'
Expand Down

0 comments on commit b171e27

Please sign in to comment.