Commits

Luke Plant  committed 15efc94

Added place availability to 'add place' page, changing camp widget to a radio button list

  • Participants
  • Parent commits 1e718bf
  • Branches bookings

Comments (0)

Files changed (3)

File cciw/bookings/forms.py

 from django import forms
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
 
 from cciw.bookings.models import BookingAccount, Booking
 from cciw.cciwmain.forms import CciwFormMixin
 
 
 class AddPlaceForm(CciwFormMixin, forms.ModelForm):
+
+    camp = forms.ChoiceField(choices=[],
+                             widget=forms.RadioSelect)
+
     def __init__(self, *args, **kwargs):
         super(AddPlaceForm, self).__init__(*args, **kwargs)
-        self.fields['camp'].queryset = Camp.objects.filter(year=get_thisyear())
+        def render_camp(c):
+            return (escape("Camp %d, %s, %s" % (c.number, c.leaders_formatted,
+                                                c.start_date.strftime("%e %b %Y"))) +
+                    '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
+                    '<span class="placeAvailability">' +
+                    escape("(Places left: %d total, max %d for boys, max %d for girls)" %
+                           c.get_places_left()) + '</span>')
+        self.fields['camp'].choices = [(c.id, mark_safe(render_camp(c)))
+                                       for c in Camp.objects.filter(year=get_thisyear())]
+
 
     class Meta:
         model = Booking
             ]
 
     def clean_camp(self):
-        camp = self.cleaned_data['camp']
-        thisyear = get_thisyear()
-        if camp.year != thisyear:
-            # This will not ever trigger if the limiting of the camp queryset
-            # above works as intended. Instead you get 'Select a valid choice'
-            raise forms.ValidationError('Only a camp in %s can be selected.' % thisyear)
-
-        return camp
+        camp_id = self.cleaned_data['camp']
+        return Camp.objects.get(id=int(camp_id))
 
 AddPlaceForm.base_fields['agreement'].required = True

File cciw/cciwmain/static/css/style.css

     vertical-align: top;
 }
 
+.placeAvailability {
+    color: #404040;
+}
+
 /* Popups */
 
 .inlinepopup {

File templates/cciw/bookings/add_place.html

 
 <h2>Camp</h2>
 {% cciw_form_field form 'camp' 'Choose camp:' %}
-<div id="id_camp_availability">
-</div>
 
 <h2>Price</h2>
 <p>The 2nd child from the same family is eligible for '2nd child discount'.