예제 #1
0
def ajax_search_suggestions(request):
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        cat = request.GET.get('cat', 'all')

        # Don't let Marketplace query any other types.
        if settings.MARKETPLACE:
            cat = 'apps'

        if cat != 'apps':
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append({
                        'id': a.id,
                        'name': _(u'{0} Add-ons').format(a.pretty),
                        'url': locale_url(a.short),
                        'cls': 'app ' + a.short
                    })

        # Categories.
        cats = Category.objects
        if cat == 'apps':
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(Q(application=request.APP.id) |
                               Q(type=amo.ADDON_SEARCH))
            if cat == 'personas':
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(type__in=[amo.ADDON_PERSONA,
                                              amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        suggestions = {
            'all': AddonSuggestionsAjax,
            'personas': PersonaSuggestionsAjax,
            'apps': WebappSuggestionsAjax,
        }.get(cat, AddonSuggestionsAjax)

        results += suggestions(request).items

    return results
예제 #2
0
파일: views.py 프로젝트: flyun/zamboni
def ajax_search_suggestions(request):
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        cat = request.GET.get('cat', 'all')

        # Don't let Marketplace query any other types.
        if settings.MARKETPLACE:
            cat = 'apps'

        if cat != 'apps':
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append({
                        'id': a.id,
                        'name': _(u'{0} Add-ons').format(a.pretty),
                        'url': locale_url(a.short),
                        'cls': 'app ' + a.short
                    })

        # Categories.
        cats = Category.objects
        if cat == 'apps':
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(
                Q(application=request.APP.id) | Q(type=amo.ADDON_SEARCH))
            if cat == 'themes':
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(
                    type__in=[amo.ADDON_PERSONA, amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        suggestions = {
            'all': AddonSuggestionsAjax,
            'themes': PersonaSuggestionsAjax,
            'apps': WebappSuggestionsAjax,
        }.get(cat, AddonSuggestionsAjax)

        results += suggestions(request).items

    return results
예제 #3
0
파일: views.py 프로젝트: almet/zamboni
def ajax_search_suggestions(request):
    results = []
    q = request.GET.get("q")
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        cat = request.GET.get("cat", "all")

        # Don't let Marketplace query any other types.
        if settings.MARKETPLACE:
            cat = "apps"

        if cat != "apps":
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append(
                        {
                            "id": a.id,
                            "name": _(u"{0} Add-ons").format(a.pretty),
                            "url": locale_url(a.short),
                            "cls": "app " + a.short,
                        }
                    )

        # Categories.
        cats = Category.objects
        if cat == "apps":
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(Q(application=request.APP.id) | Q(type=amo.ADDON_SEARCH))
            if cat == "themes":
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(type__in=[amo.ADDON_PERSONA, amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({"id": c.id, "name": unicode(c.name), "url": c.get_url_path(), "cls": "cat"})

        suggestions = {
            "all": AddonSuggestionsAjax,
            "themes": PersonaSuggestionsAjax,
            "apps": WebappSuggestionsAjax,
        }.get(cat, AddonSuggestionsAjax)

        results += suggestions(request).items

    return results
예제 #4
0
    def search_applications(self, params, apps=[]):
        r = self.client.get(self.url + '?' + params)
        eq_(r.status_code, 200)
        data = json.loads(r.content)

        data = sorted(data, key=lambda x: x['id'])
        apps = sorted(apps, key=lambda x: x.id)

        eq_(len(data), len(apps))
        for got, expected in zip(data, apps):
            eq_(int(got['id']), expected.id)
            eq_(got['name'], '%s Add-ons' % unicode(expected.pretty))
            eq_(got['url'], locale_url(expected.short))
            eq_(got['cls'], 'app ' + expected.short)
예제 #5
0
    def search_applications(self, params, apps=[]):
        r = self.client.get("?".join([self.url, params]))
        eq_(r.status_code, 200)
        data = json.loads(r.content)

        data = sorted(data, key=lambda x: x["id"])
        apps = sorted(apps, key=lambda x: x.id)

        eq_(len(data), len(apps))
        for got, expected in zip(data, apps):
            eq_(int(got["id"]), expected.id)
            eq_(got["name"], "%s Add-ons" % unicode(expected.pretty))
            eq_(got["url"], locale_url(expected.short))
            eq_(got["cls"], "app " + expected.short)
예제 #6
0
    def search_applications(self, params, apps=[]):
        r = self.client.get(self.url + '?' + params)
        eq_(r.status_code, 200)
        data = json.loads(r.content)

        data = sorted(data, key=lambda x: x['id'])
        apps = sorted(apps, key=lambda x: x.id)

        eq_(len(data), len(apps))
        for got, expected in zip(data, apps):
            eq_(int(got['id']), expected.id)
            eq_(got['name'], '%s Add-ons' % unicode(expected.pretty))
            eq_(got['url'], locale_url(expected.short))
            eq_(got['cls'], 'app ' + expected.short)
예제 #7
0
def _build_suggestions(request, cat, suggester):
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        if cat != 'apps':
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append({
                        'id': a.id,
                        'name': _(u'{0} Add-ons').format(a.pretty),
                        'url': locale_url(a.short),
                        'cls': 'app ' + a.short
                    })

        # Categories.
        cats = Category.objects
        if cat == 'apps':
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(Q(application=request.APP.id) |
                               Q(type=amo.ADDON_SEARCH))
            if cat == 'themes':
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(type__in=[amo.ADDON_PERSONA,
                                              amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        results += suggester.items

    return results
예제 #8
0
def _build_suggestions(request, cat, suggester):
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        if cat != 'apps':
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append({
                        'id': a.id,
                        'name': _(u'{0} Add-ons').format(a.pretty),
                        'url': locale_url(a.short),
                        'cls': 'app ' + a.short
                    })

        # Categories.
        cats = Category.objects
        if cat == 'apps':
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(
                Q(application=request.APP.id) | Q(type=amo.ADDON_SEARCH))
            if cat == 'themes':
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(
                    type__in=[amo.ADDON_PERSONA, amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        results += suggester.items

    return results
예제 #9
0
파일: views.py 프로젝트: vinu76jsr/zamboni
def _build_suggestions(request, cat, suggester):
    results = []
    q = request.GET.get("q")
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        if cat != "apps":
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append(
                        {
                            "id": a.id,
                            "name": _(u"{0} Add-ons").format(a.pretty),
                            "url": locale_url(a.short),
                            "cls": "app " + a.short,
                        }
                    )

        # Categories.
        cats = Category.objects
        if cat == "apps":
            cats = cats.filter(type=amo.ADDON_WEBAPP)
        else:
            cats = cats.filter(Q(application=request.APP.id) | Q(type=amo.ADDON_SEARCH))
            if cat == "themes":
                cats = cats.filter(type=amo.ADDON_PERSONA)
            else:
                cats = cats.exclude(type__in=[amo.ADDON_PERSONA, amo.ADDON_WEBAPP])

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({"id": c.id, "name": unicode(c.name), "url": c.get_url_path(), "cls": "cat"})

        results += suggester.items

    return results
예제 #10
0
파일: views.py 프로젝트: atassumer/zamboni
def ajax_search_suggestions(request):
    # TODO(cvan): Tests will come when I know this is what fligtar wants.
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or (not q.isdigit() and len(q) > 2)):
        q_ = q.lower()

        # Applications.
        for a in amo.APP_USAGE:
            if q_ in unicode(a.pretty).lower():
                results.append({
                    'id': a.id,
                    'name': _(u'{0} Add-ons').format(a.pretty),
                    'url': locale_url(a.short),
                    'cls': 'app ' + a.short
                })

        # Categories.
        cats = (Category.objects
                .filter(Q(application=request.APP.id) |
                        Q(type=amo.ADDON_SEARCH))
                .exclude(type=amo.ADDON_WEBAPP))
        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        # Add-ons.
        results += SuggestionsAjax(request).items

    return results
예제 #11
0
파일: views.py 프로젝트: tmp0230/zamboni
def ajax_search_suggestions(request):
    # TODO(cvan): Tests will come when I know this is what fligtar wants.
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or (not q.isdigit() and len(q) > 2)):
        q_ = q.lower()

        # Applications.
        for a in amo.APP_USAGE:
            if q_ in unicode(a.pretty).lower():
                results.append({
                    'id': a.id,
                    'name': _(u'{0} Add-ons').format(a.pretty),
                    'url': locale_url(a.short),
                    'cls': 'app ' + a.short
                })

        # Categories.
        cats = (Category.objects.filter(
            Q(application=request.APP.id)
            | Q(type=amo.ADDON_SEARCH)).exclude(type=amo.ADDON_WEBAPP))
        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        # Add-ons.
        results += SuggestionsAjax(request).items

    return results
예제 #12
0
def report_menu(context, request, addon, report):

    report_tree = [
        {
            'name': 'overview',
            'url': '/',
            'title': _('Overview'),
        },
        {
            'name': 'downloads',
            'url': '/downloads/',
            'title': _('Downloads'),
            'children': [
                {
                    'name': 'sources',
                    'url': '/downloads/sources/',
                    'title': _('by Source'),
                },
            ]
        },
        {
            'name': 'usage',
            'url': '/usage/',
            'title': _('Daily Users'),
            'children': [
                {
                    'name': 'versions',
                    'url': '/usage/versions/',
                    'title': _('by Add-on Version')
                },
                {
                    'name': 'apps',
                    'url': '/usage/applications/',
                    'title': _('by Application')
                },
                {
                    'name': 'locales',
                    'url': '/usage/languages/',
                    'title': _('by Language')
                },
                {
                    'name': 'os',
                    'url': '/usage/os/',
                    'title': _('by Platform')
                },
                {
                    'name': 'statuses',
                    'url': '/usage/status/',
                    'title': _('by Add-on Status')
                },
            ]
        },
    ]

    if (request.user.is_authenticated() and (
            acl.action_allowed(request, 'Admin', 'ViewAnyStats') or
            addon.has_author(request.amo_user))):
        report_tree.append({
            'name': 'contributions',
            'url': '/contributions/',
            'title': _('Contributions')
        })

    base_url = '/addon/%d/statistics' % (addon.id)

    """Reports Menu. navigation for the various statistic reports."""
    c = {'report': report,
        'base_url': locale_url(base_url),
        'report_tree': report_tree}
    return c
예제 #13
0
파일: helpers.py 프로젝트: tmp0230/zamboni
def report_menu(context, addon, report):

    report_tree = [
        {
            'name': 'overview',
            'url': '/',
            'title': _('Overview'),
        },
        {
            'name':
            'downloads',
            'url':
            '/downloads/',
            'title':
            _('Downloads'),
            'children': [
                {
                    'name': 'sources',
                    'url': '/downloads/sources/',
                    'title': _('by Source'),
                },
            ]
        },
        {
            'name':
            'usage',
            'url':
            '/usage/',
            'title':
            _('Daily Users'),
            'children': [
                {
                    'name': 'versions',
                    'url': '/usage/versions/',
                    'title': _('by Add-on Version')
                },
                {
                    'name': 'apps',
                    'url': '/usage/applications/',
                    'title': _('by Application')
                },
                {
                    'name': 'locales',
                    'url': '/usage/languages/',
                    'title': _('by Language')
                },
                {
                    'name': 'os',
                    'url': '/usage/os/',
                    'title': _('by Operating System')
                },
                {
                    'name': 'statuses',
                    'url': '/usage/status/',
                    'title': _('by Add-on Status')
                },
            ]
        },
        {
            'name': 'contributions',
            'url': '/contributions/',
            'title': _('Contributions')
        },
    ]

    base_url = '/addon/%d/statistics' % (addon.id)
    """Reports Menu. navigation for the various statistic reports."""
    c = {
        'report': report,
        'base_url': locale_url(base_url),
        'report_tree': report_tree
    }
    return c
예제 #14
0
 def test_mobile_link_firefox(self):
     doc = pq(test.Client().get('/firefox', follow=True).content)
     eq_(doc('#site-nav #more .more-mobile a').attr('href'),
         locale_url(amo.MOBILE.short))
예제 #15
0
def report_menu(context, addon, report):

    report_tree = [
        {
            'name': 'overview',
            'url': '/',
            'title': _('Overview'),
        },
        {
            'name': 'downloads',
            'url': '/downloads/',
            'title': _('Downloads'),
            'children': [
                {
                    'name': 'sources',
                    'url': '/downloads/sources/',
                    'title': _('by Download Source'),
                },
            ]
        },
        {
            'name': 'usage',
            'url': '/usage/',
            'title': _('Daily Users'),
            'children': [
                {
                    'name': 'versions',
                    'url': '/usage/versions/',
                    'title': _('by Add-on Version')
                },
                {
                    'name': 'apps',
                    'url': '/usage/applications/',
                    'title': _('by Application')
                },
                {
                    'name': 'locales',
                    'url': '/usage/languages/',
                    'title': _('by Language')
                },
                {
                    'name': 'os',
                    'url': '/usage/os/',
                    'title': _('by Operating System')
                },
                {
                    'name': 'status',
                    'url': '/usage/status/',
                    'title': _('by Add-on Status')
                },
            ]
        },
        {
            'name': 'contributions',
            'url': '/contributions/',
            'title': _('Contributions')
        },
    ]

    base_url = '/addon/%d/statistics' % (addon.id)

    """Reports Menu. navigation for the various statistic reports."""
    c = {'report': report,
        'base_url': locale_url(base_url),
        'report_tree': report_tree}
    return c
예제 #16
0
 def test_mobile_link_firefox(self):
     doc = pq(test.Client().get("/firefox", follow=True).content)
     eq_(doc("#site-nav #more .more-mobile a").attr("href"), locale_url(amo.MOBILE.short))