summaryrefslogtreecommitdiffstats
path: root/hyperkitty/views/forms.py
blob: fc885c8d6c33d09ba61a38525b90a9d2bfe7d114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from django import forms
from django.core import validators
from django.contrib.auth.models import User

def isValidUsername(username):
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            return
        raise validators.ValidationError('The username "%s" is already taken.' % username)

class RegistrationForm(forms.Form):

    username =  forms.CharField(label='username', help_text=None,
                widget=forms.TextInput(
                    attrs={'placeholder': 'username...'}
                    ), required = True, validators=[isValidUsername]
                )

    email     = forms.EmailField(required=True)

    password1 = forms.CharField(widget=forms.PasswordInput)

    password2 = forms.CharField(widget=forms.PasswordInput)

    def save(self, new_user_data):
        u = User.objects.create_user(new_user_data['username'],
                                     new_user_data['email'],
                                     new_user_data['password1'])
        u.is_active = True
        u.save()
        return u


class AddTagForm(forms.Form):
    tag =  forms.CharField(label='', help_text=None,
                widget=forms.TextInput(
                    attrs={'placeholder': 'Add a tag...'}
                    )
                )
    from_url = forms.CharField(widget=forms.HiddenInput, required=False)

class SearchForm(forms.Form):
    target =  forms.CharField(label='', help_text=None,
                widget=forms.Select(
                    choices=(('Subject', 'Subject'),
                            ('Content', 'Content'),
                            ('SubjectContent', 'Subject & Content'),
                            ('From', 'From'))
                    )
                )

    keyword = forms.CharField(max_length=100,label='', help_text=None,
                widget=forms.TextInput(
                    attrs={'placeholder': 'Search this list.'}
                    )
                )