<commit_before>from django import forms
from models import JoinRequest

PENDING = JoinRequest.PENDING
WITHDRAWN = JoinRequest.WITHDRAWN
ACCEPTED = JoinRequest.ACCEPTED
REJECTED = JoinRequest.REJECTED


class JoinRequestForm(forms.ModelForm):
    class Meta:
        model = JoinRequest
        fields = ('message', 'state')

    DISALLOWED = {PENDING: (ACCEPTED, REJECTED),
                  WITHDRAWN: (ACCEPTED, REJECTED),
                  ACCEPTED: (PENDING, REJECTED),
                  REJECTED: (PENDING, WITHDRAWN, ACCEPTED)}

    DISALLOWED_MSG = {PENDING: "Your request has already been processed.",
                      WITHDRAWN: "You cannot alter a rejected request.",
                      ACCEPTED: "You cannot accept your own request."
                      REJECTED: "You cannot reject your own request."}

    def clean_state(self):
        if self.cleaned_data['state'] in DISALLOWED[self.initial['state']]:
            raise forms.ValidationError(
                DISALLOWED_MSG[self.cleaned_data['state']])


class JoinResponseForm(forms.ModelForm):
    class Meta:
        model = JoinRequest
        fields = ('response', 'state')

    DISALLOWED = {PENDING: (WITHDRAWN,),
                  WITHDRAWN: (PENDING, ACCEPTED, REJECTED),
                  ACCEPTED: (WITHDRAWN,),
                  REJECTED: (WITHDRAWN,)}

    DISALLOWED_MSG = {PENDING: "You cannot alter a withdrawn request.",
                      WITHDRAWN: "You cannot withdraw someone else's request.",
                      ACCEPTED: "You cannot accept a withdrawn request.",
                      REJECTED: "You cannot reject a withdrawn request."}

    def clean_state(self):
        if self.cleaned_data['state'] in DISALLOWED[self.initial['state']]:
            raise forms.ValidationError(
                DISALLOWED_MSG[self.cleaned_data['state']])<commit_msg>Changed the forms to reflect the changes to the JoinRequest model.<commit_after>from django import forms
from models import JoinRequest


class JoinHostForm(forms.ModelForm):
    class Meta:
        model = JoinRequest
        fields = ('host_message', 'host_state')


class JoinUserForm(forms.ModelForm):
    class Meta:
        model = JoinRequest
        fields = ('message', 'state')
{'fraction_non_alphanumeric': 0.09487750556792873, 'fraction_numerical': 0.0, 'mean_word_length': 2.498442367601246, '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': '2826369', 'n_tokens_mistral': 642, 'n_tokens_neox': 624, 'n_words': 177}