示例#1
0
文件: helpers.py 项目: aspes/zamboni
def impala_breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
    """
    show a list of breadcrumbs. If url is None, it won't be a link.
    Accepts: [(url, label)]
    """
    if add_default:
        if context.get('WEBAPPS'):
            base_title = _('Apps Marketplace')
        else:
            base_title = page_name(context['request'].APP)
        crumbs = [(urlresolvers.reverse('home'), base_title)]
    else:
        crumbs = []

    # add user-defined breadcrumbs
    if items:
        try:
            crumbs += items
        except TypeError:
            crumbs.append(items)

    crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
    c = {'breadcrumbs': crumbs, 'has_home': add_default}
    t = env.get_template('amo/impala/breadcrumbs.html').render(c)
    return jinja2.Markup(t)
示例#2
0
def mkt_breadcrumbs(context, product=None, items=None, crumb_size=40,
                    add_default=True, cls=None):
    """
    Wrapper function for ``breadcrumbs``.

    **items**
        list of [(url, label)] to be inserted after Add-on.
    **product**
        Adds the App/Add-on name to the end of the trail.  If items are
        specified then the App/Add-on will be linked.
    **add_default**
        Prepends trail back to home when True.  Default is True.
    """
    if add_default:
        crumbs = [(reverse('home'), _('Home'))]
    else:
        crumbs = []

    if product:
        if items:
            url_ = product.get_detail_url()
        else:
            # The Product is the end of the trail.
            url_ = None
        crumbs += [(None, _('Apps')), (url_, product.name)]
    if items:
        crumbs.extend(items)

    if len(crumbs) == 1:
        crumbs = []

    crumbs = [(u, truncate(label, crumb_size)) for (u, label) in crumbs]
    t = env.get_template('site/helpers/breadcrumbs.html').render(
        breadcrumbs=crumbs, cls=cls)
    return jinja2.Markup(t)
示例#3
0
    def get(self, request, *args, **kwargs):
        form_data = self.get_search_data(request, ApiSearchForm)
        query = form_data.get('q', '')
        base_filters = {'type': form_data['type']}

        qs = self.get_query(request, base_filters=base_filters,
                            region=self.get_region(request))
        profile = get_feature_profile(request)
        qs = self.apply_filters(request, qs, data=form_data, profile=profile)

        names = []
        descriptions = []
        urls = []
        icons = []

        for obj in qs:
            # FIXME: this does a lot of stuff we don't need. When es_app_to_dict
            # is replaced by a Serializer, then we should replace this with a
            # custom, lean serializer.
            base_data = self.serialize(request, obj)
            names.append(base_data['name'])
            descriptions.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icons'][64])
        return Response([query, names, descriptions, urls, icons],
                        content_type='application/x-suggestions+json')
示例#4
0
    def test_suggestions(self):
        app1 = Webapp.objects.get(pk=337141)
        app1.save()
        app2 = app_factory(name=u"Second âpp",
                           description=u"Second dèsc" * 25,
                           created=self.days_ago(3))
        self.refresh('webapp')

        response = self.client.get(self.url)
        parsed = json.loads(response.content)
        eq_(parsed[0], '')
        self.assertSetEqual(
            parsed[1],
            [unicode(app1.name), unicode(app2.name)])
        self.assertSetEqual(
            parsed[2],
            [unicode(app1.description),
             unicode(truncate(app2.description))])
        self.assertSetEqual(parsed[3], [
            absolutify(app1.get_detail_url()),
            absolutify(app2.get_detail_url())
        ])
        self.assertSetEqual(parsed[4],
                            [app1.get_icon_url(64),
                             app2.get_icon_url(64)])

        # Cleanup to remove these from the index.
        unindex_webapps([app1.id, app2.id])
        app1.delete()
        app2.delete()
示例#5
0
def impala_breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
    """
    show a list of breadcrumbs. If url is None, it won't be a link.
    Accepts: [(url, label)]
    """
    if add_default:
        if context.get('WEBAPPS'):
            base_title = _('Apps Marketplace')
        else:
            base_title = page_name(context['request'].APP)
        crumbs = [(urlresolvers.reverse('home'), base_title)]
    else:
        crumbs = []

    # add user-defined breadcrumbs
    if items:
        try:
            crumbs += items
        except TypeError:
            crumbs.append(items)

    crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
    c = {'breadcrumbs': crumbs, 'has_home': add_default}
    t = env.get_template('amo/impala/breadcrumbs.html').render(**c)
    return jinja2.Markup(t)
示例#6
0
 def dehydrate(self, bundle):
     data = super(SuggestionsResource, self).dehydrate(bundle).data
     return {
         'description': truncate(data['description']),
         'name': data['name'],
         'absolute_url': data['absolute_url'],
         'icon': data['icons'][64],
     }
示例#7
0
 def test_suggestions(self):
     response = self.client.get(self.url, data={"lang": "en-US"})
     parsed = json.loads(response.content)
     eq_(parsed[0], "")
     self.assertSetEqual(parsed[1], [unicode(self.app1.name), unicode(self.app2.name)])
     self.assertSetEqual(parsed[2], [unicode(self.app1.description), unicode(truncate(self.app2.description))])
     self.assertSetEqual(parsed[3], [absolutify(self.app1.get_detail_url()), absolutify(self.app2.get_detail_url())])
     self.assertSetEqual(parsed[4], [self.app1.get_icon_url(64), self.app2.get_icon_url(64)])
示例#8
0
文件: api.py 项目: kmaglione/zamboni
 def dehydrate(self, bundle):
     data = super(SuggestionsResource, self).dehydrate(bundle).data
     return {
         "description": truncate(data["description"]),
         "name": data["name"],
         "absolute_url": data["absolute_url"],
         "icon": data["icons"][64],
     }
示例#9
0
 def test_redirect_sharing(self):
     addon = Addon.objects.get(id=3615)
     r = self.client.get(reverse('addons.share', args=['a3615']),
                         {'service': 'delicious'})
     url = absolutify(unicode(addon.get_url_path()))
     summary = truncate(addon.summary, length=250)
     eq_(r.status_code, 302)
     assert iri_to_uri(addon.name) in r['Location']
     assert iri_to_uri(url) in r['Location']
     assert iri_to_uri(summary) in r['Location']
示例#10
0
 def test_redirect_sharing(self):
     addon = Addon.objects.get(id=3615)
     r = self.client.get(reverse('addons.share', args=['a3615']),
                         {'service': 'delicious'})
     url = absolutify(unicode(addon.get_url_path()))
     summary = truncate(addon.summary, length=250)
     eq_(r.status_code, 302)
     assert iri_to_uri(addon.name) in r['Location']
     assert iri_to_uri(url) in r['Location']
     assert iri_to_uri(summary) in r['Location']
示例#11
0
 def test_redirect_sharing(self):
     r = self.client.get(reverse('apps.share', args=['yeah']),
                         {'service': 'delicious'})
     d = {
         'title': page_title({'request': r}, self.webapp.name,
                             force_webapps=True),
         'description': truncate(self.webapp.summary, length=250),
         'url': absolutify(self.webapp.get_url_path()),
     }
     url = iri_to_uri(get_service('delicious').url.format(**d))
     self.assertRedirects(r, url, status_code=302, target_status_code=301)
示例#12
0
 def test_redirect_sharing(self):
     r = self.client.get(reverse('apps.share', args=['yeah']),
                         {'service': 'delicious'})
     d = {
         'title': page_title({'request': r}, self.webapp.name,
                             force_webapps=True),
         'description': truncate(self.webapp.summary, length=250),
         'url': absolutify(self.webapp.get_url_path()),
     }
     url = iri_to_uri(get_service('delicious').url.format(**d))
     self.assertRedirects(r, url, status_code=302, target_status_code=301)
示例#13
0
文件: api.py 项目: lmorchard/zamboni
    def get(self, request, *args, **kwargs):
        results, query = self.search(request)

        names = []
        descriptions = []
        urls = []
        icons = []

        for base_data in results.data['objects']:
            names.append(base_data['name'])
            descriptions.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icons'][64])
        return Response([query, names, descriptions, urls, icons],
                        content_type='application/x-suggestions+json')
示例#14
0
文件: api.py 项目: imclab/olympia
    def get(self, request, *args, **kwargs):
        results, query = self.search(request)

        names = []
        descriptions = []
        urls = []
        icons = []

        for base_data in results.data['objects']:
            names.append(base_data['name'])
            descriptions.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icons'][64])
        return Response([query, names, descriptions, urls, icons],
                        content_type='application/x-suggestions+json')
示例#15
0
    def get(self, request, *args, **kwargs):
        results, query = self.search(request)

        names = []
        descs = []
        urls = []
        icons = []

        for base_data in results.data['objects']:
            names.append(base_data['name'])
            descs.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icon'])
        # This results a list. Usually this is a bad idea, but we don't return
        # any user-specific data, it's fully anonymous, so we're fine.
        return HttpResponse(json.dumps([query, names, descs, urls, icons]),
                            content_type='application/x-suggestions+json')
示例#16
0
文件: views.py 项目: aspes/zamboni
    def get(self, request, *args, **kwargs):
        results, query = self.search(request)

        names = []
        descs = []
        urls = []
        icons = []

        for base_data in results.data['objects']:
            names.append(base_data['name'])
            descs.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icon'])
        # This results a list. Usually this is a bad idea, but we don't return
        # any user-specific data, it's fully anonymous, so we're fine.
        return HttpResponse(json.dumps([query, names, descs, urls, icons]),
                            content_type='application/x-suggestions+json')
示例#17
0
    def test_suggestions(self):
        app1 = Webapp.objects.get(pk=337141)
        app1.save()
        app2 = app_factory(name=u"Second âpp", description=u"Second dèsc" * 25, created=self.days_ago(3))
        self.refresh("webapp")

        response = self.client.get(self.url)
        parsed = json.loads(response.content)
        eq_(parsed[0], "")
        eq_(parsed[1], [unicode(app1.name), unicode(app2.name)])
        eq_(parsed[2], [unicode(app1.description), unicode(truncate(app2.description))])
        eq_(parsed[3], [absolutify(app1.get_detail_url()), absolutify(app2.get_detail_url())])
        eq_(parsed[4], [app1.get_icon_url(64), app2.get_icon_url(64)])

        # Cleanup to remove these from the index.
        unindex_webapps([app1.id, app2.id])
        app1.delete()
        app2.delete()
示例#18
0
 def test_suggestions(self):
     response = self.client.get(self.url, data={'lang': 'en-US'})
     parsed = json.loads(response.content)
     eq_(parsed[0], '')
     self.assertSetEqual(
         parsed[1],
         [unicode(self.app1.name), unicode(self.app2.name)])
     self.assertSetEqual(
         parsed[2],
         [unicode(self.app1.description),
          unicode(truncate(self.app2.description))])
     self.assertSetEqual(
         parsed[3],
         [absolutify(self.app1.get_detail_url()),
          absolutify(self.app2.get_detail_url())])
     self.assertSetEqual(
         parsed[4],
         [self.app1.get_icon_url(64), self.app2.get_icon_url(64)])
示例#19
0
def mkt_breadcrumbs(context,
                    product=None,
                    items=None,
                    crumb_size=40,
                    add_default=True,
                    cls=None):
    """
    Wrapper function for ``breadcrumbs``.

    **items**
        list of [(url, label)] to be inserted after Add-on.
    **product**
        Adds the App/Add-on name to the end of the trail.  If items are
        specified then the App/Add-on will be linked.
    **add_default**
        Prepends trail back to home when True.  Default is True.
    """
    if add_default:
        crumbs = [(reverse('home'), _('Home'))]
    else:
        crumbs = []

    if product:
        if items:
            url_ = product.get_detail_url()
        else:
            # The Product is the end of the trail.
            url_ = None
        crumbs += [(None, _('Apps')), (url_, product.name)]
    if items:
        crumbs.extend(items)

    if len(crumbs) == 1:
        crumbs = []

    crumbs = [(u, truncate(label, crumb_size)) for (u, label) in crumbs]
    t = env.get_template('site/helpers/breadcrumbs.html').render({
        'breadcrumbs':
        crumbs,
        'cls':
        cls
    })
    return jinja2.Markup(t)
示例#20
0
文件: helpers.py 项目: rajuch/zamboni
def breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
    """
    show a list of breadcrumbs. If url is None, it won't be a link.
    Accepts: [(url, label)]
    """
    if add_default:
        app = context['request'].APP
        crumbs = [(urlresolvers.reverse('home'), page_name(app))]
    else:
        crumbs = []
    # add user-defined breadcrumbs
    if items:
        try:
            crumbs += items
        except TypeError:
            crumbs.append(items)

    crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
    c = {'breadcrumbs': crumbs}
    t = env.get_template('amo/breadcrumbs.html').render(**c)
    return jinja2.Markup(t)
示例#21
0
def impala_breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
    """
    show a list of breadcrumbs. If url is None, it won't be a link.
    Accepts: [(url, label)]
    """
    if add_default:
        base_title = page_name(context["request"].APP)
        crumbs = [(urlresolvers.reverse("home"), base_title)]
    else:
        crumbs = []

    # add user-defined breadcrumbs
    if items:
        try:
            crumbs += items
        except TypeError:
            crumbs.append(items)

    crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
    c = {"breadcrumbs": crumbs, "has_home": add_default}
    t = env.get_template("amo/impala/breadcrumbs.html").render(c)
    return jinja2.Markup(t)
示例#22
0
def breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
    """
    show a list of breadcrumbs. If url is None, it won't be a link.
    Accepts: [(url, label)]
    """
    if add_default:
        app = context['request'].APP
        crumbs = [(urlresolvers.reverse('home'), page_name(app))]
    else:
        crumbs = []

    # add user-defined breadcrumbs
    if items:
        try:
            crumbs += items
        except TypeError:
            crumbs.append(items)

    crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
    c = {'breadcrumbs': crumbs}
    t = env.get_template('amo/breadcrumbs.html').render(**c)
    return jinja2.Markup(t)
示例#23
0
文件: api.py 项目: hardikj/zamboni
    def get(self, request, *args, **kwargs):
        form_data = self.get_search_data(request, ApiSearchForm)
        query = form_data.get('q', '')
        base_filters = {'type': form_data['type']}

        qs = self.get_query(request, base_filters=base_filters,
                            region=self.get_region(request))
        profile = get_feature_profile(request)
        qs = self.apply_filters(request, qs, data=form_data, profile=profile)

        names = []
        descriptions = []
        urls = []
        icons = []

        for obj in qs:
            base_data = self.serialize(request, obj)
            names.append(base_data['name'])
            descriptions.append(truncate(base_data['description']))
            urls.append(base_data['absolute_url'])
            icons.append(base_data['icons'][64])
        return Response([query, names, descriptions, urls, icons],
                        content_type='application/x-suggestions+json')
示例#24
0
文件: admin.py 项目: zuzelvp/olympia
 def truncate_response(obj):
     return truncate(obj.response, 50)
示例#25
0
 def clean_description(self):
     return truncate(self.cleaned_data.get('description', ''), 250)
示例#26
0
def share(request, addon):
    """Add-on sharing"""
    return share_redirect(request,
                          addon,
                          name=addon.name,
                          description=truncate(addon.summary, length=250))
示例#27
0
文件: admin.py 项目: AALEKH/zamboni
 def truncate_response(obj):
     return truncate(obj.response, 50)
示例#28
0
def share(request, addon):
    """Add-on sharing"""
    return share_redirect(request, addon, name=addon.name,
                          description=truncate(addon.summary, length=250))
示例#29
0
文件: views.py 项目: ozten/zamboni
def share(request, addon_id):
    """Add-on sharing"""
    addon = get_object_or_404(Addon.objects.valid(), id=addon_id)
    return share_redirect(request, addon, name=addon.name,
                          description=truncate(addon.summary, length=250))