Exemplo n.º 1
0
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
Exemplo n.º 2
0
    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"]
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
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', )
Exemplo n.º 5
0
    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"]
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
class GroupInviteForm(forms.ModelForm):
    user = MultipleUserField(label=_("User"))

    class Meta:
        model = InvitationToJoinGroup
        fields = ('user', 'message')