예제 #1
0
파일: views.py 프로젝트: Soundug/bedrock
    def render_to_response(self, context, **response_kwargs):
        # set experimental percentages per locale with this config
        # e.g. EXP_CONFIG_FX_NEW=de:20,en-US:10,fr:25
        # this would send 20% of de, 10% of en-US, and 25% of fr requests to the experiment page
        # all other locales would be unaffected
        redirect_percents = config('EXP_CONFIG_FX_NEW',
                                   default='',
                                   parser=DictOf(int))
        skip_exp = 'automation' in self.request.GET
        # only engage the experiment infra if some experiments are set
        if redirect_percents and not skip_exp:
            locale = l10n_utils.get_locale(self.request)
            percent = redirect_percents.get(locale, 0)
            if percent:
                percent = percent / 100
                print(percent)
                if random() <= percent:
                    exp_url = reverse('exp.firefox.new')
                    query_string = self.request.META.get('QUERY_STRING', '')
                    if query_string:
                        exp_url = '?'.join([
                            exp_url,
                            force_text(query_string, errors='ignore')
                        ])
                    response = HttpResponseRedirect(exp_url)
                else:
                    response = super().render_to_response(
                        context, **response_kwargs)
                # remove cache for better experiment results
                add_never_cache_headers(response)
                return response

        return super().render_to_response(context, **response_kwargs)
예제 #2
0
파일: waffle.py 프로젝트: Delphine/bedrock
def switch(name):
    """A template helper that replaces waffle

    * All calls default to True when DEV setting is True.
    * 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.
    """
    env_name = name.upper().replace('-', '_')
    return config(env_name, default=str(settings.DEV), parser=bool, namespace='SWITCH')
예제 #3
0
def switch(name):
    """A template helper that replaces waffle

    * All calls default to True when DEV setting is True.
    * 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.
    """
    env_name = name.upper().replace('-', '_')
    return config(env_name,
                  default=str(settings.DEV),
                  parser=bool,
                  namespace='SWITCH')