~cjohnston/loco-team-portal/686271

« back to all changes in this revision

Viewing changes to loco_directory/events/forms.py

  • Committer: Chris Johnston
  • Date: 2010-12-22 19:13:41 UTC
  • mfrom: (344.1.1 loco-directory)
  • Revision ID: chrisjohnston@ubuntu.com-20101222191341-ycph1wt90y824v60
Sorts venues by LoCo Team's country first. Props Ronnie

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from common.forms import RenderableMixin
10
10
 
11
11
import pytz
 
12
import itertools
12
13
 
13
14
def validate_tag(tag):
14
15
    if tag.startswith('#'):
61
62
        model = TeamEvent
62
63
        exclude = ('teams', 'date_created')
63
64
        
64
 
    def __init__(self, *args, **kargs):
 
65
    def __init__(self, teams=[], *args, **kargs):
65
66
        super(TeamEventForm, self).__init__(*args, **kargs)
 
67
        self.teams = teams
66
68
        self.fields['venue'].choices = self.grouped_venue_list()
67
69
        from common.widgets import PopupRelatedFieldWidgetWrapper
68
70
        self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new'))
87
89
        venue_choices = [('', '---------')]
88
90
        country_choices = []
89
91
        current_country = ''
 
92
        
 
93
        # Show the venues which belong the the 'current team' first. then show the other countries
 
94
        venues_team = Venue.objects.filter(country__team__in=self.teams).order_by('country', 'spr', 'city')
 
95
        venues_other = Venue.objects.all().exclude(country__team__in=self.teams).order_by('country', 'spr', 'city')
 
96
        venues = itertools.chain(venues_team, venues_other)
 
97
        
90
98
        # Ordered by country so we can tell when we're done with one
91
99
        # and starting another
92
 
        for venue in Venue.objects.all().order_by('country', 'spr', 'city'):
 
100
        for venue in venues:
93
101
            # If this venue has a different country, start a new group
94
102
            if venue.country != current_country:
95
103
                # Add the old group to the list if it's non-empty