<commit_before>import caching.base as caching
import jingo
import jinja2
from tower import ugettext_lazy as _

from addons.models import Addon
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 TemplatePromo(PromoModule):
    abstract = True
    template = None

    def context(self):
        return {}

    def render(self, **kw):
        r = jingo.render_to_string(self.request, self.template, self.context())
        return jinja2.Markup(r)


class RockYourFirefox(TemplatePromo):
    slug = 'Rock Your Firefox'
    template = 'discovery/modules/ryf.html'

    def context(self):
        return {'ryf': BlogCacheRyf.objects.get()}


class MonthlyPick(TemplatePromo):
    slug = 'Monthly Pick'
    template = 'discovery/modules/monthly.html'

    # TODO A bit of hardcoding here to support an alternative locale.  This
    # will all be redone with the mango bugs: http://bugzil.la/[t:mango]
    def context(self):
        return {
                'addon': Addon.objects.get(id=6416),
                'addon_de': Addon.objects.get(id=146384)
               }


class GoMobile(TemplatePromo):
    slug = 'Go Mobile'
    template = 'discovery/modules/go-mobile.html'


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

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

    def get_descriptions(self):
        return {}

    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)
        f = lambda: addon_filter(addons, **kw)
        return caching.cached_with(addons, f, repr(kw))

    def render(self, module_context='discovery'):
        c = dict(promo=self, addons=self.get_addons(),
                 module_context=module_context,
                 descriptions=self.get_descriptions())
        return jinja2.Markup(
            jingo.render_to_string(self.request, self.template, c))


class ShoppingCollection(CollectionPromo):
    slug = 'Shopping Collection'
    pk = 16651
    cls = 'shopping'
    title = _(u'Save cash and have fun with these shopping add-ons')


class WebdevCollection(CollectionPromo):
    slug = 'Webdev Collection'
    pk = 10
    cls = 'webdev'
    title = _(u'Build the perfect website')


class TesterCollection(CollectionPromo):
    slug = 'Firefox Tester Tools'
    pk = 82266
    cls = 'tester'
    title = _(u'Help test Firefox with these tools')


class StarterPack(CollectionPromo):
    slug = 'Starter Pack'
    pk = 153649
    id = 'starter'
    cls = 'promo'
    title = _(u'First time with Add-ons?')
    subtitle = _(u'Not to worry, here are three to get started.')

    def get_descriptions(self):
        return {
            2257: _(u'Translate content on the web from and into over 40 '
                    'languages.'),
            1833: _(u"Easily connect to your social networks, and share or "
                    "comment on the page you're visiting."),
            11377: _(u'A quick view to compare prices when you shop online '
                     'or search for flights.')
        }


class Fx4Collection(CollectionPromo):
    slug = 'Fx4 Collection'
    pk = 153651
    id = 'fx4-collection'
    cls = 'promo'
    title = _(u'Firefox 4 Collection')
    subtitle = _(u'Here are some great add-ons for Firefox 4.')
    linkify_title = True


class StPatricksPersonas(CollectionPromo):
    slug = 'St. Pat Personas'
    pk = 666627
    id = 'st-patricks'
    cls = 'promo'
    title = _(u'St. Patrick&rsquo;s Day Personas')
    subtitle = _(u'Decorate your browser to celebrate '
                 'St. Patrick&rsquo;s Day.')


class FxSummerCollection(CollectionPromo):
    slug = 'Fx Summer Collection'
    pk = 2128026
    id = 'fx4-collection'
    cls = 'promo'
    title = _(u'Firefox Summer Collection')
    subtitle = _(u'Here are some great add-ons for Firefox.')<commit_msg>adding thunderbird collection for tb5 release<commit_after>import caching.base as caching
import jingo
import jinja2
from tower import ugettext_lazy as _

from addons.models import Addon
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 TemplatePromo(PromoModule):
    abstract = True
    template = None

    def context(self):
        return {}

    def render(self, **kw):
        r = jingo.render_to_string(self.request, self.template, self.context())
        return jinja2.Markup(r)


class RockYourFirefox(TemplatePromo):
    slug = 'Rock Your Firefox'
    template = 'discovery/modules/ryf.html'

    def context(self):
        return {'ryf': BlogCacheRyf.objects.get()}


class MonthlyPick(TemplatePromo):
    slug = 'Monthly Pick'
    template = 'discovery/modules/monthly.html'

    # TODO A bit of hardcoding here to support an alternative locale.  This
    # will all be redone with the mango bugs: http://bugzil.la/[t:mango]
    def context(self):
        return {
                'addon': Addon.objects.get(id=6416),
                'addon_de': Addon.objects.get(id=146384)
               }


class GoMobile(TemplatePromo):
    slug = 'Go Mobile'
    template = 'discovery/modules/go-mobile.html'


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

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

    def get_descriptions(self):
        return {}

    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)
        f = lambda: addon_filter(addons, **kw)
        return caching.cached_with(addons, f, repr(kw))

    def render(self, module_context='discovery'):
        c = dict(promo=self, addons=self.get_addons(),
                 module_context=module_context,
                 descriptions=self.get_descriptions())
        return jinja2.Markup(
            jingo.render_to_string(self.request, self.template, c))


class ShoppingCollection(CollectionPromo):
    slug = 'Shopping Collection'
    pk = 16651
    cls = 'shopping'
    title = _(u'Save cash and have fun with these shopping add-ons')


class WebdevCollection(CollectionPromo):
    slug = 'Webdev Collection'
    pk = 10
    cls = 'webdev'
    title = _(u'Build the perfect website')


class TesterCollection(CollectionPromo):
    slug = 'Firefox Tester Tools'
    pk = 82266
    cls = 'tester'
    title = _(u'Help test Firefox with these tools')


class StarterPack(CollectionPromo):
    slug = 'Starter Pack'
    pk = 153649
    id = 'starter'
    cls = 'promo'
    title = _(u'First time with Add-ons?')
    subtitle = _(u'Not to worry, here are three to get started.')

    def get_descriptions(self):
        return {
            2257: _(u'Translate content on the web from and into over 40 '
                    'languages.'),
            1833: _(u"Easily connect to your social networks, and share or "
                    "comment on the page you're visiting."),
            11377: _(u'A quick view to compare prices when you shop online '
                     'or search for flights.')
        }


class Fx4Collection(CollectionPromo):
    slug = 'Fx4 Collection'
    pk = 153651
    id = 'fx4-collection'
    cls = 'promo'
    title = _(u'Firefox 4 Collection')
    subtitle = _(u'Here are some great add-ons for Firefox 4.')
    linkify_title = True


class StPatricksPersonas(CollectionPromo):
    slug = 'St. Pat Personas'
    pk = 666627
    id = 'st-patricks'
    cls = 'promo'
    title = _(u'St. Patrick&rsquo;s Day Personas')
    subtitle = _(u'Decorate your browser to celebrate '
                 'St. Patrick&rsquo;s Day.')


class FxSummerCollection(CollectionPromo):
    slug = 'Fx Summer Collection'
    pk = 2128026
    id = 'fx4-collection'
    cls = 'promo'
    title = _(u'Firefox Summer Collection')
    subtitle = _(u'Here are some great add-ons for Firefox.')

    
class ThunderbirdCollection(CollectionPromo):
    slug = 'Thunderbird Collection'
    pk = 2128303
    id = 'tb-collection'
    cls = 'promo'
    title = _(u'Thunderbird Collection')
    subtitle = _(u'Here are some great add-ons for Thunderbird.')
{'fraction_non_alphanumeric': 0.0990552533638706, 'fraction_numerical': 0.01450520087794637, 'mean_word_length': 2.7097345132743365, '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': '6026171', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3141, 'n_words': 928}