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)
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)
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')
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()
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)
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], }
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)])
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], }
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']
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)
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')
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')
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()
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)])
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)
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)
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)
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')
def truncate_response(obj): return truncate(obj.response, 50)
def clean_description(self): return truncate(self.cleaned_data.get('description', ''), 250)
def share(request, addon): """Add-on sharing""" return share_redirect(request, addon, name=addon.name, description=truncate(addon.summary, length=250))
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))