Ronnie has proposed merging lp:~ronnie.vd.c/loco-directory/691202 into 
lp:loco-directory.

Requested reviews:
  loco-directory-dev (loco-directory-dev)
Related bugs:
  #691202 venues of the country of the current selected team should be first
  https://bugs.launchpad.net/bugs/691202


The list of venues is now sorted, with the venues of the Country of the team 
first.
-- 
https://code.launchpad.net/~ronnie.vd.c/loco-directory/691202/+merge/43944
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~ronnie.vd.c/loco-directory/691202 into lp:loco-directory.
=== modified file 'loco_directory/events/forms.py'
--- loco_directory/events/forms.py	2010-11-27 13:02:31 +0000
+++ loco_directory/events/forms.py	2010-12-16 18:14:47 +0000
@@ -9,6 +9,7 @@
 from common.forms import RenderableMixin
 
 import pytz
+import itertools
 
 def validate_tag(tag):
     if tag.startswith('#'):
@@ -61,8 +62,9 @@
         model = TeamEvent
         exclude = ('teams', 'date_created')
         
-    def __init__(self, *args, **kargs):
+    def __init__(self, teams=[], *args, **kargs):
         super(TeamEventForm, self).__init__(*args, **kargs)
+        self.teams = teams
         self.fields['venue'].choices = self.grouped_venue_list()
         from common.widgets import PopupRelatedFieldWidgetWrapper
         self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new'))
@@ -87,9 +89,15 @@
         venue_choices = [('', '---------')]
         country_choices = []
         current_country = ''
+        
+        # Show the venues which belong the the 'current team' first. then show the other countries
+        venues_team = Venue.objects.filter(country__team__in=self.teams).order_by('country', 'spr', 'city')
+        venues_other = Venue.objects.all().exclude(country__team__in=self.teams).order_by('country', 'spr', 'city')
+        venues = itertools.chain(venues_team, venues_other)
+        
         # Ordered by country so we can tell when we're done with one
         # and starting another
-        for venue in Venue.objects.all().order_by('country', 'spr', 'city'):
+        for venue in venues:
             # If this venue has a different country, start a new group
             if venue.country != current_country:
                 # Add the old group to the list if it's non-empty

=== modified file 'loco_directory/events/views.py'
--- loco_directory/events/views.py	2010-11-20 17:40:31 +0000
+++ loco_directory/events/views.py	2010-12-16 18:14:47 +0000
@@ -197,14 +197,14 @@
     if is_on_lc or is_member:
         global_event = None
         if request.method == 'POST':
-            form = TeamEventForm(data=request.POST)
+            form = TeamEventForm(data=request.POST, teams=[team_object])
             if form.is_valid():
                 team_event = form.save()
                 team_event.teams.add(team_object)
                 request.user.message_set.create(message=_('New event created.'))
                 return redirect( team_object )
         else:
-            form = TeamEventForm(initial={'global_event':request.GET.get('global_event_id', None)})
+            form = TeamEventForm(initial={'global_event':request.GET.get('global_event_id', None)}, teams=[team_object])
             if request.GET.has_key('global_event_id'):
                 global_event = get_object_or_404(GlobalEvent, pk=request.GET.get('global_event_id'))
                 
@@ -235,14 +235,14 @@
     
     if is_on_lc or is_member:
         if request.method == 'POST':
-            form = TeamEventForm(instance=team_event, data=request.POST)
+            form = TeamEventForm(instance=team_event, data=request.POST, teams=team_event.teams.all())
             if form.is_valid():
                 team_event = form.save()
                 team_event.teams.add(team_object)
                 request.user.message_set.create(message=_('New event created.'))
                 return redirect( team_object )
         else:
-            form = TeamEventForm(instance=team_event)
+            form = TeamEventForm(instance=team_event, teams=team_event.teams.all())
         
         context = {
             'team_object': team_object,
@@ -272,13 +272,13 @@
     
     if is_on_lc or is_member:
         if request.method == 'POST':		
-            form = TeamEventForm(data=request.POST, instance=team_event_object)
+            form = TeamEventForm(data=request.POST, instance=team_event_object, teams=team_event_object.teams.all())
             if form.is_valid():
                 form.save()
                 request.user.message_set.create(message=_('Team Event updated.'))
                 return redirect( team_event_object )
         else:
-            form = TeamEventForm(instance=team_event_object)
+            form = TeamEventForm(instance=team_event_object, teams=team_event_object.teams.all())
             
         context = {
             'form': form,

_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to