Luke Plant avatar Luke Plant committed b1881ca

Fixed 'copy place details' to exclude the current place in candidates

Comments (0)

Files changed (3)

cciw/bookings/tests.py

         json = simplejson.loads(resp.content)
         self.assertEqual(json['places'][0]['name'], self.place_details['name'])
 
+    def test_places_json_with_exclusion(self):
+        self.login()
+        self.create_place()
+        acc = self.get_account()
+        resp = self.client.get(reverse('cciw.bookings.views.places_json') +
+                               ("?exclude=%d" % acc.bookings.all()[0].id))
+        json = simplejson.loads(resp.content)
+        self.assertEqual(json['places'], [])
+
+    def test_places_json_with_bad_exclusion(self):
+        self.login()
+        resp = self.client.get(reverse('cciw.bookings.views.places_json') +"?exclude=x")
+        json = simplejson.loads(resp.content)
+        self.assertEqual(json['places'], [])
+
     def test_account_json(self):
         self.login()
         acc = self.get_account()

cciw/bookings/views.py

 @json_response
 def places_json(request):
     retval = {'status': 'success'}
+    qs = request.booking_account.bookings.all()
+    if 'exclude' in request.GET:
+        try:
+            exclude_id = int(request.GET['exclude'])
+            qs = qs.exclude(id=exclude_id)
+        except ValueError:
+            pass
     retval['places'] = [dict((k, getattr(b, k)) for k in BOOKING_PLACE_PUBLIC_ATTRS)
-                        for b in request.booking_account.bookings.all()]
+                        for b in qs]
     return retval
 
 

templates/cciw/bookings/add_place.html

        /* Load data about existing places */
        $.ajax({
            type: "GET",
-           url: '{% url "cciw.bookings.views.places_json" %}',
+           url: '{% url "cciw.bookings.views.places_json" %}?exclude={{ form.instance.id }}',
            dataType: "json",
            success: handleExistingPlacesData
        });
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.