diff --git a/arkindex/documents/apps.py b/arkindex/documents/apps.py index a829589430791c506ed7c3a584abe37f97813b12..ad5872afc6428463700cfb2e9884fe49c7405c63 100644 --- a/arkindex/documents/apps.py +++ b/arkindex/documents/apps.py @@ -1,8 +1,28 @@ from django.apps import AppConfig +from django.conf import settings +from django.core.exceptions import ImproperlyConfigured +import os +import pkg_resources +import arkindex class DocumentsConfig(AppConfig): name = 'arkindex.documents' + def _package_version(self, name): + try: + return open(os.path.join(settings.BASE_DIR, '..', 'VERSION')).read() + except (OSError, AttributeError, ImproperlyConfigured) as e: + # File not found or settings module not ready + pass + + try: + return pkg_resources.get_distribution(name).version + except pkg_resources.ResolutionError: + pass + + raise RuntimeError("Could not fetch '{}' version".format(name)) + def ready(self): from arkindex.documents import signals # noqa + arkindex.VERSION = self._package_version('arkindex') diff --git a/arkindex/documents/templatetags/__init__.py b/arkindex/documents/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/arkindex/documents/templatetags/package_version.py b/arkindex/documents/templatetags/package_version.py new file mode 100644 index 0000000000000000000000000000000000000000..f289be880d0afb251fe495712852c02b0c389005 --- /dev/null +++ b/arkindex/documents/templatetags/package_version.py @@ -0,0 +1,9 @@ +from django import template +import arkindex + +register = template.Library() + + +@register.simple_tag +def package_version(): + return arkindex.VERSION diff --git a/arkindex/documents/tests/test_apps.py b/arkindex/documents/tests/test_apps.py new file mode 100644 index 0000000000000000000000000000000000000000..61896bd0703e9f2e6aa47e3285f2246ea81be5fa --- /dev/null +++ b/arkindex/documents/tests/test_apps.py @@ -0,0 +1,34 @@ +from unittest import TestCase +from unittest.mock import patch, mock_open +from pkg_resources import ResolutionError +import arkindex.documents +from arkindex.documents.apps import DocumentsConfig + + +class TestApps(TestCase): + + @classmethod + def setUpClass(cls): + cls.documents = DocumentsConfig('documents', arkindex.documents) + + def test_package_version_from_file(self): + with patch('arkindex.documents.apps.open', mock_open(read_data='0.42')) as p: + self.assertEqual(self.documents._package_version('something'), '0.42') + self.assertTrue(p.called) + + def test_package_version_from_setuptools(self): + open_mock = patch('arkindex.documents.apps.open').start() + open_mock.side_effect = OSError + with patch('arkindex.documents.apps.pkg_resources.get_distribution') as p: + p().version = '1.3.3.7' + self.assertEqual(self.documents._package_version('something'), '1.3.3.7') + self.assertTrue(open_mock.called) + self.assertTrue(p.called) + + def test_package_version_fail(self): + open_mock = patch('arkindex.documents.apps.open').start() + open_mock.side_effect = OSError + pkg_mock = patch('arkindex.documents.apps.pkg_resources.get_distribution').start() + pkg_mock.side_effect = ResolutionError + with self.assertRaises(RuntimeError): + self.documents._package_version('something') diff --git a/arkindex/project/settings.py b/arkindex/project/settings.py index 8fa49c8687e38cdd33cc8d15b88500cc54c72446..7fbb5911c8bfaaadc1698e7b41caaec708da91c9 100644 --- a/arkindex/project/settings.py +++ b/arkindex/project/settings.py @@ -217,7 +217,7 @@ ELASTIC_SEARCH_HOSTS = [ # The Scroll API is required to go over 10K results ES_RESULTS_LIMIT = 10000 # ES defaults to three items returned in a nested query if the inner_hits size is not defined -ES_INNER_RESULTS_LIMIT = 10 +ES_INNER_RESULTS_LIMIT = 6 ES_INDEX_TRANSCRIPTIONS = 'transcriptions' ES_INDEX_ACTS = 'acts' diff --git a/arkindex/templates/base.html b/arkindex/templates/base.html index eaf90e91257a36003aab745a862395965b78b2cc..b3b45b5b507250449501f9efa20b7c4366ec8260 100644 --- a/arkindex/templates/base.html +++ b/arkindex/templates/base.html @@ -1,3 +1,4 @@ +{% load package_version %} <!DOCTYPE html> <html> <head> @@ -57,7 +58,7 @@ {% if user.is_authenticated %} <div class="navbar-item has-dropdown is-hoverable"> <a class="navbar-link"> - {{ user }} + <i class="icon-user"></i> {{ user }} </a> <div class="navbar-dropdown"> <a href="{% url 'credentials' %}" class="navbar-item">OAuth</a> @@ -77,9 +78,11 @@ </div> </nav> - <div class="container"> + <main class="container"> {% block content %}{% endblock %} - </div> + </main> + + <footer class="footer is-paddingless has-text-right">Version {% package_version %}</footer> {% render_bundle 'main' 'js' %} </body> diff --git a/arkindex/templates/documents/volume.act.html b/arkindex/templates/documents/volume.act.html index 8d26a4d6392b1ba648b8897301207a391988f01a..c0021a4087c76ef55be35129d5f95426392478b5 100644 --- a/arkindex/templates/documents/volume.act.html +++ b/arkindex/templates/documents/volume.act.html @@ -1,9 +1,6 @@ {% extends 'base.html' %} {% block content %} -<h1 class="title">Acts in volume {{ volume.name }}</h1> -<h2 class="subtitle">View all acts inside a volume</h2> - <div id="app"> <Volume-Acts id="{{ volume.id }}" /> </div>