Beispiel #1
0
def switch(cxt, name, locales=None):
    """A template helper that replaces waffle

    * All calls default to True when DEV setting is True (for the listed locales).
    * If the env var is explicitly false it will be false even when DEV = True.
    * Otherwise the call is False by default and True is a specific env var exists and is truthy.

    For example:

        {% if switch('dude-and-walter') %}

    would check for an environment variable called `SWITCH_DUDE_AND_WALTER`. The string from the
    `switch()` call is converted to uppercase and dashes replaced with underscores.

    If the `locales` argument is a list of locales then it will only check the switch in those
    locales, and return False otherwise. The `locales` argument could also contain a "locale group",
    which is a list of locales for a prefix (e.g. "en" expands to "en-US, en-GB, en-ZA").
    """
    if locales:
        if cxt['LANG'] not in expand_locale_groups(locales):
            return False

    return waffle.switch(name)
Beispiel #2
0
def switch(cxt, name, locales=None):
    """A template helper that replaces waffle

    * All calls default to True when DEV setting is True (for the listed locales).
    * If the env var is explicitly false it will be false even when DEV = True.
    * Otherwise the call is False by default and True is a specific env var exists and is truthy.

    For example:

        {% if switch('dude-and-walter') %}

    would check for an environment variable called `SWITCH_DUDE_AND_WALTER`. The string from the
    `switch()` call is converted to uppercase and dashes replaced with underscores.

    If the `locales` argument is a list of locales then it will only check the switch in those
    locales, and return False otherwise. The `locales` argument could also contain a "locale group",
    which is a list of locales for a prefix (e.g. "en" expands to "en-US, en-GB, en-ZA").
    """
    if locales:
        if cxt['LANG'] not in expand_locale_groups(locales):
            return False

    return waffle.switch(name)
Beispiel #3
0
 def _all_variation_locales(self):
     return expand_locale_groups(self.variation_locales)
Beispiel #4
0
def test_expand_locale_groups():
    assert expand_locale_groups(["de", "fr", "en-GB"]) == ["de", "fr", "en-GB"]
    assert expand_locale_groups(["de", "fr",
                                 "en"]) == ["de", "fr", "en-US", "en-GB"]
    assert expand_locale_groups(["en"]) == ["en-US", "en-GB"]
Beispiel #5
0
def test_expand_locale_groups():
    assert expand_locale_groups(['de', 'fr', 'en-GB']) == ['de', 'fr', 'en-GB']
    assert expand_locale_groups(['de', 'fr',
                                 'en']) == ['de', 'fr', 'en-US', 'en-GB']
    assert expand_locale_groups(['en']) == ['en-US', 'en-GB']
Beispiel #6
0
def test_expand_locale_groups():
    assert expand_locale_groups(['de', 'fr', 'en-GB']) == ['de', 'fr', 'en-GB']
    assert expand_locale_groups(['de', 'fr', 'en']) == ['de', 'fr', 'en-US', 'en-GB']
    assert expand_locale_groups(['en']) == ['en-US', 'en-GB']