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

dateTimeOptions = {
    'weekStart': '1',
9 10
    #'minView': '1',
    'minuteStep': '15',
Christophe Siraut's avatar
Christophe Siraut committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    'startDate': datetime.today().date(),
    '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
29 30

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

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

christophe siraut's avatar
christophe siraut committed
40 41

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

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

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

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