-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from NickolausDS/api-docs
Add docs for Generic Class-Based views
- Loading branch information
Showing
3 changed files
with
140 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.. _generic_views_reference: | ||
|
||
Generic Class-Based Views | ||
========================= | ||
|
||
Generic views allow for more fine-grained customization of Django Globus Portal Framework viwes. | ||
They are built on Django Generic Class-Based views. DGPF generic views should be inherited with | ||
specific desired functionality overridden. The URL conf also needs to be updated to override the | ||
original DGPF views. | ||
|
||
An example here shows usage of a class-based view which requires login and allows extending filters: | ||
|
||
.. code-block:: python | ||
# views.py | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from globus_portal_framework.views.generic import SearchView | ||
class MyCustomSearchView(LoginRequiredMixin, SearchView): | ||
@property | ||
def filters(self): | ||
"""Allow custom default_filters per-index in settings.py""" | ||
return super().filters + self.get_index_info().get('default_filters', []) | ||
And here shows overriding the built-in DPGF Search View in ``urls.py``: | ||
|
||
.. code-block:: python | ||
# urls.py | ||
from django.urls import path, include | ||
import globus_portal_framework.urls # Allows index converter usage | ||
from testportal.views import MyCustomSearchView | ||
urlpatterns = [ | ||
path("<index:index>/", MyCustomSearchView.as_view(), name="search"), | ||
# Note, you must define your custom view above the originals for Django to use it! | ||
path("", include("globus_portal_framework.urls")), | ||
] | ||
.. automodule:: globus_portal_framework.views.generic | ||
:members: | ||
:member-order: bysource | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters