<commit_before>from datetime import datetime

from django import forms

from news.forms import MaterialFileWidget

from .models import Profile


class ProfileSearchForm(forms.Form):
    name = forms.CharField(max_length=200)


class ProfileForm(forms.ModelForm):
    image = forms.FileField(required=False, widget=MaterialFileWidget)

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user", None)
        super(ProfileForm, self).__init__(*args, **kwargs)

    def clean(self):
        cleaned_data = super().clean()
        has_ongoing_or_future_reservations = self.user.reservations.filter(
            end__gt=datetime.now()
        ).exists()
        if cleaned_data["phone_number"] is None and has_ongoing_or_future_reservations:
            self.add_error(
                "phone_number",
                "Du kan ikke fjerne telefonnummer med pågående eller fremtidige reservasjoner",
            )

    class Meta:
        model = Profile
        fields = [
            "image",
            "study",
            "show_email",
            "social_discord",
            "social_steam",
            "social_battlenet",
            "social_git",
            "allergi_gluten",
            "allergi_vegetar",
            "allergi_vegan",
            "allergi_annet",
            "limit_social",
            "phone_number",
        ]<commit_msg>Add 24 hour waiting time for removing phone number after reservation<commit_after>from datetime import datetime, timedelta

from django import forms

from news.forms import MaterialFileWidget

from .models import Profile


class ProfileSearchForm(forms.Form):
    name = forms.CharField(max_length=200)


class ProfileForm(forms.ModelForm):
    image = forms.FileField(required=False, widget=MaterialFileWidget)

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user", None)
        super(ProfileForm, self).__init__(*args, **kwargs)

    def clean(self):
        cleaned_data = super().clean()
        has_recent_or_future_reservations = self.user.reservations.filter(
            end__gt=datetime.now() - timedelta(days=1)
        ).exists()
        if cleaned_data["phone_number"] is None and has_recent_or_future_reservations:
            self.add_error(
                "phone_number",
                "Du kan ikke fjerne telefonnummer med nylig gjennomførte (siste 24 timer), pågående eller fremtidige "
                "reservasjoner",
            )

    class Meta:
        model = Profile
        fields = [
            "image",
            "study",
            "show_email",
            "social_discord",
            "social_steam",
            "social_battlenet",
            "social_git",
            "allergi_gluten",
            "allergi_vegetar",
            "allergi_vegan",
            "allergi_annet",
            "limit_social",
            "phone_number",
        ]
{'fraction_non_alphanumeric': 0.0945100764419736, 'fraction_numerical': 0.003822098679638638, 'mean_word_length': 2.20958751393534, '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': '1836297', 'n_tokens_mistral': 843, 'n_tokens_neox': 822, 'n_words': 175}