Skip to content

Commit

Permalink
Added query to get a list of available languages and count
Browse files Browse the repository at this point in the history
  • Loading branch information
hackthehackerman committed May 19, 2016
1 parent f4522c5 commit c2e8ad9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cnxarchive/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def _read_sql_file(name):
return fp.read()

SQL = {
'get-available-languages-and-count': _read_sql_file(
'get-available-languages-and-count'),
'get-module': _read_sql_file('get-module'),
'get-content-from-legacy-id': _read_sql_file('get-content-from-legacy-id'),
'get-content-from-legacy-id-ver': _read_sql_file(
Expand Down
11 changes: 11 additions & 0 deletions cnxarchive/sql/get-available-languages-and-count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- ###
-- Copyright (c) 2016, 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: N/A
SELECT language, count(language)
FROM latest_modules
group by language;
1 change: 1 addition & 0 deletions cnxarchive/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,7 @@ def test_extras(self, cursor):
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'languages_and_count': [[u'da', 1], [u'en', 17]],
u'licenses': [{u'code': u'by',
u'isValidForPublication': False,
u'name': u'Creative Commons Attribution License',
Expand Down
8 changes: 8 additions & 0 deletions cnxarchive/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ def _get_subject_list(cursor):
yield subject


def _get_available_languages_and_count(cursor):
"""Return a list of available language and its count"""
cursor.execute(SQL['get-available-languages-and-count'])
return cursor.fetchall()


def _get_featured_links(cursor):
"""Return featured books for the front page."""
cursor.execute(SQL['get-featured-links'])
Expand Down Expand Up @@ -881,6 +887,8 @@ def extras(request):
with psycopg2.connect(settings[config.CONNECTION_STRING]) as db_connection:
with db_connection.cursor() as cursor:
metadata = {
'languages_and_count': _get_available_languages_and_count(
cursor),
'subjects': list(_get_subject_list(cursor)),
'featuredLinks': _get_featured_links(cursor),
'messages': _get_service_state_messages(cursor),
Expand Down

0 comments on commit c2e8ad9

Please sign in to comment.