forms.py 1.79 KB
Newer Older
christophe siraut's avatar
christophe siraut committed
1
from django import forms
Christophe Siraut's avatar
Christophe Siraut committed
2
from .models import UserProfile, Poll, Choice, Bulletin, Vote
Christophe Siraut's avatar
Christophe Siraut committed
3
from django.utils.translation import ugettext_lazy as _
Christophe Siraut's avatar
Christophe Siraut committed
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
from datetimewidget.widgets import DateTimeWidget
from datetime import datetime

dateTimeOptions = {
    'weekStart': '1',
    'startView': '3',
    'minView': '1',
    'startDate': datetime.today().date(),
    'autoclose': 'true',
    'todayHighlight': 'true'
}


class UserProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('email_notifications',)

class DateTimeWidgetFixed(DateTimeWidget):
    def __init__(self, **kwargs):
        super(DateTimeWidgetFixed, self).__init__(**kwargs)

    def value_from_datadict(self, data, files, name):
        return str(super(
            DateTimeWidgetFixed, self).value_from_datadict(data, files, name))

christophe siraut's avatar
christophe siraut committed
30
31

class PollForm(forms.ModelForm):
Christophe Siraut's avatar
Christophe Siraut committed
32
33
34
35
36
    title = forms.CharField(label=_('Title'))
    description = forms.CharField(
        widget=forms.Textarea,
        label=_('Description'))

christophe siraut's avatar
christophe siraut committed
37
38
    class Meta:
        model = Poll
Christophe Siraut's avatar
Christophe Siraut committed
39
40
        fields = ('title', 'description')

christophe siraut's avatar
christophe siraut committed
41
42

class ChoiceForm(forms.ModelForm):
Christophe Siraut's avatar
Cleanup    
Christophe Siraut committed
43
    choice = forms.DateTimeField(
Christophe Siraut's avatar
Christophe Siraut committed
44
45
46
47
        widget=DateTimeWidgetFixed(
            options=dateTimeOptions)
    )

christophe siraut's avatar
christophe siraut committed
48
49
    class Meta:
        model = Choice
Christophe Siraut's avatar
Christophe Siraut committed
50
51
52
53
54
        #widgets = {
        #  'choice': DateTimeWidget(
        #       attrs={'id': '666'},
        #       options=dateTimeOptions)}
        exclude = ('poll', 'votecount')
christophe siraut's avatar
christophe siraut committed
55
56
57
58
59
60

class BulletinForm(forms.ModelForm):
    class Meta:
        model = Bulletin

class VoteForm(forms.ModelForm):
Christophe Siraut's avatar
Cleanup    
Christophe Siraut committed
61
62
63
64
65
    comment = forms.CharField(
        required=False,
        max_length=80,
        widget=forms.TextInput(attrs={'class':'comment'})
        )
christophe siraut's avatar
christophe siraut committed
66
67
68
69
70
    choice = forms.CharField()
    class Meta:
        model = Vote
        fields = ('choice','voice','comment')