<commit_before>import datetime

from django.views.generic import ListView
from django.views.generic.base import TemplateResponseMixin
from django.views.generic.edit import CreateView, ProcessFormView, ModelFormMixin
from django.contrib import messages

from meetings.models import (Meeting,
                             Topic,
                             Presentor)

from meetings.models import RSVP as RSVPModel

from meetings.forms import TopicForm, RSVPForm

class PastMeetings(ListView):
    template_name = 'meetings/past_meetings.html'
    queryset = Meeting.objects.filter(when__lt = datetime.datetime.now() - datetime.timedelta(hours = 3))

class ProposeTopic(CreateView):
    template_name = 'meetings/propose_topic.html'
    form_class = TopicForm
    success_url = '/'

    def get_form_kwargs(self):
        kwargs = super(ProposeTopic, self).get_form_kwargs()
        kwargs.update({'request':self.request})
        return kwargs
    
    def post(self, request, *args, **kwargs):
        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            # Set message
            messages.success(request, 'Topic has been submitted.')
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

class MyTopics(ListView):
    template_name = 'meetings/my_topics.html'

    def get_queryset(self):
        try:
            presentor = Presentor.objects.filter(user = self.request.user)
        except Presentor.DoesNotExist:
            return Topic.objects.none()

        return Topic.objects.filter(presentor = presentor)


class RSVP(ProcessFormView, ModelFormMixin, TemplateResponseMixin):
    http_method_names = ['post']
    form_class = RSVPForm
    success_url = '/'
    template_name = 'meetings/_rsvp_form_response.html'
    
    def get_form_kwargs(self):
        kwargs = super(RSVP, self).get_form_kwargs()
        kwargs.update({'request':self.request})

        if not kwargs.get('instance', False) and self.request.user.is_authenticated():
            try:
                meeting = Meeting.objects.get(pk = self.request.POST['meeting'])
                kwargs['instance'] = RSVPModel.objects.get(user = self.request.user, meeting = meeting)
            except RSVPModel.DoesNotExist:
                pass

        return kwargs

        
    def form_invalid(self, form):
        import pdb; pdb.set_trace();

    def post(self, request, *args, **kwargs):
        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            # Set message
            messages.success(request, 'RSVP Successful.')
            return self.form_valid(form)
        else:
            return self.form_invalid(form)


class PastTopics(ListView):
    context_object_name = 'topics'
    template_name = 'meetings/past_topics.html'
    queryset = Topic.objects.filter(meeting__when__lt = datetime.date.today(), approved = True)<commit_msg>No reason to import pdb<commit_after>import datetime

from django.views.generic import ListView
from django.views.generic.base import TemplateResponseMixin
from django.views.generic.edit import CreateView, ProcessFormView, ModelFormMixin
from django.contrib import messages

from meetings.models import (Meeting,
                             Topic,
                             Presentor)

from meetings.models import RSVP as RSVPModel

from meetings.forms import TopicForm, RSVPForm

class PastMeetings(ListView):
    template_name = 'meetings/past_meetings.html'
    queryset = Meeting.objects.filter(when__lt = datetime.datetime.now() - datetime.timedelta(hours = 3))

class ProposeTopic(CreateView):
    template_name = 'meetings/propose_topic.html'
    form_class = TopicForm
    success_url = '/'

    def get_form_kwargs(self):
        kwargs = super(ProposeTopic, self).get_form_kwargs()
        kwargs.update({'request':self.request})
        return kwargs
    
    def post(self, request, *args, **kwargs):
        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            # Set message
            messages.success(request, 'Topic has been submitted.')
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

class MyTopics(ListView):
    template_name = 'meetings/my_topics.html'

    def get_queryset(self):
        try:
            presentor = Presentor.objects.filter(user = self.request.user)
        except Presentor.DoesNotExist:
            return Topic.objects.none()

        return Topic.objects.filter(presentor = presentor)


class RSVP(ProcessFormView, ModelFormMixin, TemplateResponseMixin):
    http_method_names = ['post']
    form_class = RSVPForm
    success_url = '/'
    template_name = 'meetings/_rsvp_form_response.html'
    
    def get_form_kwargs(self):
        kwargs = super(RSVP, self).get_form_kwargs()
        kwargs.update({'request':self.request})

        if not kwargs.get('instance', False) and self.request.user.is_authenticated():
            try:
                meeting = Meeting.objects.get(pk = self.request.POST['meeting'])
                kwargs['instance'] = RSVPModel.objects.get(user = self.request.user, meeting = meeting)
            except RSVPModel.DoesNotExist:
                pass

        return kwargs

    def post(self, request, *args, **kwargs):
        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            # Set message
            messages.success(request, 'RSVP Successful.')
            return self.form_valid(form)
        else:
            return self.form_invalid(form)


class PastTopics(ListView):
    context_object_name = 'topics'
    template_name = 'meetings/past_topics.html'
    queryset = Topic.objects.filter(meeting__when__lt = datetime.date.today(), approved = True)
{'fraction_non_alphanumeric': 0.09682776947350938, 'fraction_numerical': 0.0003321707357581797, 'mean_word_length': 2.685434516523868, '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': '6322394', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1720, 'n_words': 357}