diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 91e0889e9..bdd1b636d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,28 +1,12 @@ before_script: tests: + stage: test script: - - git submodule init - - git submodule update - virtualenv-3.4 env - source env/bin/activate - - cd src - - XDG_CACHE_HOME=/cache pip3 install -r requirements.txt -r requirements/dev.txt -r requirements/py34.txt - - flake8 --ignore=E123,F403,F401,N802,C901,W503 . - - isort -c -rc . - - python3 manage.py check - - make - - make compress - - coverage run -m py.test tests + - pip install -U pip wheel setuptools + - XDG_CACHE_HOME=/cache bash .travis.sh style + - XDG_CACHE_HOME=/cache bash .travis.sh tests + - XDG_CACHE_HOME=/cache bash .travis.sh doctests tags: - python3 - - selenium -build: - type: deploy - script: - - cd deployment/docker/standalone/ - - docker login -u ciuser -p $DOCKERPW -e admin@rami.io docker.rami.io - - docker build -t pretix/standalone . - - docker tag -f pretix/standalone docker.rami.io/pretix/standalone:$CI_BUILD_REF_NAME - - docker push docker.rami.io/pretix/standalone:$CI_BUILD_REF_NAME - tags: - - docker diff --git a/.travis.sh b/.travis.sh new file mode 100755 index 000000000..dd794e8cd --- /dev/null +++ b/.travis.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e +set -x + +echo "Executing job $1" + +if [ "$1" == "style" ]; then + XDG_CACHE_HOME=/cache pip3 install -Ur src/requirements.txt -r src/requirements/dev.txt -r src/requirements/py34.txt + cd src + flake8 --ignore=E123,F403,F401,N802,C901,W503,E402 . + isort -c -rc . +fi +if [ "$1" == "doctests" ]; then + XDG_CACHE_HOME=/cache pip3 install -Ur doc/requirements.txt -r src/requirements/py34.txt + cd doc + make doctest +fi +if [ "$1" == "tests" ]; then + pip3 install -r src/requirements.txt -Ur src/requirements/dev.txt -r src/requirements/py34.txt + cd src + python manage.py check + make all compress + coverage run -m py.test tests && coverage report +fi +if [ "$1" == "tests-cov" ]; then + pip3 install -r src/requirements.txt -Ur src/requirements/dev.txt -r src/requirements/py34.txt + cd src + python manage.py check + make all compress + coverage run -m py.test tests && coveralls +fi diff --git a/.travis.yml b/.travis.yml index a81ef4c38..a2f7709a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,18 +4,12 @@ python: - "3.4" install: - pip install -U pip wheel setuptools - - pip install -q -U -r src/requirements.txt -r src/requirements/dev.txt -r src/requirements/py34.txt -before_script: - - cd src script: - - flake8 --ignore=E123,F403,F401,N802,C901,W503,E402 . - - isort -c -rc . - - python manage.py check - - make - - make compress - - coverage run -m py.test tests -after_success: - - coveralls + - bash .travis.sh $JOB cache: directories: - $HOME/.cache/pip +env: + - JOB=style + - JOB=doctests + - JOB=tests-cov diff --git a/doc/development/implementation/i18n.rst b/doc/development/implementation/i18n.rst index b8dad84bd..7bc7ba1a8 100644 --- a/doc/development/implementation/i18n.rst +++ b/doc/development/implementation/i18n.rst @@ -29,6 +29,73 @@ Whenever you interact with those fields, you will either provide or receive an i .. autoclass:: pretix.base.i18n.LazyI18nString :members: __init__, localize, __str__ +Usage +----- + +The following examples are given to illustrate how you can work with ``LazyI18nString``. + +.. testsetup:: * + + from pretix.base.i18n import LazyI18nString, language + +To create a LazyI18nString, we can cast a simple string: + +.. doctest:: + + >>> naive = LazyI18nString('Naive untranslated string') + >>> naive + + +Or we can provide a dictionary with multiple translations: + +.. doctest:: + + >>> translated = LazyI18nString({'en': 'English String', 'de': 'Deutscher String'}) + +We can use ``localize`` to get the string in a specific language: + +.. doctest:: + + >>> translated.localize('de') + 'Deutscher String' + + >>> translated.localize('en') + 'English String' + +If we try a locale that does not exist for the string, we might get a it either in a similar locale or in the system's default language: + +.. doctest:: + + >>> translated.localize('de-AT') + 'Deutscher String' + + >>> translated.localize('zh') + 'English String' + + >>> naive.localize('de') + 'Naive untranslated string' + +If we cast a ``LazyI18nString`` to ``str``, ``localize`` will be called with the currently active language: + +.. doctest:: + + >>> from django.utils import translation + >>> str(translated) + 'English String' + >>> translation.activate('de') + >>> str(translated) + 'Deutscher String' + +You can also use our handy context manager to set the locale temporarily: + +.. doctest:: + + >>> translation.activate('en') + >>> with language('de'): + ... str(translated) + 'Deutscher String' + >>> str(translated) + 'English String' Forms ----- diff --git a/src/requirements/dev.txt b/src/requirements/dev.txt index 42cd1aecb..dcdc1095e 100644 --- a/src/requirements/dev.txt +++ b/src/requirements/dev.txt @@ -7,7 +7,7 @@ pep8-naming flake8 coveralls coverage -pytest +pytest==2.9.* pytest-django isort pytest-mock