Skip to content

Commit

Permalink
Merge pull request #2365 from freedomofpress/refactor
Browse files Browse the repository at this point in the history
Source app refactor
  • Loading branch information
redshiftzero authored Sep 27, 2017
2 parents f575185 + dd8dea7 commit e3fea98
Show file tree
Hide file tree
Showing 20 changed files with 562 additions and 482 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ docs: ## Build project documentation in live reload for editing
flake8: ## Validates PEP8 compliance for Python source files.
flake8 --exclude='config.py' testinfra securedrop-admin \
securedrop/*.py securedrop/management \
securedrop/source_app/*.py \
securedrop/tests/functional securedrop/tests/*.py

.PHONY: html-lint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@
/var/www/securedrop/i18n.pyc rw,
/var/www/securedrop/source.py r,
/var/www/securedrop/source.pyc rw,
/var/www/securedrop/source_app/__init__.py r,
/var/www/securedrop/source_app/__init__.pyc rw,
/var/www/securedrop/source_app/__pycache__/** rw,
/var/www/securedrop/source_app/api.py r,
/var/www/securedrop/source_app/api.pyc rw,
/var/www/securedrop/source_app/decorators.py r,
/var/www/securedrop/source_app/decorators.pyc rw,
/var/www/securedrop/source_app/info.py r,
/var/www/securedrop/source_app/info.pyc rw,
/var/www/securedrop/source_app/main.py r,
/var/www/securedrop/source_app/main.pyc rw,
/var/www/securedrop/source_app/utils.py r,
/var/www/securedrop/source_app/utils.pyc rw,
/var/www/securedrop/source_templates/banner_warning_flashed.html r,
/var/www/securedrop/source_templates/base.html r,
/var/www/securedrop/source_templates/error.html r,
Expand Down
2 changes: 2 additions & 0 deletions securedrop/.rsync-filter
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include management/
include management/*.py
include requirements/
include requirements/**.txt
include source_app/
include source_app/*.py
include source_templates/
include source_templates/*.html
include static/
Expand Down
14 changes: 13 additions & 1 deletion securedrop/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import os
import re

from os import path

LOCALE_SPLIT = re.compile('(-|_)')
LOCALES = set(['en_US'])
babel = None
Expand All @@ -34,8 +36,18 @@ class LocaleNotFound(Exception):
"""Raised when the desired locale is not in the translations directory"""


def setup_app(app):
def setup_app(app, translation_dirs=None):
global babel

if translation_dirs is None:
translation_dirs = \
path.join(path.dirname(path.realpath(__file__)),
'translations')

# `babel.translation_directories` is a nightmare
# We need to set this manually via an absolute path
app.config['BABEL_TRANSLATION_DIRECTORIES'] = translation_dirs

babel = Babel(app)
assert len(list(babel.translation_directories)) == 1
for dirname in os.listdir(next(babel.translation_directories)):
Expand Down
Loading

0 comments on commit e3fea98

Please sign in to comment.