Skip to content

Commit

Permalink
Merge branch 'dev' into fix4862
Browse files Browse the repository at this point in the history
  • Loading branch information
artragis committed May 24, 2018
2 parents 7ab83c9 + 751d993 commit 3c755a9
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ base.db
/contents-public
/media
/articles-data
/zds/_version.py

/tutoriels-private-test
/tutoriels-public-test
Expand Down
7 changes: 6 additions & 1 deletion templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<p class="copyright">
{{app.site.literal_name}}
<span class="version">
&bull; {% trans "Version :" %} <a href="{{git_version.url}}">{{git_version.name}}</a>
&bull; {% trans "Version :" %}
{% if zds_version.url %}
<a href="{{zds_version.url}}">{{zds_version.name}}</a>
{% else %}
{{ zds_version.name }}
{% endif %}
</span>
</p>

Expand Down
14 changes: 14 additions & 0 deletions zds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@
import logging
logging.debug('json is loaded, module is %s', json_handler.__name__) # this allows to know which one we loaded
# and avoid pep8 warning.

# Try to load the version informations from `zds/_version.py` and fallback to
# a default `dev` version.
#
# `zds/_version.py` should look like this:
#
# __version__ = 'v27-foo'
# git_version = '444c8f11acc921ef97c6971fc30bd91c383a3fea'
#
try:
from ._version import __version__, git_version
except ImportError:
__version__ = 'dev'
git_version = None
4 changes: 2 additions & 2 deletions zds/pages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ def test_url_cookies(self):
self.assertEqual(result.status_code, 200)

def test_render_template(self):
"""Test: render_template() works and git_version is in template."""
"""Test: render_template() works and version is in template."""

result = self.client.get(
reverse('homepage'),
)

self.assertTrue('git_version' in result.context)
self.assertTrue('zds_version' in result.context)


class CommentEditsHistoryTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion zds/settings/abstract_base/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
'social.apps.django_app.context_processors.login_redirect',
# ZDS context processors
'zds.utils.context_processor.app_settings',
'zds.utils.context_processor.git_version',
'zds.utils.context_processor.version',
],
},
}
Expand Down
15 changes: 11 additions & 4 deletions zds/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from zds.utils.context_processor import get_git_version

from .abstract_base import *

# For secrets, prefer `config[key]` over `config.get(key)` in this
Expand Down Expand Up @@ -76,11 +74,20 @@
]),
]


def _get_version():
from zds import __version__, git_version
if git_version is None:
return __version__
else:
return '{0}/{1}'.format(__version__, git_version[:7])


# Sentry (+ raven, the Python Client)
# https://docs.getsentry.com/hosted/clients/python/integrations/django/
RAVEN_CONFIG = {
'dsn': config['raven']['dsn'],
'release': get_git_version()['name'],
'release': _get_version(),
}

LOGGING = {
Expand Down Expand Up @@ -189,7 +196,7 @@
# ZESTE DE SAVOIR SETTINGS


ES_SEARCH_INDEX['shards'] = config['elasticsearch'].get('shards', 3),
ES_SEARCH_INDEX['shards'] = config['elasticsearch'].get('shards', 3)


ZDS_APP['site']['association']['email'] = 'communication@zestedesavoir.com'
Expand Down
6 changes: 5 additions & 1 deletion zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def test_ensure_access(self):
reverse('content:view', args=[tuto.pk, tuto.slug]),
follow=False)
self.assertEqual(result.status_code, 200)

self.assertIn(reverse('content:edit-container', kwargs={
'pk': tuto.pk,
'slug': tuto.slug,
'container_slug': self.part1.slug
}), result.content.decode('utf-8'))
result = self.client.get(
reverse('content:view-container',
kwargs={
Expand Down
46 changes: 12 additions & 34 deletions zds/utils/context_processor.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
from copy import deepcopy

from django.conf import settings
from django.core.cache import cache

from git import Repo
from zds import __version__, git_version


def get_git_version():
def get_version():
"""
Get Git version information.
Since retrieving the Git version can be rather slow (due to I/O on
the filesystem and, most importantly, forced garbage collections
triggered by GitPython), you must consider using
``get_cached_git_version()`` (which behaves similarly).
"""
try:
repo = Repo(settings.BASE_DIR)
branch = repo.active_branch
commit = repo.head.commit.hexsha
name = '{0}/{1}'.format(branch, commit[:7])
return {'name': name, 'url': '{}/tree/{}'.format(settings.ZDS_APP['site']['repository']['url'], commit)}
except (KeyError, TypeError):
return {'name': '', 'url': ''}


def get_cached_git_version():
"""
Get Git version information.
Same as ``get_git_version()``, but cached with a simple timeout of
one hour.
Retrieve version informations from `zds/_version.py`.
"""
version = cache.get('git_version')
if version is None:
version = get_git_version()
cache.set('git_version', version, 60 * 60)
return version
if git_version is not None:
name = '{0}/{1}'.format(__version__, git_version[:7])
url = settings.ZDS_APP['site']['repository']['url']
return {'name': name, 'url': '{}/tree/{}'.format(url, git_version)}
else:
return {'name': __version__, 'url': None}


def git_version(request):
def version(request):
"""
A context processor to include the git version on all pages.
A context processor to include the app version on all pages.
"""
return {'git_version': get_cached_git_version()}
return {'zds_version': get_version()}


def app_settings(request):
Expand Down

0 comments on commit 3c755a9

Please sign in to comment.