<commit_before># -*- coding: utf-8 -*-

from django.views.decorators.cache import cache_page
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_unicode
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.core.mail import EmailMessage
from django.utils import simplejson
from django.shortcuts import render_to_response, get_object_or_404
from django.template.loader import render_to_string
from django.template import RequestContext, loader
from django.contrib import messages
from django.db.utils import IntegrityError
from django.utils.decorators import method_decorator
from superview.views import SuperView as View


from greenmine import permissions
from greenmine.middleware import PermissionDeniedException

class GenericView(View):
    """ Generic view with some util methods. """

    def render_to_ok(self, context={}):
        response = {'valid': True, 'errors': []}
        response.update(context)
        return self.render_json(response, ok=True)

    def render_to_error(self, context={}):
        response = {'valid': False, 'errors': []}
        response.update(context)
        return self.render_json(response, ok=False)

    def redirect_referer(self, msg=None):
        if msg is not None:
            messages.info(self.request, msg)

        referer = self.request.META.get('HTTP_REFERER', '/')
        return self.render_redirect(referer)

    def check_role(self, user, project, perms, exception=PermissionDeniedException):
        ok = permissions.has_perms(self.request.user, project, perms)

        if exception is not None:   
            raise exception()

        return ok<commit_msg>Bug fixes on generic view. Related with permissions.<commit_after># -*- coding: utf-8 -*-

from django.views.decorators.cache import cache_page
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_unicode
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.core.mail import EmailMessage
from django.utils import simplejson
from django.shortcuts import render_to_response, get_object_or_404
from django.template.loader import render_to_string
from django.template import RequestContext, loader
from django.contrib import messages
from django.db.utils import IntegrityError
from django.utils.decorators import method_decorator
from superview.views import SuperView as View


from greenmine import permissions
from greenmine.middleware import PermissionDeniedException

class GenericView(View):
    """ Generic view with some util methods. """

    def render_to_ok(self, context={}):
        response = {'valid': True, 'errors': []}
        response.update(context)
        return self.render_json(response, ok=True)

    def render_to_error(self, context={}):
        response = {'valid': False, 'errors': []}
        response.update(context)
        return self.render_json(response, ok=False)

    def redirect_referer(self, msg=None):
        if msg is not None:
            messages.info(self.request, msg)

        referer = self.request.META.get('HTTP_REFERER', '/')
        return self.render_redirect(referer)

    def check_role(self, user, project, perms, exception=PermissionDeniedException):
        ok = permissions.has_perms(user, project, perms)
        if exception is not None and not ok:
            raise exception()
        return ok
{'fraction_non_alphanumeric': 0.08406593406593407, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 4.099439775910364, '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': '2738221', 'n_tokens_mistral': 997, 'n_tokens_neox': 968, 'n_words': 295}