<commit_before># -*- encoding: utf-8 -*
import json

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.db import IntegrityError, models
from django.db.models.aggregates import Sum
from django.template.loader import render_to_string
from django.http import HttpResponse, HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _

from vanilla import CreateView, ListView, UpdateView, DetailView
from djqscsv import render_to_csv_response

from .models import Event, Proposal, Vote
from .forms import (EventForm, ProposalForm)


class BaseEventView(object):
    model = Event
    form_class = EventForm
    lookup_field = 'slug'


class ListEvents(BaseEventView, ListView):
    template_name = 'event/event_list.html'
    queryset = Event.objects.published_ones()

    def get_context_data(self, **kwargs):
        context = super(ListEvents, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated():
            event_list = Event.objects.filter(
                models.Q(is_published=True) |
                models.Q(author=self.request.user))
            context.update(event_list=event_list)
        return context


class CreateEvent(BaseEventView, CreateView):
    template_name = 'event/event_form.html'

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.author = self.request.user
        self.object.save()
        self.send_event_creation_email()
        messages.success(self.request, _(u'Event created.'))
        return HttpResponseRedirect(self.get_success_url())

    def send_event_creation_email(self):
        import ipdb; ipdb.set_trace()
        event = self.object
        context = {'event_title': event.title}
        message = render_to_string('mailing/event_created.txt', context)
        subject = 'Your event is ready to receive proposals'
        send_mail(subject, message, settings.NO_REPLY_EMAIL, [event.author.email])


    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):<commit_msg>Deadly forgotten ipdb<commit_after># -*- encoding: utf-8 -*
import json

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.db import IntegrityError, models
from django.db.models.aggregates import Sum
from django.template.loader import render_to_string
from django.http import HttpResponse, HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _

from vanilla import CreateView, ListView, UpdateView, DetailView
from djqscsv import render_to_csv_response

from .models import Event, Proposal, Vote
from .forms import (EventForm, ProposalForm)


class BaseEventView(object):
    model = Event
    form_class = EventForm
    lookup_field = 'slug'


class ListEvents(BaseEventView, ListView):
    template_name = 'event/event_list.html'
    queryset = Event.objects.published_ones()

    def get_context_data(self, **kwargs):
        context = super(ListEvents, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated():
            event_list = Event.objects.filter(
                models.Q(is_published=True) |
                models.Q(author=self.request.user))
            context.update(event_list=event_list)
        return context


class CreateEvent(BaseEventView, CreateView):
    template_name = 'event/event_form.html'

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.author = self.request.user
        self.object.save()
        self.send_event_creation_email()
        messages.success(self.request, _(u'Event created.'))
        return HttpResponseRedirect(self.get_success_url())

    def send_event_creation_email(self):
        event = self.object
        context = {'event_title': event.title}
        message = render_to_string('mailing/event_created.txt', context)
        subject = 'Your event is ready to receive proposals'
        send_mail(subject, message, settings.NO_REPLY_EMAIL, [event.author.email])


    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
{'fraction_non_alphanumeric': 0.08632478632478632, 'fraction_numerical': 0.00042735042735042735, 'mean_word_length': 3.922187171398528, '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': '2521542', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1303, 'n_words': 320}