forms.py 1.8 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 _
4
from datetime import datetime
Christophe Siraut's avatar
Christophe Siraut committed
5
from datetimewidget.widgets import DateTimeWidget
Christophe Siraut's avatar
Christophe Siraut committed
6 7 8

dateTimeOptions = {
    'weekStart': '1',
Christophe Siraut's avatar
Christophe Siraut committed
9
    'minView': '0',
10
    'minuteStep': '15',
Christophe Siraut's avatar
Christophe Siraut committed
11
    'startDate': datetime.today().date(),
Christophe Siraut's avatar
Christophe Siraut committed
12
    'todayHighlight': 'true',
Christophe Siraut's avatar
Christophe Siraut committed
13 14 15 16 17 18 19 20
}


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

21

Christophe Siraut's avatar
Christophe Siraut committed
22 23 24 25 26
class DateTimeWidgetFixed(DateTimeWidget):
    def __init__(self, **kwargs):
        super(DateTimeWidgetFixed, self).__init__(**kwargs)

    def value_from_datadict(self, data, files, name):
Christophe Siraut's avatar
Christophe Siraut committed
27
        a = str(super(
Christophe Siraut's avatar
Christophe Siraut committed
28
            DateTimeWidgetFixed, self).value_from_datadict(data, files, name))
Christophe Siraut's avatar
Christophe Siraut committed
29
        return a
Christophe Siraut's avatar
Christophe Siraut committed
30

christophe siraut's avatar
christophe siraut committed
31 32

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

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

christophe siraut's avatar
christophe siraut committed
42 43

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

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

57

christophe siraut's avatar
christophe siraut committed
58 59 60
class BulletinForm(forms.ModelForm):
    class Meta:
        model = Bulletin
61 62
        exclude = []

christophe siraut's avatar
christophe siraut committed
63 64

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