<commit_before>from django.core.urlresolvers import reverse_lazy
from django.views.decorators.cache import never_cache

from .decorators import participant_required


class PrivateMixin(object):
    """
    Require participant status and never cache this view.
    """
    @classmethod
    def as_view(cls, **initkwargs):
        view = super(PrivateMixin, cls).as_view(**initkwargs)

        view = participant_required(view)
        view = never_cache(view)

        return view


class NeverCacheMixin(object):
    """
    Never cache this view.
    """
    @classmethod
    def as_view(cls, **initkwargs):
        view = super(NeverCacheMixin, cls).as_view(**initkwargs)

        view = never_cache(view)

        return view


class LargePanelMixin(object):
    """
    Add panel width and offset to this view's context.
    """
    def get_context_data(self, **kwargs):
        context = super(LargePanelMixin, self).get_context_data(**kwargs)

        context.update({
            'panel_width': 8,
            'panel_offset': 2,
        })

        return context


class UserSocialAuthUserData(object):
    """
    Implements methods for UserData models that use Python Social Auth to
    connect users.
    """

    def __init__(self, provider):
        self.provider = provider

    def __unicode__(self):
        return '<UserSocialAuthUserData:{}>'.format(self.provider)

    @property
    def href_connect(self):
        return reverse_lazy('social:begin', args=(self.provider,))

    @property
    def href_next(self):
        return reverse_lazy('activities:{}:finalize-import'
                            .format(self.provider))

    @property
    def retrieval_url(self):
        return reverse_lazy('activities:{}:request-data-retrieval'
                            .format(self.provider))

    @property
    def is_connected(self):
        # filter in Python to benefit from prefetched data
        return len([s for s in self.user.social_auth.all()
                    if s.provider == self.provider]) > 0

    def disconnect(self):
        self.user.social_auth.filter(provider=self.provider).delete()

    def get_retrieval_params(self):<commit_msg>🐛 fix fixture and model cases<commit_after>from django.core.urlresolvers import reverse_lazy
from django.views.decorators.cache import never_cache

from .decorators import participant_required


class PrivateMixin(object):
    """
    Require participant status and never cache this view.
    """
    @classmethod
    def as_view(cls, **initkwargs):
        view = super(PrivateMixin, cls).as_view(**initkwargs)

        view = participant_required(view)
        view = never_cache(view)

        return view


class NeverCacheMixin(object):
    """
    Never cache this view.
    """
    @classmethod
    def as_view(cls, **initkwargs):
        view = super(NeverCacheMixin, cls).as_view(**initkwargs)

        view = never_cache(view)

        return view


class LargePanelMixin(object):
    """
    Add panel width and offset to this view's context.
    """
    def get_context_data(self, **kwargs):
        context = super(LargePanelMixin, self).get_context_data(**kwargs)

        context.update({
            'panel_width': 8,
            'panel_offset': 2,
        })

        return context


class UserSocialAuthUserData(object):
    """
    Implements methods for UserData models that use Python Social Auth to
    connect users.
    """

    # TODO: when this is no longer used as a model mixin:
    # 1. remove hasattr check
    # 2. remove default None parameter
    def __init__(self, provider=None):
        if not hasattr(self, 'provider'):
            self.provider = provider

    def __unicode__(self):
        return '<UserSocialAuthUserData:{}>'.format(self.provider)

    @property
    def href_connect(self):
        return reverse_lazy('social:begin', args=(self.provider,))

    @property
    def href_next(self):
        return reverse_lazy('activities:{}:finalize-import'
                            .format(self.provider))

    @property
    def retrieval_url(self):
        return reverse_lazy('activities:{}:request-data-retrieval'
                            .format(self.provider))

    @property
    def is_connected(self):
        # filter in Python to benefit from prefetched data
        return len([s for s in self.user.social_auth.all()
                    if s.provider == self.provider]) > 0

    def disconnect(self):
        self.user.social_auth.filter(provider=self.provider).delete()

    def get_retrieval_params(self):
{'fraction_non_alphanumeric': 0.10202732481269282, 'fraction_numerical': 0.0017628911414720142, 'mean_word_length': 2.6516492357200323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2707335', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1258, 'n_words': 316}