Commits

Luke Plant committed 4b2dfb0

Implemented booking account overview page

Comments (0)

Files changed (5)

cciw/bookings/templatetags/bookings.py

         out.append("Not logged in")
     else:
         out.append("Bookings: %s" % escape(request.booking_account.email))
-        out.append(' | <a href="%s">Account overview</a>' % 'TODO')
+        out.append(' | <a href="%s">Account overview</a>' % escape(reverse('cciw.bookings.views.account_overview')))
         out.append(' | <a href="%s">Log out</a>' % 'TODO')
     out.append("</div>")
 

cciw/bookings/tests.py

     email = 'booker@bookers.com'
 
     def login(self, add_account_details=True):
+        if hasattr(self, '_logged_in'):
+            return
         # Easiest way is to simulate what the user actually has to do
         self.client.post(reverse('cciw.bookings.views.start'),
                          {'email': self.email})
             BookingAccount.objects.filter(email=self.email).update(name='Joe',
                                                                    address='123',
                                                                    post_code='XYZ')
+        self._logged_in = True
 
     def get_account(self):
         return BookingAccount.objects.get(email=self.email)
         resp = self.client.get(reverse('cciw.bookings.views.account_json'))
         json = simplejson.loads(resp.content)
         self.assertEqual(json['account']['address'], '123 Main Street')
+
+
+class TestAccountOverview(CreatePlaceMixin, TestCase):
+
+    fixtures = ['basic.json']
+
+    url = reverse('cciw.bookings.views.account_overview')
+
+    def test_show(self):
+        self.login()
+
+        acc = self.get_account()
+
+        # Book a place and pay
+        self.create_place()
+        book_basket_now(acc.bookings.basket(self.camp.year))
+        acc.receive_payment(acc.bookings.all()[0].amount_due)
+
+        # Book another
+        self.create_place({'name': 'Another Child'})
+        book_basket_now(acc.bookings.basket(self.camp.year))
+
+        # 3rd place, not booked at all
+        self.create_place({'name': '3rd child'})
+
+        resp = self.client.get(self.url)
+
+        # Another one, so that messages are cleared
+        resp = self.client.get(self.url)
+        self.assertEqual(resp.status_code, 200)
+
+        # Confirmed place
+        self.assertContains(resp, self.place_details['name'])
+
+
+        # Booked place
+        self.assertContains(resp, 'Another Child')
+        self.assertContains(resp, 'remember to pay')
+
+        # Basket/Shelf
+        self.assertContains(resp, 'items in your basket')

cciw/bookings/urls.py

              (r'^pay/$', 'pay'),
              (r'^pay/done/$', 'pay_done'),
              (r'^pay/cancelled/$', 'pay_cancelled'),
+             (r'^overview/$', 'account_overview'),
              )

cciw/bookings/views.py

         return self.get(*args, **kwargs)
 
 
+class BookingAccountOverview(DefaultMetaData, TemplateView):
+    metadata_title = "Booking - account overview"
+    template_name = 'cciw/bookings/account_overview.html'
+    extra_context = {'stage': ''}
+
+    def get_context_data(self, *args, **kwargs):
+        c = super(BookingAccountOverview, self).get_context_data(*args, **kwargs)
+        acc = self.request.booking_account
+        year = get_thisyear()
+        c['confirmed_places'] = acc.bookings.confirmed().filter(camp__year__exact=year)
+        c['unconfirmed_places'] = acc.bookings.unconfirmed().filter(camp__year__exact=year)
+        c['basket'] = acc.bookings.basket(year).exists()
+        c['shelf'] = acc.bookings.shelf(year).exists()
+        return c
+
+
 index = BookingIndex.as_view()
 start = BookingStart.as_view()
 email_sent = BookingEmailSent.as_view()
 pay = booking_account_required(BookingPay.as_view())
 pay_done = csrf_exempt(BookingPayDone.as_view())
 pay_cancelled = csrf_exempt(BookingPayCancelled.as_view())
+account_overview = booking_account_required(BookingAccountOverview.as_view())
 

templates/cciw/bookings/account_overview.html

+{% extends 'cciw/bookings/standard.html' %}
+{% load url from future %}
+{% block content %}
+
+<h2>Basket</h2>
+
+{% if basket or shelf %}
+
+<p>You have items in your basket or shelf - please remember to
+  <a href="{% url 'cciw.bookings.views.list_bookings' %}">book and pay for
+  them</a>.</p>
+
+{% else %}
+
+<p>You have nothing in your basket.</p>
+
+{% endif %}
+
+{% if unconfirmed_places %}
+
+<h2>Booked places</h2>
+
+<p>The following places are booked, but not yet confirmed:</p>
+<ul>
+  {% for b in unconfirmed_places %}
+  <li>{{ b.name }}, on <a href="{% url 'cciw.cciwmain.views.camps.detail' year=b.camp.year number=b.camp.number %}">camp {{ b.camp.number }}</a>, {{ b.get_price_type_display }}, £{{ b.amount_due }} {% if b.south_wales_transport %}(South Wales minibus){% endif %}</li>
+  {% endfor %}
+</ul>
+<p>Please <a href="{% url 'cciw.bookings.views.pay' %}">remember to pay</a> for
+  these places, otherwise they will expire so that someone else can take the
+  place.</p>
+
+{% endif %}
+
+<h2>Confirmed places</h2>
+{% if confirmed_places %}
+<p>You have the following confirmed places on camps this year:</p>
+<ul>
+  {% for b in confirmed_places %}
+  <li>{{ b.name }}, on <a href="{% url 'cciw.cciwmain.views.camps.detail' year=b.camp.year number=b.camp.number %}">camp {{ b.camp.number }}</a>, {{ b.get_price_type_display }}, £{{ b.amount_due }} {% if b.south_wales_transport %}(South Wales minibus){% endif %}</li>
+  {% endfor %}
+</ul>
+
+{% else %}
+<p>You have no confirmed places yet.</p>
+{% endif %}
+
+
+{% endblock %}