mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Make view
a property
Encapsulates check for a view instance.
This commit is contained in:
parent
183f13ccf4
commit
dc92b55c84
|
@ -263,10 +263,23 @@ class APIViewSchemaDescriptor(object):
|
|||
Responsible for per-view instrospection and schema generation.
|
||||
"""
|
||||
def __get__(self, instance, owner):
|
||||
# ???: Is this TOO simple? (Option is to return a new instance each time.)
|
||||
self.view = instance
|
||||
return self
|
||||
|
||||
@property
|
||||
def view(self):
|
||||
"""View property."""
|
||||
assert self._view is not None, "Schema generation REQUIRES a view instance. (Hint: you accessed `schema` from the view class rather than an instance.)"
|
||||
return self._view
|
||||
|
||||
@view.setter
|
||||
def view(self, value):
|
||||
self._view = value
|
||||
|
||||
@view.deleter
|
||||
def view(self):
|
||||
self._view = None
|
||||
|
||||
def get_link(self, path, method, base_url):
|
||||
"""
|
||||
Generate `coreapi.Link` for self.view, path and method.
|
||||
|
@ -279,10 +292,6 @@ class APIViewSchemaDescriptor(object):
|
|||
* method: The HTTP request method.
|
||||
* base_url: The project "mount point" as given to SchemaGenerator
|
||||
"""
|
||||
# TODO: make `view` a property: move this check to getter.
|
||||
assert self.view is not None, "Schema generation REQUIRES a view instance. (Hint: you accessed `schema` from the view CLASS rather than an instance.)"
|
||||
view = self.view
|
||||
|
||||
fields = self.get_path_fields(path, method)
|
||||
fields += self.get_serializer_fields(path, method)
|
||||
fields += self.get_pagination_fields(path, method)
|
||||
|
|
Loading…
Reference in New Issue
Block a user