def owner(self, request, var):
     user = request.user
     if user != var.student_info:
         return Response(
             {'response': "You don't have permissions for this operation."})
     else:
         data = {}
         q_dict = QueryDict('', mutable=True)
         q_dict.update(request.data)
         data['hi'] = "hi"
         q_dict.__setitem__('student_info', user.id)
         return q_dict
Ejemplo n.º 2
0
 def owner(self, request, question_id, answer):
     user = request.user
     if user != answer.replied_by:
         return Response(
             {'response': "You don't have permissions for this operation."})
     else:
         data = {}
         q_dict = QueryDict('', mutable=True)
         q_dict.update(request.data)
         data['hi'] = "hi"
         q_dict.__setitem__('replied_by', user.roll_no)
         q_dict.__setitem__('ans_of_ques', question_id)
         return q_dict
Ejemplo n.º 3
0
 def owner(self, request, class_id, question):
     user = request.user
     if user != question.asked_by:
         return Response(
             {'response': "You don't have permissions for this operation."})
     else:
         data = {}
         q_dict = QueryDict('', mutable=True)
         q_dict.update(request.data)
         data['hi'] = "hi"
         q_dict.__setitem__('asked_by', user.roll_no)
         q_dict.__setitem__('classdata',
                            self.class_data(class_id).class_associated)
         return q_dict
Ejemplo n.º 4
0
def pass_on_params(request):
    """

    Retrieve the standard filtering parameters from the request and prepare them
    as an outgoing URL string so as to preserve session state.
    Always get the GET parameters and ignore the POST, because by definition
    the query state is in url parameters, which are in GET.  Even if POST has
    something like tags, they relate to a specific task, not to the query state

    TODO: SECURITY is this sufficiently sanitized?

    Listing them all individually instead of using **kwargs (I think) because
      1) I'm afraid to get into **kwargs black magic
      2) Maybe not all parameters should get passed

    """

    state_params = QueryDict(query_string=None, mutable=True)
    state_params.setlist('tags', request.GET.getlist('tags'))
    state_params.setlist('exclude_tags', request.GET.getlist('exclude_tags', ''))
    state_params.__setitem__('show_closed', request.GET.get('show_closed', ''))
    state_params.__setitem__('show_snoozed', request.GET.get('show_snoozed', ''))
    state_params.__setitem__('text_filter', request.GET.get('text_filter', ''))
    state_params.__setitem__('page', request.GET.get('page', ''))
    return state_params.urlencode()
 def post(self, request, format=None):
     user = request.user
     data = {}
     q_dict = QueryDict('', mutable=True)
     q_dict.update(request.data)
     if user:
         data['hi'] = "hi"
         q_dict.__setitem__('student_info', user.id)
     else:
         data["Failure"] = "Failed to add"
     serializer = ClassDataSerializer(data=q_dict)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 6
0
 def test_immutability(self):
     q = QueryDict()
     with self.assertRaises(AttributeError):
         q.__setitem__('something', 'bar')
     with self.assertRaises(AttributeError):
         q.setlist('foo', ['bar'])
     with self.assertRaises(AttributeError):
         q.appendlist('foo', ['bar'])
     with self.assertRaises(AttributeError):
         q.update({'foo': 'bar'})
     with self.assertRaises(AttributeError):
         q.pop('foo')
     with self.assertRaises(AttributeError):
         q.popitem()
     with self.assertRaises(AttributeError):
         q.clear()
Ejemplo n.º 7
0
 def test_immutability(self):
     q = QueryDict()
     with self.assertRaises(AttributeError):
         q.__setitem__("something", "bar")
     with self.assertRaises(AttributeError):
         q.setlist("foo", ["bar"])
     with self.assertRaises(AttributeError):
         q.appendlist("foo", ["bar"])
     with self.assertRaises(AttributeError):
         q.update({"foo": "bar"})
     with self.assertRaises(AttributeError):
         q.pop("foo")
     with self.assertRaises(AttributeError):
         q.popitem()
     with self.assertRaises(AttributeError):
         q.clear()
Ejemplo n.º 8
0
 def test_immutability(self):
     q = QueryDict()
     with self.assertRaises(AttributeError):
         q.__setitem__('something', 'bar')
     with self.assertRaises(AttributeError):
         q.setlist('foo', ['bar'])
     with self.assertRaises(AttributeError):
         q.appendlist('foo', ['bar'])
     with self.assertRaises(AttributeError):
         q.update({'foo': 'bar'})
     with self.assertRaises(AttributeError):
         q.pop('foo')
     with self.assertRaises(AttributeError):
         q.popitem()
     with self.assertRaises(AttributeError):
         q.clear()
Ejemplo n.º 9
0
 def test_immutability(self):
     q = QueryDict()
     with self.assertRaises(AttributeError):
         q.__setitem__("something", "bar")
     with self.assertRaises(AttributeError):
         q.setlist("foo", ["bar"])
     with self.assertRaises(AttributeError):
         q.appendlist("foo", ["bar"])
     with self.assertRaises(AttributeError):
         q.update({"foo": "bar"})
     with self.assertRaises(AttributeError):
         q.pop("foo")
     with self.assertRaises(AttributeError):
         q.popitem()
     with self.assertRaises(AttributeError):
         q.clear()
Ejemplo n.º 10
0
    def test_multiple_keys(self):
        """Test QueryDict with two key/value pairs with same keys."""

        q = QueryDict(str('vote=yes&vote=no'))

        self.assertEqual(q['vote'], 'no')
        with self.assertRaises(AttributeError):
            q.__setitem__('something', 'bar')

        self.assertEqual(q.get('vote', 'default'), 'no')
        self.assertEqual(q.get('foo', 'default'), 'default')
        self.assertEqual(q.getlist('vote'), ['yes', 'no'])
        self.assertEqual(q.getlist('foo'), [])

        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.appendlist('foo', ['bar'])

        if six.PY2:
            self.assertEqual(q.has_key('vote'), True)
        self.assertEqual('vote' in q, True)
        if six.PY2:
            self.assertEqual(q.has_key('foo'), False)
        self.assertEqual('foo' in q, False)
        self.assertEqual(list(six.iteritems(q)), [('vote', 'no')])
        self.assertEqual(list(six.iterlists(q)), [('vote', ['yes', 'no'])])
        self.assertEqual(list(six.iterkeys(q)), ['vote'])
        self.assertEqual(list(six.itervalues(q)), ['no'])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({'foo': 'bar'})
        with self.assertRaises(AttributeError):
            q.pop('foo')
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault('foo', 'bar')
        with self.assertRaises(AttributeError):
            q.__delitem__('vote')
Ejemplo n.º 11
0
    def test_single_key_value(self):
        """Test QueryDict with one key/value pair"""

        q = QueryDict(str('foo=bar'))
        self.assertEqual(q['foo'], 'bar')
        with self.assertRaises(KeyError):
            q.__getitem__('bar')
        with self.assertRaises(AttributeError):
            q.__setitem__('something', 'bar')

        self.assertEqual(q.get('foo', 'default'), 'bar')
        self.assertEqual(q.get('bar', 'default'), 'default')
        self.assertEqual(q.getlist('foo'), ['bar'])
        self.assertEqual(q.getlist('bar'), [])

        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar'])
        with self.assertRaises(AttributeError):
            q.appendlist('foo', ['bar'])

        if six.PY2:
            self.assertTrue(q.has_key('foo'))
        self.assertIn('foo', q)
        if six.PY2:
            self.assertFalse(q.has_key('bar'))
        self.assertNotIn('bar', q)

        self.assertEqual(list(six.iteritems(q)), [('foo', 'bar')])
        self.assertEqual(list(six.iterlists(q)), [('foo', ['bar'])])
        self.assertEqual(list(six.iterkeys(q)), ['foo'])
        self.assertEqual(list(six.itervalues(q)), ['bar'])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({'foo': 'bar'})
        with self.assertRaises(AttributeError):
            q.pop('foo')
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault('foo', 'bar')

        self.assertEqual(q.urlencode(), 'foo=bar')
Ejemplo n.º 12
0
    def test_multiple_keys(self):
        """Test QueryDict with two key/value pairs with same keys."""

        q = QueryDict(str('vote=yes&vote=no'))

        self.assertEqual(q['vote'], 'no')
        with self.assertRaises(AttributeError):
            q.__setitem__('something', 'bar')

        self.assertEqual(q.get('vote', 'default'), 'no')
        self.assertEqual(q.get('foo', 'default'), 'default')
        self.assertEqual(q.getlist('vote'), ['yes', 'no'])
        self.assertEqual(q.getlist('foo'), [])

        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.appendlist('foo', ['bar'])

        if six.PY2:
            self.assertIs(q.has_key('vote'), True)
        self.assertIn('vote', q)
        if six.PY2:
            self.assertIs(q.has_key('foo'), False)
        self.assertNotIn('foo', q)
        self.assertEqual(list(six.iteritems(q)), [('vote', 'no')])
        self.assertEqual(list(six.iterlists(q)), [('vote', ['yes', 'no'])])
        self.assertEqual(list(six.iterkeys(q)), ['vote'])
        self.assertEqual(list(six.itervalues(q)), ['no'])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({'foo': 'bar'})
        with self.assertRaises(AttributeError):
            q.pop('foo')
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault('foo', 'bar')
        with self.assertRaises(AttributeError):
            q.__delitem__('vote')
Ejemplo n.º 13
0
    def test_multiple_keys(self):
        """Test QueryDict with two key/value pairs with same keys."""

        q = QueryDict(str("vote=yes&vote=no"))

        self.assertEqual(q["vote"], "no")
        with self.assertRaises(AttributeError):
            q.__setitem__("something", "bar")

        self.assertEqual(q.get("vote", "default"), "no")
        self.assertEqual(q.get("foo", "default"), "default")
        self.assertEqual(q.getlist("vote"), ["yes", "no"])
        self.assertEqual(q.getlist("foo"), [])

        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar", "baz"])
        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar", "baz"])
        with self.assertRaises(AttributeError):
            q.appendlist("foo", ["bar"])

        if six.PY2:
            self.assertEqual(q.has_key("vote"), True)
        self.assertEqual("vote" in q, True)
        if six.PY2:
            self.assertEqual(q.has_key("foo"), False)
        self.assertEqual("foo" in q, False)
        self.assertEqual(list(six.iteritems(q)), [("vote", "no")])
        self.assertEqual(list(six.iterlists(q)), [("vote", ["yes", "no"])])
        self.assertEqual(list(six.iterkeys(q)), ["vote"])
        self.assertEqual(list(six.itervalues(q)), ["no"])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({"foo": "bar"})
        with self.assertRaises(AttributeError):
            q.pop("foo")
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault("foo", "bar")
        with self.assertRaises(AttributeError):
            q.__delitem__("vote")
Ejemplo n.º 14
0
    def test_single_key_value(self):
        """Test QueryDict with one key/value pair"""

        q = QueryDict(str('foo=bar'))
        self.assertEqual(q['foo'], 'bar')
        with self.assertRaises(KeyError):
            q.__getitem__('bar')
        with self.assertRaises(AttributeError):
            q.__setitem__('something', 'bar')

        self.assertEqual(q.get('foo', 'default'), 'bar')
        self.assertEqual(q.get('bar', 'default'), 'default')
        self.assertEqual(q.getlist('foo'), ['bar'])
        self.assertEqual(q.getlist('bar'), [])

        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar'])
        with self.assertRaises(AttributeError):
            q.appendlist('foo', ['bar'])

        if six.PY2:
            self.assertTrue(q.has_key('foo'))
        self.assertIn('foo', q)
        if six.PY2:
            self.assertFalse(q.has_key('bar'))
        self.assertNotIn('bar', q)

        self.assertEqual(list(six.iteritems(q)), [('foo', 'bar')])
        self.assertEqual(list(six.iterlists(q)), [('foo', ['bar'])])
        self.assertEqual(list(six.iterkeys(q)), ['foo'])
        self.assertEqual(list(six.itervalues(q)), ['bar'])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({'foo': 'bar'})
        with self.assertRaises(AttributeError):
            q.pop('foo')
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault('foo', 'bar')

        self.assertEqual(q.urlencode(), 'foo=bar')
Ejemplo n.º 15
0
    def test_single_key_value(self):
        """Test QueryDict with one key/value pair"""

        q = QueryDict(str("foo=bar"))
        self.assertEqual(q["foo"], "bar")
        with self.assertRaises(KeyError):
            q.__getitem__("bar")
        with self.assertRaises(AttributeError):
            q.__setitem__("something", "bar")

        self.assertEqual(q.get("foo", "default"), "bar")
        self.assertEqual(q.get("bar", "default"), "default")
        self.assertEqual(q.getlist("foo"), ["bar"])
        self.assertEqual(q.getlist("bar"), [])

        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar"])
        with self.assertRaises(AttributeError):
            q.appendlist("foo", ["bar"])

        if six.PY2:
            self.assertTrue(q.has_key("foo"))
        self.assertIn("foo", q)
        if six.PY2:
            self.assertFalse(q.has_key("bar"))
        self.assertNotIn("bar", q)

        self.assertEqual(list(six.iteritems(q)), [("foo", "bar")])
        self.assertEqual(list(six.iterlists(q)), [("foo", ["bar"])])
        self.assertEqual(list(six.iterkeys(q)), ["foo"])
        self.assertEqual(list(six.itervalues(q)), ["bar"])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({"foo": "bar"})
        with self.assertRaises(AttributeError):
            q.pop("foo")
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault("foo", "bar")

        self.assertEqual(q.urlencode(), "foo=bar")
Ejemplo n.º 16
0
    def post(self, request, *args, **kwargs):
        data_dict = request.data
        mutable_query_dict = QueryDict(mutable=True)
        mutable_query_dict.update(data_dict)
        mutable_query_dict.__setitem__('user_id', request.user.id)

        if u.UserBookmarkedProperty.objects.filter(user_id=request.user.id,
                                                   bbl=data_dict['bbl']):
            return Response("User has already bookmarked this property",
                            status=status.HTTP_422_UNPROCESSABLE_ENTITY)

        serializer = self.get_serializer(data=mutable_query_dict)
        serializer.is_valid(raise_exception=True)
        serializer.create(validated_data=mutable_query_dict.dict())
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=headers)
Ejemplo n.º 17
0
    def test_multiple_keys(self):
        """Test QueryDict with two key/value pairs with same keys."""

        q = QueryDict('vote=yes&vote=no')

        self.assertEqual(q['vote'], 'no')
        with self.assertRaises(AttributeError):
            q.__setitem__('something', 'bar')

        self.assertEqual(q.get('vote', 'default'), 'no')
        self.assertEqual(q.get('foo', 'default'), 'default')
        self.assertEqual(q.getlist('vote'), ['yes', 'no'])
        self.assertEqual(q.getlist('foo'), [])

        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.setlist('foo', ['bar', 'baz'])
        with self.assertRaises(AttributeError):
            q.appendlist('foo', ['bar'])

        self.assertIn('vote', q)
        self.assertNotIn('foo', q)
        self.assertEqual(list(q), ['vote'])
        self.assertEqual(list(q.items()), [('vote', 'no')])
        self.assertEqual(list(q.lists()), [('vote', ['yes', 'no'])])
        self.assertEqual(list(q.keys()), ['vote'])
        self.assertEqual(list(q.values()), ['no'])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({'foo': 'bar'})
        with self.assertRaises(AttributeError):
            q.pop('foo')
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault('foo', 'bar')
        with self.assertRaises(AttributeError):
            q.__delitem__('vote')
Ejemplo n.º 18
0
    def test_multiple_keys(self):
        """Test QueryDict with two key/value pairs with same keys."""

        q = QueryDict("vote=yes&vote=no")

        self.assertEqual(q["vote"], "no")
        with self.assertRaises(AttributeError):
            q.__setitem__("something", "bar")

        self.assertEqual(q.get("vote", "default"), "no")
        self.assertEqual(q.get("foo", "default"), "default")
        self.assertEqual(q.getlist("vote"), ["yes", "no"])
        self.assertEqual(q.getlist("foo"), [])

        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar", "baz"])
        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar", "baz"])
        with self.assertRaises(AttributeError):
            q.appendlist("foo", ["bar"])

        self.assertIn("vote", q)
        self.assertNotIn("foo", q)
        self.assertEqual(list(q), ["vote"])
        self.assertEqual(list(q.items()), [("vote", "no")])
        self.assertEqual(list(q.lists()), [("vote", ["yes", "no"])])
        self.assertEqual(list(q.keys()), ["vote"])
        self.assertEqual(list(q.values()), ["no"])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({"foo": "bar"})
        with self.assertRaises(AttributeError):
            q.pop("foo")
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault("foo", "bar")
        with self.assertRaises(AttributeError):
            q.__delitem__("vote")
Ejemplo n.º 19
0
    def test_single_key_value(self):
        """Test QueryDict with one key/value pair"""

        q = QueryDict("foo=bar")
        self.assertEqual(q["foo"], "bar")
        with self.assertRaises(KeyError):
            q.__getitem__("bar")
        with self.assertRaises(AttributeError):
            q.__setitem__("something", "bar")

        self.assertEqual(q.get("foo", "default"), "bar")
        self.assertEqual(q.get("bar", "default"), "default")
        self.assertEqual(q.getlist("foo"), ["bar"])
        self.assertEqual(q.getlist("bar"), [])

        with self.assertRaises(AttributeError):
            q.setlist("foo", ["bar"])
        with self.assertRaises(AttributeError):
            q.appendlist("foo", ["bar"])

        self.assertIn("foo", q)
        self.assertNotIn("bar", q)

        self.assertEqual(list(q), ["foo"])
        self.assertEqual(list(q.items()), [("foo", "bar")])
        self.assertEqual(list(q.lists()), [("foo", ["bar"])])
        self.assertEqual(list(q.keys()), ["foo"])
        self.assertEqual(list(q.values()), ["bar"])
        self.assertEqual(len(q), 1)

        with self.assertRaises(AttributeError):
            q.update({"foo": "bar"})
        with self.assertRaises(AttributeError):
            q.pop("foo")
        with self.assertRaises(AttributeError):
            q.popitem()
        with self.assertRaises(AttributeError):
            q.clear()
        with self.assertRaises(AttributeError):
            q.setdefault("foo", "bar")

        self.assertEqual(q.urlencode(), "foo=bar")
Ejemplo n.º 20
0
 def post(self, request, class_id, question_id, format=None):
     op = self.part_of_class(request.user, self.class_data(class_id))
     data = {}
     if op:
         user = request.user
         data = {}
         q_dict = QueryDict('', mutable=True)
         q_dict.update(request.data)
         if user:
             data['hi'] = "hi"
             q_dict.__setitem__('replied_by', user.roll_no)
             q_dict.__setitem__('ans_of_ques', question_id)
         else:
             data["Failure"] = "not found. Add the college first"
         serializer = AnswerSerializer(data=q_dict)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data,
                             status=status.HTTP_201_CREATED)
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 21
0
    def post(self, request, *args, **kwargs):
        data_dict = request.data
        mutable_query_dict = QueryDict(mutable=True)
        mutable_query_dict.update(data_dict)
        mutable_query_dict.__setitem__('user_id', request.user.id)

        if u.AccessRequest.objects.filter(user_id=request.user.id):
            return Response('A user can only make one access request',
                            status=status.HTTP_422_UNPROCESSABLE_ENTITY)

        if 'organization_email' in data_dict and u.CustomUser.objects.filter(
                email=data_dict['organization_email'].lower()):
            return Response('This email is already taken',
                            status=status.HTTP_422_UNPROCESSABLE_ENTITY)

        serializer = self.get_serializer(data=mutable_query_dict)
        serializer.is_valid(raise_exception=True)
        serializer.create(validated_data=mutable_query_dict.dict())
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=headers)
Ejemplo n.º 22
0
 def post(self, request, class_id, format=None):
     op = self.part_of_class(request.user, self.class_data(class_id))
     data = {}
     if op:
         q_dict = QueryDict('', mutable=True)
         q_dict.update(request.data)
         user = request.user
         if user:
             q_dict.__setitem__('asked_by', user.roll_no)
             q_dict.__setitem__('classdata',
                                self.class_data(class_id).class_associated)
         else:
             data["Failure"] = "not found. Add the college first"
         serializer = QuestionSerializer(data=q_dict)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data,
                             status=status.HTTP_201_CREATED)
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
     else:
         data['Access Denied'] = "User not part of the class."
Ejemplo n.º 23
0
    def patch(self, request, *args, **kwargs):
        data_dict = request.data
        mutable_query_dict = QueryDict(mutable=True)
        mutable_query_dict.update(data_dict)
        mutable_query_dict.__setitem__('user_id', request.user.id)

        instance = self.get_object()

        if 'custom_search_view' in mutable_query_dict.keys():
            custom_search_query_fe = mutable_query_dict.__getitem__(
                'custom_search_view')
            custom_search_query = fe_to_be_url(custom_search_query_fe)

            query_hash_digest = hashlib.sha256(
                custom_search_query.encode('utf-8')).hexdigest()

            try:
                result_hash_length = get_query_result_hash_and_length(
                    custom_search_query)
                result_hash = result_hash_length['hash']
            except Exception as e:
                Response('The query submitted is not valid',
                         status=status.HTTP_422_UNPROCESSABLE_ENTITY)

            if u.CustomSearch.objects.filter(
                    query_string_hash_digest=query_hash_digest).exists():
                custom_search = u.CustomSearch.objects.get(
                    query_string_hash_digest=query_hash_digest)
            else:
                custom_search = u.CustomSearch(
                    frontend_url=custom_search_query_fe,
                    query_string=custom_search_query,
                    result_hash_digest=result_hash)
                custom_search.save()
            mutable_query_dict.__setitem__('custom_search_view',
                                           custom_search.id)
            mutable_query_dict.__setitem__('last_notified_hash',
                                           custom_search.result_hash_digest)
            mutable_query_dict.__setitem__('last_number_of_results',
                                           result_hash_length['length'])

        serializer = self.get_serializer(instance, data=mutable_query_dict)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        return Response(serializer.data, status=status.HTTP_200_OK)