<commit_before>from django import forms
from events.models import Event, City

class EventForm(forms.ModelForm):
   city = forms.ModelChoiceField(City.objects.all(), empty_label=None, label="Ville")

   class Meta:
        model = Event
        exclude = ('submission_time', 'updated_time', 'decision_time',
                   'moderator', 'moderated', 'latitude', 'longitude')
<commit_msg>Validate entered dates in Event form<commit_after># -*- encoding:utf-8 -*-
from django import forms
from events.models import Event, City
from django.forms.util import ErrorList
from datetime import datetime

class EventForm(forms.ModelForm):
    city = forms.ModelChoiceField(City.objects.all(), empty_label=None, label="Ville")

    class Meta:
      model = Event
      exclude = ('submission_time', 'updated_time', 'decision_time',
                 'moderator', 'moderated', 'latitude', 'longitude')

    def clean(self):
      cleaned_data = self.cleaned_data
      start_time = cleaned_data.get("start_time")
      end_time = cleaned_data.get("end_time")

      if start_time >= end_time:
        msg = u"L'évènement ne peut se terminer avant son début"
        self._errors["start_time"] = ErrorList([msg])
        self._errors["end_time"] = ErrorList([msg])

        del cleaned_data["start_time"]
        del cleaned_data["end_time"]

      elif start_time < datetime.today():
        msg = u"Seul les évènements à venir sont acceptés"
        self._errors["start_time"] = ErrorList([msg])

        del cleaned_data["start_time"]

      return cleaned_data
{'fraction_non_alphanumeric': 0.11639871382636656, 'fraction_numerical': 0.0006430868167202572, 'mean_word_length': 3.471264367816092, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '755168', 'n_tokens_mistral': 461, 'n_tokens_neox': 447, 'n_words': 114}