class BaseGroupForm(forms.ModelForm): slug = forms.SlugField( max_length=20, label=_("Short name"), help_text= _("a short version of the name consisting only of letters, numbers, underscores and hyphens." ), error_message= _("This value must contain only letters, numbers, underscores and hyphens." )) def __init__(self, *args, **kwargs): user = kwargs.pop( 'user', None) # pop off user arg, in case subclass doesn't use it super(BaseGroupForm, self).__init__(*args, **kwargs) def clean_slug(self): if BaseGroup.objects.filter( slug__iexact=self.cleaned_data["slug"]).count() > 0: if self.instance and self.cleaned_data[ "slug"] == self.instance.slug: pass # same instance else: raise forms.ValidationError( _("A group (network, community or project) already exists with that slug." )) return self.cleaned_data["slug"].lower() def clean_name(self): if BaseGroup.objects.filter( name__iexact=self.cleaned_data["name"]).count() > 0: if self.instance and self.cleaned_data[ "name"] == self.instance.name: pass # same instance else: raise forms.ValidationError( _("A group (network, community or project) already exists with that name." )) return self.cleaned_data["name"] def clean_welcome_email(self): self.cleaned_data['welcome_email'] = self.cleaned_data[ 'welcome_email'].strip() return self.cleaned_data['welcome_email'] class Meta: abstract = True
def clean_name(self): if BaseGroup.objects.filter(name__iexact=self.cleaned_data["name"]).count() > 0: if self.instance and self.cleaned_data["name"] == self.instance.name: pass # same instance else: raise forms.ValidationError(_("A group (network, community or project) already exists with that name.")) return self.cleaned_data["name"]
def clean_slug(self): if BaseGroup.objects.filter(slug__iexact=self.cleaned_data["slug"]).count() > 0: if self.instance and self.cleaned_data["slug"] == self.instance.slug: pass # same instance else: raise forms.ValidationError(_("A group (network, community or project) already exists with that slug.")) return self.cleaned_data["slug"].lower()
class GroupMemberForm(forms.ModelForm): user = MultipleUserField(label=_("User")) class Meta: model = GroupMember fields = ('user', 'is_admin', 'admin_title') class Media: js = (STATIC_URL + 'js/base_groups/member.js', )
def clean_name(self): if BaseGroup.objects.filter( name__iexact=self.cleaned_data["name"]).count() > 0: if self.instance and self.cleaned_data[ "name"] == self.instance.name: pass # same instance else: raise forms.ValidationError( _("A group (network, community or project) already exists with that name." )) return self.cleaned_data["name"]
def clean_slug(self): if BaseGroup.objects.filter( slug__iexact=self.cleaned_data["slug"]).count() > 0: if self.instance and self.cleaned_data[ "slug"] == self.instance.slug: pass # same instance else: raise forms.ValidationError( _("A group (network, community or project) already exists with that slug." )) return self.cleaned_data["slug"].lower()
class GroupInviteForm(forms.ModelForm): user = MultipleUserField(label=_("User")) class Meta: model = InvitationToJoinGroup fields = ('user', 'message')