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:

# 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:

# 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")),
]
class globus_portal_framework.views.generic.SearchView(template: str = None, results_per_page: int = 10)

Bases: View

Customize components of a search during different phases of receiving a request from a user to rendering a template. This is a handy class to customize if you want to modify the request sent to Globus Search, or customize the data received by Globus Search before it is rendered on the page.

See post_search for customizing the result before it is sent to Globus Search.

See process_result to override how the result is processed before it is rendered by the template.

property query: Mapping[str, str]

Process the query using globus_portal_framework.gsearch.get_search_query

property filters: Mapping[str, str]

Get filters using globus_portal_framework.gsearch.get_search_filters

property facets: Mapping[str, str]

Get facets using globus_portal_framework.gsearch.prepare_search_facets

property page: int

Get the query param for the user’s desired page, or 1 if not specified

property offset: int

Get the calculated offset based on the page number and configured results-per-page. This value is sent in the request to Globus Search

property sort: list

Get any index defined sort options defined per-index in settings.py. Default unsorted.

get_index_info(index_uuid: str = None) Mapping[str, str]

Fetch info on an index defined in settings.py

get_search_client() SearchClient

Fetch a live search client, either loaded with user credentials or generic if not logged in.

If you want to inject or modify any parameters in the globus_sdk.SearchClient.post_search function, you can override this function.

set_search_session_data(index: str)

Set some metadata about the search in the user’s session. This will record some data about their last search to fill in some basic DGPF context, such as the ‘Back To Search’ link on a result detail page.

process_result(index_info: Mapping[str, str], search_result: Mapping[str, str]) Mapping[str, str]

Process the result from Globus Search into data ready to be rendered into search templates.

get_context_data(index: str) Mapping[str, str]

calls post_search and process_result. If there is an error, returns a context with a single ‘error’ var and logs the exception.

get(request: HttpRequest, index: str, *args, **kwargs)

Fetches the context, then renders a page. Calls ‘get_template’, which checks to see if there is an overridden page for a given index. If there is, that is used instead. Otherwise, standard Django template precedence loading is used.

If there is an error, a Django message is sent which can be rendered by templates that support them.

class globus_portal_framework.views.generic.DetailView(template=None)

Bases: View

Show a single detail page to a user.

get_context_data(index: str, subject: str) Mapping[str, str]

Call globus_portal_framework.gsearch.get_subject using the index, subject, and user and return the result.

get(request: HttpRequest, index: str, subject: str)

Get context data, and return a rendered search view, selecting the template with globus_portal_framework.gsearch.get_template.