def __build_query_params_from_docstring__(self, callback, method=None):

        params = []
        # Combine class & method level comments. If parameters are specified
        if method is not None:
            try:
                docstring = trim_docstring(eval("callback.%s.__doc__" % (str(method).lower())))
            except:
                if str(method).lower() == 'get':
                    docstring = eval("callback.list.__doc__")
                elif str(method).lower() == 'post':
                    docstring = eval("callback.create.__doc__")
                else:
                    docstring = get_view_description(callback)

            params += self.__build_query_params_from_docstring__(callback)
        else: # Otherwise, get the class level docstring
            docstring = get_view_description(callback)

        split_lines = docstring.split('\n') if docstring else []

        for line in split_lines:
            param = line.split(' -- ')
            if len(param) == 2:
                params.append({
                    'paramType': 'query',
                    'name': param[0].strip(),
                    'description': param[1].strip(),
                    'dataType': '',
                })

        return params
    def __get_notes__(self, callback, method=None):
        """
        Returns the body of the docstring trimmed before any parameters are
        listed. First, get the class docstring and then get the method's. The
        methods will always inherit the class comments.
        """
        docstring = ""

        if method is not None:
            class_docs = self.__get_notes__(callback)
            try:
                method_docs = eval("callback.%s.__doc__" % (str(method).lower()))
            except:
                if str(method).lower() == 'get':
                    method_docs = eval("callback.list.__doc__")
                elif str(method).lower() == 'post':
                    method_docs = eval("callback.create.__doc__")
                else:
                    method_docs = None
            if class_docs is not None:
                docstring += class_docs
            if method_docs is not None:
                docstring += method_docs
        else:
            docstring = trim_docstring(get_view_description(callback))

        docstring = self.__strip_params_from_docstring__(docstring)
        docstring = docstring.replace("\n", "<br/>")

        return docstring
    def __build_query_params_from_docstring__(self, callback, method=None):

        params = []
        # Combine class & method level comments. If parameters are specified
        if method is not None:
            docstring = self.__eval_method_docstring_(callback, method)
            params += self.__build_query_params_from_docstring__(callback)
        else: # Otherwise, get the class level docstring
            docstring = get_view_description(callback)

        if docstring is None:
            return params

        split_lines = docstring.split('\n')

        for line in split_lines:
            param = line.split(' -- ')
            if len(param) == 2:
                params.append({
                    'paramType': 'query',
                    'name': param[0].strip(),
                    'description': param[1].strip(),
                    'dataType': '',
                })

        return params
Example #4
0
 def metadata(self, request):
     return {
         'name': get_view_name(self.__class__),
         'description': get_view_description(self.__class__),
         'renders': [renderer.media_type for renderer in self.renderer_classes],
         'parses': [parser.media_type for parser in self.parser_classes],
     }
Example #5
0
 def test_view_description_can_be_empty(self):
     """
     Ensure that if a view has no docstring,
     then it's description is the empty string.
     """
     class MockView(APIView):
         pass
     self.assertEqual(get_view_description(MockView), '')
Example #6
0
    def test_view_description_supports_unicode(self):
        """
        Unicode in docstrings should be respected.
        """

        self.assertEqual(
            get_view_description(ViewWithNonASCIICharactersInDocstring),
            smart_text(UTF8_TEST_DOCSTRING))
 def test_view_description_can_be_empty(self):
     """
     Ensure that if a view has no docstring,
     then it's description is the empty string.
     """
     class MockView(APIView):
         pass
     self.assertEqual(get_view_description(MockView), '')
    def test_view_description_supports_unicode(self):
        """
        Unicode in docstrings should be respected.
        """

        self.assertEqual(
            get_view_description(ViewWithNonASCIICharactersInDocstring),
            smart_text(UTF8_TEST_DOCSTRING)
        )
Example #9
0
    def test_view_description_supports_unicode(self):
        """
        Unicode in docstrings should be respected.
        """

        class MockView(APIView):
            """Проверка"""
            pass

        self.assertEqual(get_view_description(MockView), "Проверка")
 def metadata(self, request):
     """
     Return a dictionary of metadata about the view.
     Used to return responses for OPTIONS requests.
     """
     ret = SortedDict()
     ret['name'] = get_view_name(self.__class__)
     ret['description'] = get_view_description(self.__class__)
     ret['renders'] = [renderer.media_type for renderer in self.renderer_classes]
     ret['parses'] = [parser.media_type for parser in self.parser_classes]
     return ret
Example #11
0
    def metadata(self, request):
        """
        Return a dictionary of metadata about the view.
        Used to return responses for OPTIONS requests.
        """

        # This is used by ViewSets to disambiguate instance vs list views
        view_name_suffix = getattr(self, 'suffix', None)

        # By default we can't provide any form-like information, however the
        # generic views override this implementation and add additional
        # information for POST and PUT methods, based on the serializer.
        ret = SortedDict()
        ret['name'] = get_view_name(self.__class__, view_name_suffix)
        ret['description'] = get_view_description(self.__class__)
        ret['renders'] = [renderer.media_type for renderer in self.renderer_classes]
        ret['parses'] = [parser.media_type for parser in self.parser_classes]
        return ret
Example #12
0
    def metadata(self, request):
        """
        Return a dictionary of metadata about the view.
        Used to return responses for OPTIONS requests.
        """

        # This is used by ViewSets to disambiguate instance vs list views
        view_name_suffix = getattr(self, 'suffix', None)

        # By default we can't provide any form-like information, however the
        # generic views override this implementation and add additional
        # information for POST and PUT methods, based on the serializer.
        ret = SortedDict()
        ret['name'] = get_view_name(self.__class__, view_name_suffix)
        ret['description'] = get_view_description(self.__class__)
        ret['renders'] = [renderer.media_type for renderer in self.renderer_classes]
        ret['parses'] = [parser.media_type for parser in self.parser_classes]
        return ret
    def test_view_description_uses_docstring(self):
        """Ensure view descriptions are based on the docstring."""
        class MockView(APIView):
            """an example docstring
            ====================

            * list
            * list

            another header
            --------------

                code block

            indented

            # hash style header #"""

        self.assertEqual(get_view_description(MockView), DESCRIPTION)
Example #14
0
    def test_view_description_uses_docstring(self):
        """Ensure view descriptions are based on the docstring."""
        class MockView(APIView):
            """an example docstring
            ====================

            * list
            * list

            another header
            --------------

                code block

            indented

            # hash style header #"""

        self.assertEqual(get_view_description(MockView), DESCRIPTION)
    def __get_notes__(self, callback, method=None):
        """
        Returns the body of the docstring trimmed before any parameters are
        listed. First, get the class docstring and then get the method's. The
        methods will always inherit the class comments.
        """
        docstring = ""

        if method is not None:
            class_docs = self.__get_notes__(callback)
            method_docs = self.__eval_method_docstring_(callback, method)

            if class_docs is not None:
                docstring += class_docs
            if method_docs is not None:
                docstring += method_docs
        else:
            docstring = trim_docstring(get_view_description(callback))

        docstring = self.__strip_params_from_docstring__(docstring)
        docstring = docstring.replace("\n", "<br/>")

        return docstring
 def get_description(self, view):
     return get_view_description(view.__class__, html=True)
 def __get_description__(self, callback):
     """
     Returns the first sentence of the first line of the class docstring
     """
     return get_view_description(callback).split("\n")[0].split(".")[0]
Example #18
0
 def get_description(self, view):
     return get_view_description(view.__class__, html=True)