~mhall119/loco-team-portal/686268

« back to all changes in this revision

Viewing changes to loco_directory/meetings/forms.py

  • Committer: Chris Johnston
  • Date: 2011-01-05 14:45:26 UTC
  • mfrom: (344.5.7 627492)
  • Revision ID: chrisjohnston@ubuntu.com-20110105144526-0tcspreyy9s31ile
Fixes bug 686264 and bug 627492. Props Ronnie

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
from models import BaseMeeting, TeamMeeting
8
8
from common.forms import RenderableMixin
 
9
from userprofiles.models import UserProfile
9
10
 
10
11
import pytz
11
12
 
38
39
        self.fields['date_begin'].widget = forms.SplitDateTimeWidget()
39
40
        self.fields['date_end'].widget = forms.SplitDateTimeWidget()
40
41
        
 
42
        
41
43
    def clean(self):
42
44
        begin = self.cleaned_data.get('date_begin')
43
45
        end = self.cleaned_data.get('date_end')
44
46
        if begin and end and begin > end:
45
47
            raise forms.ValidationError("Meetings can not end before they start.")
46
48
        return self.cleaned_data
 
49
        
47
50
 
48
51
class TeamMeetingForm(BaseMeetingForm):
49
52
    """ 
52
55
    class Meta(BaseMeetingForm.Meta):
53
56
        model = TeamMeeting
54
57
        exclude = ('teams', 'date_created')
 
58
        
 
59
    def __init__(self, team=None, *args, **kargs):
 
60
        super(TeamMeetingForm, self).__init__(*args, **kargs)
 
61
        if team:
 
62
            self.fields['chair'].choices = self.grouped_user_list([team])
 
63
            self.fields['channel'].initial = team.irc_chan
 
64
        elif self.instance:
 
65
            teams = [team for team in self.instance.teams.all()]
 
66
            self.fields['chair'].choices = self.grouped_user_list(teams)
 
67
        
 
68
    def grouped_user_list(self, teams):
 
69
        other_members, team_members = [], []
 
70
        for profile in UserProfile.objects.filter(user__groups__name__in=teams):
 
71
            team_members.append((profile.id, str(profile)))
 
72
        for profile in UserProfile.objects.all().exclude(user__groups__name__in=teams):
 
73
            other_members.append((profile.id, str(profile)))
 
74
        return [('', '---------'),
 
75
                (_('Team members'), team_members),
 
76
                (_('Other users'), other_members)]
 
77