diff options
| -rw-r--r-- | ishtar_common/tests.py | 28 | ||||
| -rw-r--r-- | ishtar_common/views.py | 9 | 
2 files changed, 32 insertions, 5 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 65a5a7593..bd1833594 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1273,6 +1273,34 @@ class ShortMenuTest(TestCase):          self.assertEqual(response.status_code, 200)          self.assertFalse(str(treat.cached_label) in response.content) +    def test_pin_search(self): +        c = Client() +        c.login(username=self.username, password=self.password) +        base_find, find = self._create_find() + +        response = c.post( +            reverse('pin-search', args=['find']), +            {'value': 'Where is my find'}, +            **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} +        ) +        self.assertEqual(response.status_code, 200) +        # the selected find search is pined +        self.assertEqual(c.session['pin-search-find'], 'Where is my find') + +        # empty search save means empty dependant search +        c.get( +            reverse('pin', args=['contextrecord', +                                 str(base_find.context_record.pk)]) +        ) +        response = c.post( +            reverse('pin-search', args=['find']), +            {'value': ''}, +            **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} +        ) +        self.assertEqual(response.status_code, 200) +        self.assertEqual(c.session['pin-search-find'], '') +        self.assertEqual(c.session['contextrecord'], '') +      def test_update_current_item(self):          c = Client()          c.login(username=self.username, password=self.password) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 6fce21953..827d41ea0 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -457,12 +457,11 @@ def update_current_item(request, item_type=None, pk=None):  def pin_search(request, item_type):      key = "pin-search-" + item_type -    if not item_type or not (request.is_ajax() and request.method == 'POST'): +    if not item_type or not ( +            request.is_ajax() and request.method == 'POST' +            and 'value' in request.POST):          raise Http404 -    if 'value' in request.POST: -        request.session[key] = request.POST['value'] -    else: -        request.session[key] = request.POST['value'] +    request.session[key] = request.POST['value']      if not request.POST['value']:          # empty all          unpin(request, item_type, cascade=True) | 
