<commit_before>import jingo
from tower import ugettext_lazy as _

from api.views import addon_filter
from bandwagon.models import Collection
from .models import BlogCacheRyf


# The global registry for promo modules.  Managed through PromoModuleMeta.
registry = {}


class PromoModuleMeta(type):
    """Adds new PromoModules to the module registry."""

    def __new__(mcs, name, bases, dict_):
        cls = type.__new__(mcs, name, bases, dict_)
        if 'abstract' not in dict_:
            registry[cls.slug] = cls
        return cls


class PromoModule(object):
    """
    Base class for promo modules in the discovery pane.

    Subclasses should assign a slug and define render().  The slug is only used
    internally, so it doesn't have to really be a slug.
    """
    __metaclass__ = PromoModuleMeta
    abstract = True
    slug = None

    def __init__(self, request, platform, version):
        self.request = request
        self.platform = platform
        self.version = version

    def render(self):
        raise NotImplementedError


class RockYourFirefox(PromoModule):
    slug = 'Rock Your Firefox'

    def render(self):
        return jingo.render_to_string(
            self.request, 'discovery/modules/ryf.html',
            {'ryf': BlogCacheRyf.objects.get()})


class CollectionPromo(PromoModule):
    abstract = True
    template = 'discovery/modules/collection.html'
    title = None
    limit = 5

    def __init__(self, *args, **kw):
        super(CollectionPromo, self).__init__(*args, **kw)
        self.collection = Collection.objects.get(pk=self.pk)

    def get_addons(self):
        addons = self.collection.addons.all()
        kw = dict(addon_type='ALL', limit=6, app=self.request.APP,
                  platform=self.platform, version=self.version, shuffle=True)
        return addon_filter(addons, **kw)

    def render(self):
        c = dict(title=self.title, collection=self.collection,
                 cls=self.cls, addons=self.get_addons())
        return jingo.render_to_string(self.request, self.template, c)<commit_msg>Collection promo modules showing too many add-ons (Bug 596013)<commit_after>import jingo
from tower import ugettext_lazy as _

from api.views import addon_filter
from bandwagon.models import Collection
from .models import BlogCacheRyf


# The global registry for promo modules.  Managed through PromoModuleMeta.
registry = {}


class PromoModuleMeta(type):
    """Adds new PromoModules to the module registry."""

    def __new__(mcs, name, bases, dict_):
        cls = type.__new__(mcs, name, bases, dict_)
        if 'abstract' not in dict_:
            registry[cls.slug] = cls
        return cls


class PromoModule(object):
    """
    Base class for promo modules in the discovery pane.

    Subclasses should assign a slug and define render().  The slug is only used
    internally, so it doesn't have to really be a slug.
    """
    __metaclass__ = PromoModuleMeta
    abstract = True
    slug = None

    def __init__(self, request, platform, version):
        self.request = request
        self.platform = platform
        self.version = version

    def render(self):
        raise NotImplementedError


class RockYourFirefox(PromoModule):
    slug = 'Rock Your Firefox'

    def render(self):
        return jingo.render_to_string(
            self.request, 'discovery/modules/ryf.html',
            {'ryf': BlogCacheRyf.objects.get()})


class CollectionPromo(PromoModule):
    abstract = True
    template = 'discovery/modules/collection.html'
    title = None
    limit = 3

    def __init__(self, *args, **kw):
        super(CollectionPromo, self).__init__(*args, **kw)
        self.collection = Collection.objects.get(pk=self.pk)

    def get_addons(self):
        addons = self.collection.addons.all()
        kw = dict(addon_type='ALL', limit=self.limit, app=self.request.APP,
                  platform=self.platform, version=self.version, shuffle=True)
        return addon_filter(addons, **kw)

    def render(self):
        c = dict(title=self.title, collection=self.collection,
                 cls=self.cls, addons=self.get_addons())
        return jingo.render_to_string(self.request, self.template, c)
{'fraction_non_alphanumeric': 0.09757258448357925, 'fraction_numerical': 0.002141837220371252, 'mean_word_length': 2.9170549860205033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3678719', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1225, 'n_words': 347}