示例#1
0
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 = 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_denied(),
        'grouped_ratings': GroupedRating.get(addon.id),
        'review_form': RatingForm(),
        'reviews': Rating.without_replies.all().filter(
            addon=addon, is_latest=True).exclude(body=None),
        'get_replies': Rating.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)
示例#2
0
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 = 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_denied(),
        'grouped_ratings': GroupedRating.get(addon.id),
        'review_form': RatingForm(),
        'reviews': Rating.without_replies.all().filter(
            addon=addon, is_latest=True).exclude(body=None),
        'get_replies': Rating.get_replies,
        'collections': collections[: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)
示例#3
0
 def test_update_none(self):
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
     assert GroupedRating.get(self.addon.pk, update_none=True) == (
         self.expected_grouped_rating)
示例#4
0
 def test_cron(self):
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
     tasks.addon_grouped_rating(self.addon.pk)
     assert GroupedRating.get(self.addon.pk, update_none=False) == (
         self.expected_grouped_rating)
示例#5
0
 def test_get_unknown_addon_id(self):
     assert GroupedRating.get(3, update_none=False) is None
     assert GroupedRating.get(3) == [(1, 0), (2, 0), (3, 0), (4, 0), (5, 0)]
示例#6
0
 def test_update_none(self):
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
     assert GroupedRating.get(
         self.addon.pk, update_none=True) == (self.expected_grouped_rating)
示例#7
0
 def test_get_unknown_addon_id(self):
     assert GroupedRating.get(3, update_none=False) is None
     assert GroupedRating.get(3) == [(1, 0), (2, 0), (3, 0), (4, 0), (5, 0)]
示例#8
0
 def test_delete_grouped_rating_on_save(self):
     # post_save() -> addon_rating_aggregates() -> GroupedRating.delete()
     self.test_set()
     GroupedRating.delete(self.addon.pk)
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
示例#9
0
 def test_delete_grouped_rating_on_save(self):
     # post_save() -> addon_rating_aggregates() -> GroupedRating.delete()
     self.test_set()
     GroupedRating.delete(self.addon.pk)
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
 def test_cron(self):
     assert GroupedRating.get(self.addon.pk, update_none=False) is None
     tasks.addon_grouped_rating(self.addon.pk)
     assert GroupedRating.get(
         self.addon.pk, update_none=False) == (self.expected_grouped_rating)