<commit_before>from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

from ..models import Shift


class ShiftForm(forms.ModelForm):
    class Meta:
        model = Shift
        exclude = ['job', ]
        widgets = {
            'begin': forms.DateTimeInput(attrs={'class': 'datetime'}),
            'end': forms.DateTimeInput(attrs={'class': 'datetime'}),
        }

    def __init__(self, *args, **kwargs):
        self.job = kwargs.pop('job')

        super(ShiftForm, self).__init__(*args, **kwargs)

    def clean(self):
        super(ShiftForm, self).clean()

        if self.cleaned_data['begin'] > self.cleaned_data['end']:
            raise ValidationError(_("The begin of the shift must be before "
                                    "the end."))<commit_msg>fixed bug: begin and end maybe not set in shiftform<commit_after>from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

from ..models import Shift


class ShiftForm(forms.ModelForm):
    class Meta:
        model = Shift
        exclude = ['job', ]
        widgets = {
            'begin': forms.DateTimeInput(attrs={'class': 'datetime'}),
            'end': forms.DateTimeInput(attrs={'class': 'datetime'}),
        }

    def __init__(self, *args, **kwargs):
        self.job = kwargs.pop('job')

        super(ShiftForm, self).__init__(*args, **kwargs)

    def clean(self):
        super(ShiftForm, self).clean()

        # this should not be necessary, however it is
        if not 'begin' in self.cleaned_data:
            raise ValidationError(_("The begin of the shift must be set."))
        if not 'end' in self.cleaned_data:
            raise ValidationError(_("The end of the shift must be set."))

        # check times
        if self.cleaned_data['begin'] > self.cleaned_data['end']:
            raise ValidationError(_("The begin of the shift must be before "
                                    "the end."))
{'fraction_non_alphanumeric': 0.1189663578742077, 'fraction_numerical': 0.0, 'mean_word_length': 2.4838709677419355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4303775', 'n_tokens_mistral': 576, 'n_tokens_neox': 554, 'n_words': 164}