<commit_before>from django.views.generic import TemplateView
from django.views import static
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.shortcuts import RequestContext
from django.conf import settings
from django.template import loader
from django.http import HttpResponse

from booki.editor.models import Book, BookiGroup
from booktype.utils.security import Security, BookSecurity, GroupSecurity
from booktype.utils.security import get_security, get_security_for_book, get_security_for_group

class BasePageView(object):
    page_title = ''
    title = ''
    
    def get_context_data(self, **kwargs):
        context = super(BasePageView, self).get_context_data(**kwargs)
        context["page_title"] = self.page_title
        context["title"] = self.title
        context["request"] = self.request

        return context

class PageView(BasePageView, TemplateView):
    pass


class SecurityMixin(object):
    AVAILABLE_BRIDGES = (Security, BookSecurity, GroupSecurity)

    def __init__(self, **kwargs):
        super(SecurityMixin, self).__init__(**kwargs)
        self.security = None

        if hasattr(self, 'SECURITY_BRIDGE'):
            # validate bridge
            if self.SECURITY_BRIDGE not in self.AVAILABLE_BRIDGES:
                raise Exception('Wrong security bridge! Available bridges: '
                                '{0}'.format(",".join([str(i) for i in self.AVAILABLE_BRIDGES])))
            self.security_bridge = self.SECURITY_BRIDGE
        else:
            self.security_bridge = Security

    def dispatch(self, request, *args, **kwargs):
        # try to create security instance
        try:
            if self.security_bridge is Security:
                self.security = get_security(request.user)
            elif self.security_bridge is BookSecurity:
                book = Book.objects.get(url_title__iexact=kwargs['bookid'])
                self.security = get_security_for_book(request.user, book)
            elif self.security_bridge is GroupSecurity:
                group = BookiGroup.objects.get(url_name=kwargs['groupid'])
                self.security = get_security_for_group(request.user, group)<commit_msg>BK-1569 Return 404 page from SecurityMixin<commit_after>from django.views.generic import TemplateView
from django.views import static
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.shortcuts import RequestContext
from django.conf import settings
from django.template import loader
from django.http import HttpResponse, Http404

from booki.editor.models import Book, BookiGroup
from booktype.utils.security import Security, BookSecurity, GroupSecurity
from booktype.utils.security import get_security, get_security_for_book, get_security_for_group

class BasePageView(object):
    page_title = ''
    title = ''
    
    def get_context_data(self, **kwargs):
        context = super(BasePageView, self).get_context_data(**kwargs)
        context["page_title"] = self.page_title
        context["title"] = self.title
        context["request"] = self.request

        return context

class PageView(BasePageView, TemplateView):
    pass


class SecurityMixin(object):
    AVAILABLE_BRIDGES = (Security, BookSecurity, GroupSecurity)

    def __init__(self, **kwargs):
        super(SecurityMixin, self).__init__(**kwargs)
        self.security = None

        if hasattr(self, 'SECURITY_BRIDGE'):
            # validate bridge
            if self.SECURITY_BRIDGE not in self.AVAILABLE_BRIDGES:
                raise Exception('Wrong security bridge! Available bridges: '
                                '{0}'.format(",".join([str(i) for i in self.AVAILABLE_BRIDGES])))
            self.security_bridge = self.SECURITY_BRIDGE
        else:
            self.security_bridge = Security

    def dispatch(self, request, *args, **kwargs):
        # try to create security instance
        try:
            if self.security_bridge is Security:
                self.security = get_security(request.user)
            elif self.security_bridge is BookSecurity:
                book = Book.objects.get(url_title__iexact=kwargs['bookid'])
                self.security = get_security_for_book(request.user, book)
            elif self.security_bridge is GroupSecurity:
                group = BookiGroup.objects.get(url_name=kwargs['groupid'])
                self.security = get_security_for_group(request.user, group)
        except (BookiGroup.DoesNotExist, Book.DoesNotExist):
            raise Http404
{'fraction_non_alphanumeric': 0.08386388583973656, 'fraction_numerical': 0.004610318331503842, 'mean_word_length': 3.028293545534925, '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': '4715775', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1225, 'n_words': 300}