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 _
4
from datetime import datetime, timedelta
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 21 22 23 24 25
}


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):
Christophe Siraut's avatar
Christophe Siraut committed
26
        a = str(super(
Christophe Siraut's avatar
Christophe Siraut committed
27
            DateTimeWidgetFixed, self).value_from_datadict(data, files, name))
Christophe Siraut's avatar
Christophe Siraut committed
28
        return a
Christophe Siraut's avatar
Christophe Siraut committed
29

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')