コード例 #1
0
ファイル: tests.py プロジェクト: rjlardizabal/addons-server
    def test_search_tools_within_a_category(self):
        # Pretend Foxy is the only bookmarks related search add-on
        AddonCategory.objects.all().delete()
        foxy = Addon.objects.get(name__localized_string='FoxyProxy Standard')
        foxy.type = amo.ADDON_SEARCH
        foxy.save()
        bookmarks = Category.objects.get(slug='bookmarks')
        bookmarks.addoncategory_set.add(
            AddonCategory(addon=foxy, feature=False))
        bookmarks.save()

        url = reverse('browse.search-tools.rss',
                      args=('bookmarks', )) + '?sort=popular'
        r = self.client.get(url)
        assert r.status_code == 200
        doc = pq(r.content)

        assert doc('rss channel title')[0].text == (
            'Bookmarks :: Search Tools :: Add-ons for Firefox')

        link = doc('rss channel link')[0].text
        rel_link = reverse('browse.search-tools.rss',
                           args=('bookmarks', )) + '?sort=popular'
        assert link.endswith(rel_link), ('Unexpected link: %r' % link)

        assert doc('rss channel description')[0].text == (
            "Search tools relating to Bookmarks")

        assert [e.text for e in doc('rss channel item title')
                ] == (['FoxyProxy Standard 2.17'])
コード例 #2
0
ファイル: views.py プロジェクト: thundernest/addons-server
def personas(request, category=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request, filter_.qs, PAGINATE_PERSONAS_BY,
                                count=count)

    if 'sort' not in request.GET and count > MIN_COUNT_FOR_LANDING:
        template = 'browse/personas/category_landing.html'
    else:
        template = 'browse/personas/grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {'categories': categories, 'category': cat, 'addons': addons,
           'filter': filter_, 'sorting': filter_.field,
           'sort_opts': filter_.opts,
           'featured': featured, 'search_cat': 'themes',
           'is_homepage': cat is None and 'sort' not in request.GET}
    return render(request, template, ctx)
コード例 #3
0
ファイル: forms.py プロジェクト: mishin/addons-server
 def save(self):
     category = self.cleaned_data['category']
     # Clear any old categor[y|ies]
     self.addon.categories.all().delete()
     # Add new category
     AddonCategory(addon=self.addon, category_id=category).save()
     # Remove old, outdated categories cache on the model.
     del self.addon.all_categories
コード例 #4
0
ファイル: views.py プロジェクト: Alien426/addons-server
def creatured(request, category):
    TYPE = amo.ADDON_EXTENSION
    q = Category.objects.filter(application=request.APP.id, type=TYPE)
    category = get_object_or_404(q, slug=category)
    ids = AddonCategory.creatured_random(category, request.LANG)
    addons = manual_order(Addon.objects.public(), ids, pk_name='addons.id')
    return render(request, 'browse/creatured.html',
                  {'addons': addons, 'category': category,
                   'sorting': 'featured'})
コード例 #5
0
ファイル: views.py プロジェクト: thundernest/addons-server
def creatured(request, category):
    TYPE = amo.ADDON_EXTENSION
    q = Category.objects.filter(application=request.APP.id, type=TYPE)
    category = get_object_or_404(q, slug=category)
    ids = AddonCategory.creatured_random(category, request.LANG)
    addons = manual_order(Addon.objects.public(), ids, pk_name='addons.id')
    return render(request, 'browse/creatured.html',
                  {'addons': addons, 'category': category,
                   'sorting': 'featured'})
コード例 #6
0
 def save(self):
     category_slug = self.cleaned_data['category']
     # Clear any old categor[y|ies]
     AddonCategory.objects.filter(addon=self.addon).delete()
     # Add new categor[y|ies]
     for app in CATEGORIES.keys():
         category = CATEGORIES[app].get(self.addon.type,
                                        {}).get(category_slug, None)
         if category:
             AddonCategory(addon=self.addon, category_id=category.id).save()
     # Remove old, outdated categories cache on the model.
     del self.addon.all_categories
コード例 #7
0
def personas(request, category=None, template=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    if filter_.field == 'up-and-coming':
        # Almost hardcoding the number of element because performing
        # `filter_.qs.count()` is a performance killer. We're still
        # verifying the `base.count()` for the template switch below.
        base_count = base.count()
        count = (base_count if base_count < MIN_COUNT_FOR_LANDING else
                 PAGINATE_PERSONAS_BY * settings.PERSONA_DEFAULT_PAGES)
    else:
        # Pass the count from base instead of letting it come from
        # filter_.qs.count() since that would join against personas.
        count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request,
                                filter_.qs,
                                PAGINATE_PERSONAS_BY,
                                count=count)

    if ('sort' not in request.GET
            and ((request.MOBILE and not cat) or
                 (not request.MOBILE and count > MIN_COUNT_FOR_LANDING))):
        template += 'category_landing.html'
    else:
        template += 'grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {
        'categories': categories,
        'category': cat,
        'addons': addons,
        'filter': filter_,
        'sorting': filter_.field,
        'sort_opts': filter_.opts,
        'featured': featured,
        'search_cat': 'themes',
        'is_homepage': cat is None and 'sort' not in request.GET
    }
    return render(request, template, ctx)
コード例 #8
0
ファイル: forms.py プロジェクト: gregglind/addons-server
    def save(self, addon):
        application = self.cleaned_data.get('application')
        categories_new = self.cleaned_data['categories']
        categories_old = [cats for app, cats in addon.app_categories if
                          (app and application and app.id == application)
                          or (not app and not application)]
        if categories_old:
            categories_old = categories_old[0]

        # Add new categories.
        for c in set(categories_new) - set(categories_old):
            AddonCategory(addon=addon, category=c).save()

        # Remove old categories.
        for c in set(categories_old) - set(categories_new):
            AddonCategory.objects.filter(addon=addon, category=c).delete()
コード例 #9
0
ファイル: views.py プロジェクト: Alien426/addons-server
def personas(request, category=None, template=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    if filter_.field == 'up-and-coming':
        # Almost hardcoding the number of element because performing
        # `filter_.qs.count()` is a performance killer. We're still
        # verifying the `base.count()` for the template switch below.
        base_count = base.count()
        count = (base_count if base_count < MIN_COUNT_FOR_LANDING
                 else PAGINATE_PERSONAS_BY * settings.PERSONA_DEFAULT_PAGES)
    else:
        # Pass the count from base instead of letting it come from
        # filter_.qs.count() since that would join against personas.
        count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request, filter_.qs, PAGINATE_PERSONAS_BY,
                                count=count)

    if ('sort' not in request.GET and (
            (request.MOBILE and not cat) or
            (not request.MOBILE and count > MIN_COUNT_FOR_LANDING))):
        template += 'category_landing.html'
    else:
        template += 'grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {'categories': categories, 'category': cat, 'addons': addons,
           'filter': filter_, 'sorting': filter_.field,
           'sort_opts': filter_.opts,
           'featured': featured, 'search_cat': 'themes',
           'is_homepage': cat is None and 'sort' not in request.GET}
    return render(request, template, ctx)
コード例 #10
0
    def save(self, addon):
        application = self.cleaned_data.get('application')
        categories_new = [c.id for c in self.cleaned_data['categories']]
        categories_old = [
            c.id for c in
            addon.app_categories.get(amo.APP_IDS[application], [])]

        # Add new categories.
        for c_id in set(categories_new) - set(categories_old):
            AddonCategory(addon=addon, category_id=c_id).save()

        # Remove old categories.
        for c_id in set(categories_old) - set(categories_new):
            AddonCategory.objects.filter(
                addon=addon, category_id=c_id).delete()

        # Remove old, outdated categories cache on the model.
        del addon.all_categories
コード例 #11
0
    def save(self, commit=False):
        data = self.cleaned_data
        addon = Addon.objects.create(slug=data.get('slug'),
                                     status=amo.STATUS_PENDING,
                                     type=amo.ADDON_PERSONA)
        addon.name = {'en-US': data['name']}
        if data.get('description'):
            addon.description = data['description']
        addon._current_version = Version.objects.create(addon=addon,
                                                        version='0')
        addon.save()

        # Create Persona instance.
        p = Persona()
        p.persona_id = 0
        p.addon = addon
        p.header = 'header.png'
        if data['footer_hash']:
            p.footer = 'footer.png'
        if data['accentcolor']:
            p.accentcolor = data['accentcolor'].lstrip('#')
        if data['textcolor']:
            p.textcolor = data['textcolor'].lstrip('#')
        p.license = data['license']
        p.submit = datetime.now()
        user = self.request.user
        p.author = user.username
        p.display_username = user.name
        p.save()

        # Save header, footer, and preview images.
        save_theme.delay(data['header_hash'], data['footer_hash'], addon)

        # Save user info.
        addon.addonuser_set.create(user=user, role=amo.AUTHOR_ROLE_OWNER)

        # Save tags.
        for t in data['tags']:
            Tag(tag_text=t).save_tag(addon)

        # Save categories.
        AddonCategory(addon=addon, category=data['category']).save()

        return addon
コード例 #12
0
    def save(self, addon):
        application = self.cleaned_data.get('application')
        categories_new = [c.id for c in self.cleaned_data['categories']]
        categories_old = [
            c.id for c in
            addon.app_categories.get(amo.APP_IDS[application].short, [])]

        # Add new categories.
        for c_id in set(categories_new) - set(categories_old):
            AddonCategory(addon=addon, category_id=c_id).save()

        # Remove old categories.
        for c_id in set(categories_old) - set(categories_new):
            AddonCategory.objects.filter(
                addon=addon, category_id=c_id).delete()

        # Remove old, outdated categories cache on the model.
        del addon.all_categories

        # Make sure the add-on is properly re-indexed
        addons_tasks.index_addons.delay([addon.id])
コード例 #13
0
ファイル: views.py プロジェクト: Alien426/addons-server
 def __init__(self, request, base, category, key, default):
     self.category = category
     self.ids = AddonCategory.creatured_random(category, request.LANG)
     super(CategoryLandingFilter, self).__init__(request, base, key,
                                                 default)
コード例 #14
0
ファイル: views.py プロジェクト: thundernest/addons-server
 def __init__(self, request, base, category, key, default):
     self.category = category
     self.ids = AddonCategory.creatured_random(category, request.LANG)
     super(CategoryLandingFilter, self).__init__(request, base, key,
                                                 default)