1. pombredanne
  2. cciw-website

Commits

Luke Plant  committed c04e416

Checked 'view/edit' on 'list bookings' page from link to button for consistency

  • Participants
  • Parent commits c5a9fec
  • Branches bookings

Comments (0)

Files changed (3)

File cciw/bookings/tests.py

View file
  • Ignore whitespace
 
         # Should be gone
         self.assertEqual(0, acc.bookings.count())
+
+    def test_edit_place_btn(self):
+        self.login()
+        self.create_place()
+        acc = BookingAccount.objects.get(email=self.email)
+        b = acc.bookings.all()[0]
+        resp = self.client.post(reverse('cciw.bookings.views.list_bookings'))
+
+        # Delete button should be there
+        self.assertContains(resp, "name=\"edit_%s\"" % b.id)
+
+        # Now click it
+        resp2 = self.client.post(reverse('cciw.bookings.views.list_bookings'), {'edit_%s' % b.id: '1'})
+        self.assertEqual(resp2.status_code, 302)
+        self.assertTrue(resp2['Location'].endswith(reverse('cciw.bookings.views.edit_place', kwargs={'id':b.id})))

File cciw/bookings/views.py

View file
  • Ignore whitespace
         def delete(place):
             place.delete()
 
+        def edit(place):
+            return HttpResponseRedirect(reverse('cciw.bookings.views.edit_place',
+                                                kwargs={'id':str(place.id)}))
+
         for k in request.POST.keys():
             # handle shelve and unshelve buttons
             for r, action in [(r'shelve_(\d+)', shelve),
                               (r'unshelve_(\d+)', unshelve),
-                              (r'delete_(\d+)', delete)]:
+                              (r'delete_(\d+)', delete),
+                              (r'edit_(\d+)', edit),
+                              ]:
                 m = re.match(r, k)
                 if m is not None:
                     try:
                         b_id = int(m.groups()[0])
                         place = places.get(id=b_id)
-                        action(place)
+                        retval = action(place)
+                        if retval is not None:
+                            return retval
                     except (ValueError, Booking.DoesNotExist):
                         pass
         return self.get(request, *args, **kwargs)

File templates/cciw/bookings/place_details_row_inc.html

View file
  • Ignore whitespace
       {% if b.amount_due_normalised|default_if_none:"None" == "None" %}TBA{% else %}£{{ b.amount_due_normalised }}{% endif %}
     </td>
     <td rowspan="2" style="text-align:center;">
-      <a href="{% url 'cciw.bookings.views.edit_place' id=b.id %}">View/edit</a><br/>
+      <input type="submit" name="edit_{{ b.id }}" value="View/edit"><br/>
       {% if basket %}
         <input type="submit" name="shelve_{{ b.id }}" value="Save for later"><br/>
       {% endif %}