Skip to content
Snippets Groups Projects
Commit 332400d6 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Display version number

See merge request !106
parents e5af9020 3f4fe56d
No related branches found
No related tags found
1 merge request!106Frontend edits
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')
from django import template
import arkindex
register = template.Library()
@register.simple_tag
def package_version():
return arkindex.VERSION
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')
......@@ -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'
......
{% 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>
......
{% 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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment