Commits

Luke Plant  committed ab099ce

Added 'booking bar' that shows the state of the booking process with links to skip backwards/forwards

  • Participants
  • Parent commits e1e9c22
  • Branches bookings

Comments (0)

Files changed (14)

File cciw/bookings/templatetags/__init__.py

Empty file added.

File cciw/bookings/templatetags/bookings.py

+from django import template
+from django.core.urlresolvers import reverse
+from django.utils.html import escape
+
+from cciw.bookings.views import ensure_booking_acount_attr
+
+register = template.Library()
+
+
+@register.simple_tag(takes_context=True)
+def bookingbar(context):
+
+    request = context['request']
+    ensure_booking_acount_attr(request)
+    logged_in = request.booking_account is not None
+    current_stage = context['stage']
+    has_account_details = request.booking_account.has_account_details()
+
+    # Tuple of (name, caption, if this a link, url):
+    stages = [
+        ('email',  'Log in', False,
+         ''),
+        ('account', 'Account details', logged_in,
+         reverse('cciw.bookings.views.account_details')),
+        ('place', 'Place details', logged_in and has_account_details,
+         reverse('cciw.bookings.views.add_place')),
+        ('list', 'Checkout', logged_in and has_account_details,
+         reverse('cciw.bookings.views.list_bookings')),
+        ('pay', 'Pay', logged_in and has_account_details,
+         reverse('cciw.bookings.views.pay')),
+        ]
+
+    out = []
+    out.append("""
+<div id="bookingbar">
+  <div id="bookingbartop">""")
+
+    if not logged_in:
+        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">Log out</a>' % 'TODO')
+    out.append("</div>")
+
+    out.append("<ul>")
+    for name, caption, is_link, url in stages:
+        if is_link and name != current_stage:
+            out.append('<li><a href="%s">%s</a></li>' % (escape(url), escape(caption)))
+        elif name == current_stage:
+            out.append('<li><span class="active">%s</span></li>' % escape(caption))
+        else:
+            out.append('<li><span>%s</span></li>' % escape(caption))
+
+    out.append("</ul></div>")
+    return ''.join(out)

File cciw/bookings/views.py

         return None
 
 
+def ensure_booking_acount_attr(request):
+    if not hasattr(request, 'booking_account'):
+        request.booking_account = get_booking_account_from_cookie(request)
+
+
 def booking_account_required(view_func):
     """
     Requires a signed cookie that verifies the booking account,
     """
     @wraps(view_func)
     def view(request, *args, **kwargs):
-        account = get_booking_account_from_cookie(request)
-        if account is None:
+        ensure_booking_acount_attr(request)
+        if request.booking_account is None:
             return HttpResponseRedirect(reverse('cciw.bookings.views.not_logged_in'))
-        request.booking_account = account
         return view_func(request, *args, **kwargs)
     return view
 
     form_class = EmailForm
     template_name = 'cciw/bookings/start.html'
     success_url = reverse_lazy('cciw.bookings.views.email_sent')
-    extra_context = {'booking_open': is_booking_open_thisyear}
+    extra_context = {'booking_open': is_booking_open_thisyear,
+                     'stage': 'email'}
 
     def dispatch(self, request, *args, **kwargs):
         account = get_booking_account_from_cookie(request)
 class BookingEmailSent(DefaultMetaData, TemplateView):
     metadata_title = "Booking email address"
     template_name = "cciw/bookings/email_sent.html"
+    extra_context = {'stage': 'email'}
 
 
 def verify_email(request, account_id, token):
 class BookingVerifyEmailFailed(DefaultMetaData, TemplateView):
     metadata_title = "Booking account email verification failed"
     template_name = "cciw/bookings/email_verification_failed.html"
+    extra_context = {'stage': 'email'}
 
 
 class BookingNotLoggedIn(DefaultMetaData, TemplateView):
     form_class = AccountDetailsForm
     template_name = 'cciw/bookings/account_details.html'
     success_url = reverse_lazy('cciw.bookings.views.add_place')
+    extra_context = {'stage': 'account'}
 
     def get_object(self):
         return self.request.booking_account
     success_url = reverse_lazy('cciw.bookings.views.list_bookings')
     extra_context = {'booking_open': is_booking_open_thisyear,
                      'south_wales_surcharge': lambda: Price.objects.get(year=get_thisyear(),
-                                                                        price_type=PRICE_SOUTH_WALES_TRANSPORT).price}
+                                                                        price_type=PRICE_SOUTH_WALES_TRANSPORT).price,
+                     'stage': 'place'}
+
 
     def post(self, request, *args, **kwargs):
         if not is_booking_open_thisyear():
 class BookingListBookings(DefaultMetaData, TemplateView):
     metadata_title = "Booking - checkout"
     template_name = "cciw/bookings/list_bookings.html"
+    extra_context = {'stage': 'list'}
 
     def get_context_data(self, **kwargs):
         c = super(BookingListBookings, self).get_context_data(**kwargs)
 class BookingPay(DefaultMetaData, TemplateView):
     metadata_title = "Booking - Pay"
     template_name = "cciw/bookings/pay.html"
+    extra_context = {'stage': 'pay'}
 
     def get(self, request):
         acc = self.request.booking_account
 class BookingPayDone(DefaultMetaData, TemplateView):
     metadata_title = "Booking - payment complete"
     template_name = "cciw/bookings/pay_done.html"
+    extra_context = {'stage': 'pay'}
 
     # Paypal wants to post to this view
     def post(self, *args, **kwargs):
 class BookingPayCancelled(DefaultMetaData, TemplateView):
     metadata_title = "Booking - payment cancelled"
     template_name = "cciw/bookings/pay_cancelled.html"
+    extra_context = {'stage': 'pay'}
 
     def post(self, *args, **kwargs):
         return self.get(*args, **kwargs)

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

 ul.messagelist li.error{
     background-image: url(../admin/img/icon_error.gif);
 }
+
+
+#bookingbar {
+    margin-top: -2px; /* cover green border at top */
+    background-color: #406080;
+    color: white;
+    padding: 1px 0 3px 0; /* equals padding on #bookingbar a */
+    text-align: center;
+}
+
+#bookingbartop {
+    padding: 3px;
+    margin: 0px 0px 3px 0px;
+    border-bottom: 1px solid #A0B0C0;
+    text-align: right;
+}
+
+#bookingbar ul {
+    margin: 0;
+    padding: 0;
+    list-style-type: none;
+}
+
+#bookingbar ul li {
+    display: inline;
+}
+
+#bookingbar ul li a,
+#bookingbar ul li span {
+    text-decoration: none;
+    padding: 3px 10px;
+    color: white;
+    line-height:1.3em;
+    margin: 0px;
+    font-weight: bold;
+}
+
+#bookingbar ul li a:hover {
+    background-color:	#668099;
+}
+
+#bookingbar ul li a.active,
+#bookingbar ul li span.active,
+#bookingbar ul li a.active:hover {
+    color: black;
+    background:white;
+}
+
+#bookingbar a {
+    color: white;
+}

File templates/cciw/bookings/account_details.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 {% block content %}
 <p>Please enter your name and address:</p>
 

File templates/cciw/bookings/add_place.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 {% load cciwform %}
 {% load url from future %}
 {% block content %}

File templates/cciw/bookings/email_sent.html

-{% extends "cciw/standard.html" %}
+{% extends "cciw/bookings/standard.html" %}
 {% block content %}
 <p>An email has been sent to your address to verify that it works. Please follow
 the instructions in the email to continue the booking process.</p>

File templates/cciw/bookings/email_verification_failed.html

-{% extends "cciw/standard.html" %}
+{% extends "cciw/bookings/standard.html" %}
 {% load url from future %}
 {% block content %}
 <p>The verification email was not correct, or was out of date, and your email

File templates/cciw/bookings/list_bookings.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 {% load url from future %}
 {% load static %}
 

File templates/cciw/bookings/pay.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 
 {% block content %}
 

File templates/cciw/bookings/pay_cancelled.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 {% load url from future %}
 {% block content %}
 <h3>Payment cancelled</h3>

File templates/cciw/bookings/pay_done.html

-{% extends 'cciw/standard.html' %}
+{% extends 'cciw/bookings/standard.html' %}
 {% load url from future %}
 {% block content %}
 <h3>Payment complete!</h3>

File templates/cciw/bookings/standard.html

+{% extends 'cciw/standard.html' %}
+{% load url from future %}
+{% load bookings %}
+{% block contentTop %}
+{% bookingbar %}
+{{ block.super }}
+{% endblock %}

File templates/cciw/bookings/start.html

-{% extends "cciw/standard.html" %}
+{% extends "cciw/bookings/standard.html" %}
 {% block content %}
 <h2>Booking account - email address</h2>