<commit_before>from . import forms, models
from django.conf import settings
from django.core import urlresolvers
from django.views import generic
from features.groups import models as groups
from utils import forms as utils_forms, views as utils_views


class BaseContent(utils_views.ActionMixin, generic.CreateView):
    permission = 'content.create_content'

    def get_initial(self):
        return {
                'author': self.request.user.gestalt.pk,
                'group': self.get_group(),
                'pinned': self.request.GET.get('pinned'),
                'public': self.request.GET.get('public')}

    def get_permission_object(self):
        return None


class Article(BaseContent):
    action = 'Artikel erstellen'
    form_class = forms.Article
    menu = 'article'
    parent = 'article-index'


class Event(BaseContent):
    action = 'Ereignis erstellen'
    form_class = forms.Event
    menu = 'event'
    parent = 'event-index'


class Gallery(BaseContent):
    action = 'Galerie erstellen'
    form_class = forms.Gallery
    menu = 'gallery'
    parent = 'gallery-index'


class BaseMessage(utils_views.ActionMixin, generic.CreateView):
    action = 'Nachricht senden'
    message = 'Die Nachricht wurde versendet.'

    def get_initial(self):
        if self.request.user.is_authenticated():
            return {'recipient': self.get_recipient().pk, 'sender': self.request.user.email}
        else:
            return {'recipient': self.get_recipient().pk}

    def get_parent(self):
        return self.get_recipient()

    def get_permission_object(self):
        return self.get_recipient()


class GestaltMessage(BaseMessage):
    form_class = forms.GestaltMessage
    menu = 'gestalt'
    permission = 'entities.create_gestalt_message'

    def get_recipient(self):
        return self.get_gestalt()

<commit_msg>throw http404 if message recipient is not found<commit_after>from . import forms, models
from django.conf import settings
from django.core import urlresolvers
from django.views import generic
from django.http import Http404
from features.groups import models as groups
from utils import forms as utils_forms, views as utils_views


class BaseContent(utils_views.ActionMixin, generic.CreateView):
    permission = 'content.create_content'

    def get_initial(self):
        return {
                'author': self.request.user.gestalt.pk,
                'group': self.get_group(),
                'pinned': self.request.GET.get('pinned'),
                'public': self.request.GET.get('public')}

    def get_permission_object(self):
        return None


class Article(BaseContent):
    action = 'Artikel erstellen'
    form_class = forms.Article
    menu = 'article'
    parent = 'article-index'


class Event(BaseContent):
    action = 'Ereignis erstellen'
    form_class = forms.Event
    menu = 'event'
    parent = 'event-index'


class Gallery(BaseContent):
    action = 'Galerie erstellen'
    form_class = forms.Gallery
    menu = 'gallery'
    parent = 'gallery-index'


class BaseMessage(utils_views.ActionMixin, generic.CreateView):
    action = 'Nachricht senden'
    message = 'Die Nachricht wurde versendet.'

    def get_initial(self):
        recipient = self.get_recipient()

        if not recipient:
            raise Http404("recipient not found")

        if self.request.user.is_authenticated():
            return {'recipient': recipient.pk, 'sender': self.request.user.email}
        else:
            return {'recipient': recipient.pk}

    def get_parent(self):
        return self.get_recipient()

    def get_permission_object(self):
        return self.get_recipient()


class GestaltMessage(BaseMessage):
    form_class = forms.GestaltMessage
    menu = 'gestalt'
    permission = 'entities.create_gestalt_message'

    def get_recipient(self):
        return self.get_gestalt()


{'fraction_non_alphanumeric': 0.09782608695652174, 'fraction_numerical': 0.002329192546583851, 'mean_word_length': 3.0598739495798317, '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': '4183581', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1106, 'n_words': 276}