예제 #1
0
파일: views.py 프로젝트: chowse/reporter
def _get_sentiments(request, sentiment):
    sentiments = []
    url = request.get_full_path()

    f = Filter(urlparams(url, s=None), _('All'),  _('All feedback'),
               not sentiment)

    sentiments.append(f)

    f = Filter(urlparams(url, s='happy'), _('Praise'),  _('Praise only'),
               (sentiment == 'happy'))

    sentiments.append(f)

    f = Filter(urlparams(url, s='sad'), _('Issues'),  _('Issues only'),
               (sentiment == 'sad'))

    sentiments.append(f)

    f = Filter(urlparams(url, s='suggestions'), _('Suggestions'),
            _('Suggestions only'),
               (sentiment == 'suggestions'))

    sentiments.append(f)
    return sentiments
예제 #2
0
    def test_urlparams_unicode(self):
        """Make sure urlparams handles unicode well."""

        # Evil unicode
        url = u'/xx?evil=reco\ufffd\ufffd\ufffd\u02f5'
        urlparams(url)  # No error, please

        # Russian string (bug 580629)
        res = urlparams(u'/xx?russian=быстро')
        self.assertEqual(
            res, u'/xx?russian=%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%BE')

        # Polish string (bug 582506)
        res = urlparams(u'/xx?y=obsłudze')
        self.assertEqual(res, u'/xx?y=obs%C5%82udze')
예제 #3
0
    def test_urlparams_unicode(self):
        """Make sure urlparams handles unicode well."""

        # Evil unicode
        url = u'/xx?evil=reco\ufffd\ufffd\ufffd\u02f5'
        urlparams(url)  # No error, please

        # Russian string (bug 580629)
        res = urlparams(u'/xx?russian=быстро')
        self.assertEqual(
            res, u'/xx?russian=%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%BE')

        # Polish string (bug 582506)
        res = urlparams(u'/xx?y=obsłudze')
        self.assertEqual(res, u'/xx?y=obs%C5%82udze')
예제 #4
0
파일: views.py 프로젝트: chowse/reporter
def _get_platforms(request, platform):
    platforms = []
    url = request.get_full_path()

    f = Filter(urlparams(url, p=None), _('All'), _('All Platforms'),
               (not platform))
    platforms.append(f)

    platforms_from_db = (Theme.objects.values_list('platform', flat=True)
                         .distinct().order_by('platform'))

    for p in platforms_from_db:
        f = Filter(urlparams(url, p=p), p, OSES[p].pretty,
                   (platform == p))
        platforms.append(f)

    return platforms
예제 #5
0
파일: views.py 프로젝트: chowse/reporter
def _get_products(request, product):
    products = []
    url = request.get_full_path()

    for app in APP_USAGE:
        f = Filter(urlparams(url, a=app.short), app.pretty, app.pretty,
                   (product == app.short))
        products.append(f)

    return products
예제 #6
0
def _get_products(request, product):
    """Get product filters."""
    products = []
    url = request.get_full_path()

    for prod in PRODUCT_USAGE:
        f = Filter(urlparams(url, a=prod.short), prod.pretty, prod.pretty,
                   (product == prod.short))
        products.append(f)

    return products
예제 #7
0
def _get_platforms(request, product, platform):
    """Get platforms."""
    platforms = []
    url = request.get_full_path()

    f = Filter(urlparams(url, p=None), _('All'), _('All Platforms'),
               (not platform))
    platforms.append(f)
    platforms_from_db = (Theme.objects.filter(
        product=PRODUCTS[product].id).values_list(
            'platform', flat=True).distinct().order_by('platform'))

    for p in platforms_from_db:
        if not p:
            continue
        f = Filter(urlparams(url, p=p), p, PLATFORMS[p].pretty,
                   (platform == p))
        platforms.append(f)

    return platforms
예제 #8
0
def _get_products(request, product):
    """Get product filters."""
    products = []
    url = request.get_full_path()

    for prod in PRODUCT_USAGE:
        f = Filter(urlparams(url, a=prod.short), prod.pretty, prod.pretty,
                   (product == prod.short))
        products.append(f)

    return products
예제 #9
0
def _get_platforms(request, product, platform):
    """Get platforms."""
    platforms = []
    url = request.get_full_path()

    f = Filter(urlparams(url, p=None), _('All'), _('All Platforms'),
               (not platform))
    platforms.append(f)
    platforms_from_db = (Theme.objects.filter(product=PRODUCTS[product].id)
                         .values_list('platform', flat=True)
                         .distinct().order_by('platform'))

    for p in platforms_from_db:
        if not p:
            continue
        f = Filter(urlparams(url, p=p), p, PLATFORMS[p].pretty,
                   (platform == p))
        platforms.append(f)

    return platforms
예제 #10
0
def _get_sentiments(request, sentiment):
    """Get available sentiment filters."""
    sentiments = []
    url = request.get_full_path()

    f = Filter(urlparams(url, s=None), _('All'), _('All feedback'),
               not sentiment)
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_PRAISE.short), _('Praise'),
               _('Praise only'), (sentiment == OPINION_PRAISE.short))
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_ISSUE.short), _('Issues'),
               _('Issues only'), (sentiment == OPINION_ISSUE.short))
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_IDEA.short), _('Ideas'),
               _('Ideas only'), (sentiment == OPINION_IDEA.short))
    sentiments.append(f)

    return sentiments
예제 #11
0
def _get_sentiments(request, sentiment):
    """Get available sentiment filters."""
    sentiments = []
    url = request.get_full_path()

    f = Filter(urlparams(url, s=None), _('All'),  _('All feedback'),
               not sentiment)
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_PRAISE.short), _('Praise'),
               _('Praise only'), (sentiment == OPINION_PRAISE.short))
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_ISSUE.short), _('Issues'),
               _('Issues only'), (sentiment == OPINION_ISSUE.short))
    sentiments.append(f)

    f = Filter(urlparams(url, s=OPINION_IDEA.short), _('Ideas'),
               _('Ideas only'), (sentiment == OPINION_IDEA.short))
    sentiments.append(f)

    return sentiments
예제 #12
0
    def process_request(self, request):
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        # Lang and channel are changeable by GET request.
        # Note that some paths might not exist across all channels, so handle
        # with care.
        # Format is (GET parameter, prefixer attribute)
        for param, attr in (('lang', 'locale'), ('channel', 'channel')):
            if param in request.GET:
                # Blank out the prefixer attribute so that we can set a new
                # one. Remove the parameter from the query params so we don't
                # have an infinite loop.
                setattr(prefixer, attr, '')
                new_path = prefixer.fix(prefixer.shortened_path)
                query = dict((smart_str(k), request.GET[k]) for k in
                             request.GET)
                query.pop(param)
                return HttpResponsePermanentRedirect(urlparams(new_path,
                                                               **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, new_channel, _ = prefixer.split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        request.channel = prefixer.channel
        tower.activate(prefixer.locale)
예제 #13
0
    def process_request(self, request):
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        # Lang is changeable by GET request.
        if 'lang' in request.GET:
            # Blank out the prefixer attribute so that we can set a new
            # one. Remove the parameter from the query params so we don't
            # have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), request.GET[k]) for k in
                         request.GET)
            query.pop('lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = prefixer.split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        tower.activate(prefixer.locale)
예제 #14
0
    def process_request(self, request):
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        # Lang is changeable by GET request.
        if 'lang' in request.GET:
            # Blank out the prefixer attribute so that we can set a new
            # one. Remove the parameter from the query params so we don't
            # have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), request.GET[k]) for k in request.GET)
            query.pop('lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = prefixer.split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        tower.activate(prefixer.locale)
예제 #15
0
def sites_url(context, url, **kw):
    _parsed = utils.urlparse(url)
    base_url = reverse('single_site', args=[_parsed.scheme, _parsed.netloc])
    base_url = base_url + '?' + context['request'].META['QUERY_STRING']
    return urlparams(base_url, page=None)