<commit_before>"""
Admin forms for ``icekit_events`` app.
"""

from django import forms

from . import models


class BaseEventRepeatsGeneratorForm(forms.ModelForm):

    class Meta:
        fields = '__all__'
        model = models.EventRepeatsGenerator

    @property
    def media(self):
        media = super(BaseEventRepeatsGeneratorForm, self).media
        media.add_js(['admin/js/event_all_day_field.js'])
        return media

    def clean(self):
        cleaned_data = super(BaseEventRepeatsGeneratorForm, self).clean()
        # Handle situation where hidden time fields in admin UI submit the
        # value "00:00:00" for `repeat_end` without a corresponding date.
        if 'repeat_end' in self.errors:
            if self.data.get(self.prefix + '-repeat_end_1') == '00:00:00' \
                    and not self.data.get(self.prefix + '-repeat_end_0'):
                cleaned_data['repeat_end'] = None
                del(self.errors['repeat_end'])
        return cleaned_data


class BaseOccurrenceForm(forms.ModelForm):

    class Meta:
        fields = '__all__'<commit_msg>Fixed an error where a repeat end without a recurrence rule would crash an event save - re #293<commit_after>"""
Admin forms for ``icekit_events`` app.
"""

from django import forms

from . import models


class BaseEventRepeatsGeneratorForm(forms.ModelForm):

    class Meta:
        fields = '__all__'
        model = models.EventRepeatsGenerator

    @property
    def media(self):
        media = super(BaseEventRepeatsGeneratorForm, self).media
        media.add_js(['admin/js/event_all_day_field.js'])
        return media

    def clean(self):
        cleaned_data = super(BaseEventRepeatsGeneratorForm, self).clean()
        # Handle situation where hidden time fields in admin UI submit the
        # value "00:00:00" for `repeat_end` without a corresponding date.
        if cleaned_data['repeat_end'] and not cleaned_data['recurrence_rule']:
            self.add_error('recurrence_rule', 'Recurrence rule must be set if a repeat end date/time is')
        if 'repeat_end' in self.errors:
            if self.data.get(self.prefix + '-repeat_end_1') == '00:00:00' \
                    and not self.data.get(self.prefix + '-repeat_end_0'):
                cleaned_data['repeat_end'] = None
                del(self.errors['repeat_end'])
        return cleaned_data


class BaseOccurrenceForm(forms.ModelForm):

    class Meta:
        fields = '__all__'
{'fraction_non_alphanumeric': 0.10012210012210013, 'fraction_numerical': 0.012617012617012617, 'mean_word_length': 2.7873651771956856, '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': '7292404', 'n_tokens_mistral': 736, 'n_tokens_neox': 706, 'n_words': 187}