Exemplo n.º 1
0
def link(request, banner_instance_id):
    """Handle banner link."""
    try:
        instance = (BannerInstance.objects.select_related('badge', 'image')
                    .get(pk=banner_instance_id))
    except BannerInstance.DoesNotExist:
        return HttpResponseRedirect(settings.DEFAULT_AFFILIATE_LINK)

    try:
        tasks.add_click.delay(banner_instance_id)
    except socket.timeout:
        log.warning('Timeout connecting to celery for banner click.')

    # Special redirection for bug 719522
    filename = splitext(basename(instance.image.image.path))[0]
    if filename in settings.BANNERS_HASH:
        user_agent = request.META.get('HTTP_USER_AGENT', '')
        versions_regexp = current_firefox_regexp()
        ua_regexp = r"Firefox/(%s)" % versions_regexp

        # Old Firefoxes go to an update page
        if 'Firefox' in user_agent and not re.search(ua_regexp, user_agent):
            return HttpResponseRedirect(settings.FIREFOX_UPGRADE_REDIRECT)

    return HttpResponseRedirect(instance.badge.href)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        # If there are no special banners to handle, remove the .htaccess.
        if not settings.BANNERS_HASH:
            try:
                os.remove(join(settings.MEDIA_ROOT, '.htaccess'))
            except OSError:
                pass  # File did not exist, this is fine.
        else:
            template = open(join(CURRENT_PATH, 'htaccess.template')).read()
            banners_hash = '|'.join(settings.BANNERS_HASH)
            version_regexp = current_firefox_regexp()
            output = template % (banners_hash, version_regexp)

            with open(join(settings.MEDIA_ROOT, '.htaccess'), 'w') as f:
                f.write(output)