<commit_before>from rules.contrib.views import PermissionRequiredMixin

from django.shortcuts import redirect
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import (
    CreateView,
    DetailView,
    UpdateView,
)

from .models import Event, EventRSVP, EventComment
from .forms import EventUpdateForm, EventCommentCreateForm


class CommunityEventMixin:
    def get_object(self, queryset=None):
        obj = Event.objects.get(
            slug=self.kwargs.get('slug'), community__slug=self.kwargs.get('community_slug'))
        return obj


class EventUpdateView(LoginRequiredMixin, PermissionRequiredMixin, CommunityEventMixin, UpdateView):
    model = Event
    template_name = 'events/event_update.html'
    permission_required = 'event.can_edit'
    form_class = EventUpdateForm


class EventDetailView(CommunityEventMixin, DetailView):
    model = Event

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['comment_form'] = EventCommentCreateForm()
        return context<commit_msg>fix 500 - closes #20<commit_after>from rules.contrib.views import PermissionRequiredMixin

from django.shortcuts import redirect, get_object_or_404
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import (
    CreateView,
    DetailView,
    UpdateView,
)

from .models import Event, EventRSVP, EventComment
from .forms import EventUpdateForm, EventCommentCreateForm


class CommunityEventMixin:
    def get_object(self, queryset=None):
        return get_object_or_404(
            Event,
            slug=self.kwargs.get('slug'),
            community__slug=self.kwargs.get('community_slug'))


class EventUpdateView(LoginRequiredMixin, PermissionRequiredMixin, CommunityEventMixin, UpdateView):
    model = Event
    template_name = 'events/event_update.html'
    permission_required = 'event.can_edit'
    form_class = EventUpdateForm


class EventDetailView(CommunityEventMixin, DetailView):
    model = Event

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['comment_form'] = EventCommentCreateForm()
        return context
{'fraction_non_alphanumeric': 0.08171557562076749, 'fraction_numerical': 0.004966139954853273, 'mean_word_length': 4.365617433414044, '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': '2065715', 'n_tokens_mistral': 634, 'n_tokens_neox': 608, 'n_words': 136}