def detail(request, addon, add_review=False): """Product details page.""" reviews = Review.objects.valid().filter(addon=addon, is_latest=True) # Mature regions show only reviews from within that region. if not request.REGION.adolescent: reviews = reviews.filter(client_data__region=request.REGION.id) reviewed_filter = dict(user=request.user.id) if addon.is_packaged: reviewed_filter['version'] = addon.current_version num_reviews = 6 if request.TABLET or not request.MOBILE else 2 user_review = reviews.filter(**reviewed_filter) ctx = { 'product': addon, 'reviews': reviews[:num_reviews], 'flags': get_flags(request, reviews), 'has_review': request.user.is_authenticated() and user_review.exists(), 'grouped_ratings': GroupedRating.get(addon.id), 'details_page': True, 'add_review': add_review, } if ctx['has_review']: ctx['my_review'] = user_review[0] if addon.is_public(): ctx['abuse_form'] = AbuseForm(request=request) return jingo.render(request, 'detail/app.html', ctx)
def extension_detail(request, addon): """Extensions details page.""" # If current version is incompatible with this app, redirect. comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return redirect('addons.detail', addon.slug, permanent=True) # Popular collections this addon is part of. collections = Collection.objects.listed().filter( addons=addon, application=request.APP.id) ctx = { 'addon': addon, 'src': request.GET.get('src', 'dp-btn-primary'), 'version_src': request.GET.get('src', 'dp-btn-version'), 'tags': addon.tags.not_blacklisted(), 'grouped_ratings': GroupedRating.get(addon.id), 'review_form': ReviewForm(), 'reviews': Review.objects.valid().filter(addon=addon, is_latest=True), 'get_replies': Review.get_replies, 'collections': collections.order_by('-subscribers')[:3], 'abuse_form': AbuseForm(request=request), } # details.html just returns the top half of the page for speed. The bottom # does a lot more queries we don't want on the initial page load. if request.is_ajax(): # Other add-ons/apps from the same author(s). ctx['author_addons'] = addon.authors_other_addons(app=request.APP)[:6] return render(request, 'addons/impala/details-more.html', ctx) else: return render(request, 'addons/impala/details.html', ctx)
def extension_detail(request, addon): """Extensions details page.""" # If current version is incompatible with this app, redirect. comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return redirect('addons.detail', addon.slug, permanent=True) # get satisfaction only supports en-US. lang = translation.to_locale(translation.get_language()) addon.has_satisfaction = (lang == 'en_US' and addon.get_satisfaction_company) # Addon recommendations. recommended = Addon.objects.listed(request.APP).filter( recommended_for__addon=addon)[:6] # Popular collections this addon is part of. collections = Collection.objects.listed().filter( addons=addon, application__id=request.APP.id) ctx = { 'addon': addon, 'src': request.GET.get('src', 'dp-btn-primary'), 'version_src': request.GET.get('src', 'dp-btn-version'), 'tags': addon.tags.not_blacklisted(), 'grouped_ratings': GroupedRating.get(addon.id), 'recommendations': recommended, 'review_form': ReviewForm(), 'reviews': Review.objects.latest().filter(addon=addon), 'get_replies': Review.get_replies, 'collections': collections.order_by('-subscribers')[:3], 'abuse_form': AbuseForm(request=request), } # details.html just returns the top half of the page for speed. The bottom # does a lot more queries we don't want on the initial page load. if request.is_ajax(): # Other add-ons/apps from the same author(s). if addon.is_webapp(): others = Webapp.objects.listed().filter(type=amo.ADDON_WEBAPP) else: others = (Addon.objects.listed(request.APP) .exclude(type=amo.ADDON_WEBAPP)) others = (others.exclude(id=addon.id).distinct() .filter(addonuser__listed=True, authors__in=addon.listed_authors)) ctx['author_addons'] = others[:6] return jingo.render(request, 'addons/impala/details-more.html', ctx) else: if addon.is_webapp(): ctx['search_placeholder'] = 'apps' return jingo.render(request, 'addons/impala/details.html', ctx)
def impala_extension_detail(request, addon): """Extensions details page.""" # if current version is incompatible with this app, redirect comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return http.HttpResponsePermanentRedirect(reverse( 'addons.detail', args=[addon.slug])) # source tracking src = request.GET.get('src', 'addon-detail') # get satisfaction only supports en-US lang = translation.to_locale(translation.get_language()) addon.has_satisfaction = (lang == 'en_US' and addon.get_satisfaction_company) # other add-ons from the same author(s) author_addons = order_by_translation(addon.authors_other_addons, 'name')[:6] # tags tags = addon.tags.not_blacklisted() # addon recommendations recommended = MiniAddon.objects.valid().filter( recommended_for__addon=addon)[:5] # popular collections this addon is part of collections = Collection.objects.listed().filter( addons=addon, application__id=request.APP.id) data = { 'addon': addon, 'author_addons': author_addons, 'src': src, 'tags': tags, 'grouped_ratings': GroupedRating.get(addon.id), 'recommendations': recommended, 'review_form': ReviewForm(), 'reviews': Review.objects.latest().filter(addon=addon), 'get_replies': Review.get_replies, 'collections': collections.order_by('-subscribers')[:3], } if settings.REPORT_ABUSE: data['abuse_form'] = AbuseForm(request=request) return jingo.render(request, 'addons/impala/details.html', data)
def detail(request, addon): """Product details page.""" reviews = Review.objects.latest().filter(addon=addon) ctx = { "product": addon, "reviews": reviews[:2], "flags": get_flags(request, reviews), "has_review": request.user.is_authenticated() and reviews.filter(user=request.user.id).exists(), "grouped_ratings": GroupedRating.get(addon.id), } if addon.is_public(): ctx["abuse_form"] = AbuseForm(request=request) return jingo.render(request, "detail/app.html", ctx)
def impala_extension_detail(request, addon): """Extensions details page.""" # if current version is incompatible with this app, redirect comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return http.HttpResponsePermanentRedirect( reverse('addons.detail', args=[addon.slug])) # source tracking src = request.GET.get('src', 'addon-detail') # get satisfaction only supports en-US lang = translation.to_locale(translation.get_language()) addon.has_satisfaction = (lang == 'en_US' and addon.get_satisfaction_company) # other add-ons from the same author(s) author_addons = order_by_translation(addon.authors_other_addons, 'name')[:6] # tags tags = addon.tags.not_blacklisted() # addon recommendations recommended = MiniAddon.objects.valid().filter( recommended_for__addon=addon)[:5] # popular collections this addon is part of collections = Collection.objects.listed().filter( addons=addon, application__id=request.APP.id) data = { 'addon': addon, 'author_addons': author_addons, 'src': src, 'tags': tags, 'grouped_ratings': GroupedRating.get(addon.id), 'recommendations': recommended, 'review_form': ReviewForm(), 'reviews': Review.objects.latest().filter(addon=addon), 'get_replies': Review.get_replies, 'collections': collections.order_by('-subscribers')[:3], } if settings.REPORT_ABUSE: data['abuse_form'] = AbuseForm(request=request) return jingo.render(request, 'addons/impala/details.html', data)
def detail(request, addon): """Product details page.""" reviews = Review.objects.latest().filter(addon=addon) ctx = { 'product': addon, 'reviews': reviews[:2], 'flags': get_flags(request, reviews), 'has_review': request.user.is_authenticated() and reviews.filter(user=request.user.id).exists(), 'grouped_ratings': GroupedRating.get(addon.id) } if addon.is_public(): ctx['abuse_form'] = AbuseForm(request=request) return jingo.render(request, 'detail/app.html', ctx)
def extension_detail(request, addon): """Extensions details page.""" # If current version is incompatible with this app, redirect. comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return redirect("addons.detail", addon.slug, permanent=True) # get satisfaction only supports en-US. lang = translation.to_locale(translation.get_language()) addon.has_satisfaction = lang == "en_US" and addon.get_satisfaction_company # Addon recommendations. recommended = Addon.objects.listed(request.APP).filter(recommended_for__addon=addon)[:6] # Popular collections this addon is part of. collections = Collection.objects.listed().filter(addons=addon, application__id=request.APP.id) ctx = { "addon": addon, "src": request.GET.get("src", "dp-btn-primary"), "version_src": request.GET.get("src", "dp-btn-version"), "tags": addon.tags.not_blacklisted(), "grouped_ratings": GroupedRating.get(addon.id), "recommendations": recommended, "review_form": ReviewForm(), "reviews": Review.objects.latest().filter(addon=addon), "get_replies": Review.get_replies, "collections": collections.order_by("-subscribers")[:3], "abuse_form": AbuseForm(request=request), } # details.html just returns the top half of the page for speed. The bottom # does a lot more queries we don't want on the initial page load. if request.is_ajax(): # Other add-ons/apps from the same author(s). if addon.is_webapp(): others = Webapp.objects.listed().filter(type=amo.ADDON_WEBAPP) else: others = Addon.objects.listed(request.APP).exclude(type=amo.ADDON_WEBAPP) others = others.exclude(id=addon.id).distinct().filter(addonuser__listed=True, authors__in=addon.listed_authors) ctx["author_addons"] = others[:6] return jingo.render(request, "addons/impala/details-more.html", ctx) else: if addon.is_webapp(): ctx["search_cat"] = "apps" return jingo.render(request, "addons/impala/details.html", ctx)
def extension_detail(request, addon): """Extensions details page.""" # If current version is incompatible with this app, redirect. comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return redirect('addons.detail', addon.slug, permanent=True) # Addon recommendations. recommended = Addon.objects.listed(request.APP).filter( recommended_for__addon=addon)[:6] # Popular collections this addon is part of. collections = Collection.objects.listed().filter( addons=addon, application__id=request.APP.id) ctx = { 'addon': addon, 'src': request.GET.get('src', 'dp-btn-primary'), 'version_src': request.GET.get('src', 'dp-btn-version'), 'tags': addon.tags.not_blacklisted(), 'grouped_ratings': GroupedRating.get(addon.id), 'recommendations': recommended, 'review_form': ReviewForm(), 'reviews': Review.objects.valid().filter(addon=addon, is_latest=True), 'get_replies': Review.get_replies, 'collections': collections.order_by('-subscribers')[:3], 'abuse_form': AbuseForm(request=request), } # details.html just returns the top half of the page for speed. The bottom # does a lot more queries we don't want on the initial page load. if request.is_ajax(): # Other add-ons/apps from the same author(s). ctx['author_addons'] = addon.authors_other_addons(app=request.APP)[:6] return jingo.render(request, 'addons/impala/details-more.html', ctx) else: if addon.is_webapp(): ctx['search_placeholder'] = 'apps' return jingo.render(request, 'addons/impala/details.html', ctx)
def detail(request, addon): """Product details page.""" reviews = Review.objects.latest().filter(addon=addon) ctx = { 'product': addon, 'reviews': reviews[:2], 'flags': get_flags(request, reviews), 'has_review': request.user.is_authenticated() and reviews.filter(user=request.user.id).exists(), 'grouped_ratings': GroupedRating.get(addon.id), 'details_page': True } if addon.is_public(): ctx['abuse_form'] = AbuseForm(request=request) return jingo.render(request, 'detail/app.html', ctx)
def extension_detail(request, addon): """Extensions details page.""" # If current version is incompatible with this app, redirect. comp_apps = addon.compatible_apps if comp_apps and request.APP not in comp_apps: prefixer = urlresolvers.get_url_prefix() prefixer.app = comp_apps.keys()[0].short return redirect("addons.detail", addon.slug, permanent=True) # Addon recommendations. recommended = Addon.objects.listed(request.APP).filter(recommended_for__addon=addon)[:6] # Popular collections this addon is part of. collections = Collection.objects.listed().filter(addons=addon, application__id=request.APP.id) ctx = { "addon": addon, "src": request.GET.get("src", "dp-btn-primary"), "version_src": request.GET.get("src", "dp-btn-version"), "tags": addon.tags.not_blacklisted(), "grouped_ratings": GroupedRating.get(addon.id), "recommendations": recommended, "review_form": ReviewForm(), "reviews": Review.objects.valid().filter(addon=addon, is_latest=True), "get_replies": Review.get_replies, "collections": collections.order_by("-subscribers")[:3], "abuse_form": AbuseForm(request=request), } # details.html just returns the top half of the page for speed. The bottom # does a lot more queries we don't want on the initial page load. if request.is_ajax(): # Other add-ons/apps from the same author(s). ctx["author_addons"] = addon.authors_other_addons(app=request.APP)[:6] return render(request, "addons/impala/details-more.html", ctx) else: return render(request, "addons/impala/details.html", ctx)
def test_cron(self): eq_(GroupedRating.get(1865), None) tasks.addon_grouped_rating(1865) eq_(GroupedRating.get(1865), [(1, 0), (2, 0), (3, 0), (4, 1), (5, 0)])
def test_set(self): eq_(GroupedRating.get(1865), None) GroupedRating.set(1865) eq_(GroupedRating.get(1865), [(1, 0), (2, 0), (3, 0), (4, 1), (5, 0)])
def test_update_none(self): eq_(GroupedRating.get(1865, update_none=False), None) eq_(GroupedRating.get(1865, update_none=True), self.grouped_ratings)
def test_cron(self): eq_(GroupedRating.get(1865, update_none=False), None) tasks.addon_grouped_rating(1865) eq_(GroupedRating.get(1865, update_none=False), self.grouped_ratings)
def test_set(self): eq_(GroupedRating.get(1865, update_none=False), None) GroupedRating.set(1865) eq_(GroupedRating.get(1865, update_none=False), self.grouped_ratings)
def test_get_none(self): eq_(GroupedRating.get(3), None)
def test_cron(self): eq_(GroupedRating.get(1865), None) tasks.addon_grouped_rating(1865) eq_(GroupedRating.get(1865), [[1, 0], [2, 0], [3, 0], [4, 1], [5, 0]])
def test_set(self): eq_(GroupedRating.get(1865), None) GroupedRating.set(1865) eq_(GroupedRating.get(1865), [[1, 0], [2, 0], [3, 0], [4, 1], [5, 0]])
def rating_header(context, product, title): c = dict(context.items()) c.update(product=product, title=title, grouped_ratings=GroupedRating.get(product.id)) return c
def test_get_none(self): eq_(GroupedRating.get(3, update_none=False), None)