api ¤
The api
app exposes the API endpoints for the application.
It uses the rest_framework
package to provide the API endpoints.
Modules:
-
admin
– -
authentication
– -
models
– -
permissions
– -
renderer
– -
serializers
– -
views
–
admin ¤
Classes:
-
APITokenAdmin
–Custom Admin for DRF Token.
APITokenAdmin ¤
Bases: TokenAdmin
Custom Admin for DRF Token. Add supports for custom permissions.
Methods:
-
formfield_for_foreignkey
–Show all or only current user depending on permissions.
-
get_form
–Prefill the form with the current user.
-
get_queryset
–Show all or only own tokens depending on permissions.
-
get_sortable_by
–Hack to send a message depending on the status of the user.
formfield_for_foreignkey ¤
formfield_for_foreignkey(db_field: ForeignKey[Any, Any], request: HttpRequest, **kwargs: Any) -> ModelChoiceField
Show all or only current user depending on permissions.
Source code in src/firefighter/api/admin.py
get_form ¤
get_form(request: HttpRequest, obj: APITokenProxy | None = None, change: bool = False, **kwargs: Any) -> type[ModelForm[APITokenProxy]]
Prefill the form with the current user.
Source code in src/firefighter/api/admin.py
get_queryset ¤
get_queryset(request: HttpRequest) -> QuerySet[APITokenProxy]
Show all or only own tokens depending on permissions.
Source code in src/firefighter/api/admin.py
get_sortable_by ¤
Hack to send a message depending on the status of the user.
Source code in src/firefighter/api/admin.py
authentication ¤
Classes:
-
BearerTokenAuthentication
–To use
Authorization: Bearer <token>
instead ofAuthorization: Token <token>
.
BearerTokenAuthentication ¤
Bases: TokenAuthentication
To use Authorization: Bearer <token>
instead of Authorization: Token <token>
.
models ¤
Classes:
-
APITokenProxy
–Proxy mapping pk to user pk for use in admin.
APITokenProxy ¤
Bases: APIToken
Proxy mapping pk to user pk for use in admin.
Overrides default permissions.
permissions ¤
Classes:
-
StrictDjangoModelPermissions
–Custom class to restrict GET requests.
StrictDjangoModelPermissions ¤
Bases: DjangoModelPermissions
Custom class to restrict GET requests.
renderer ¤
Classes:
-
CSVRenderer
–Renderer which serializes to CSV
-
TSVRenderer
–Renderer which serializes to TSV.
CSVRenderer ¤
Bases: CSVRenderer
Renderer which serializes to CSV Override the default CSV Renderer to allow hiding header fields. Hide head by setting labels to "hidden".
Methods:
-
tablize
–Convert a list of data into a table.
tablize ¤
tablize(data: Any, header: Any | None = None, labels: Any | None = None) -> Generator[list[Any], None, None]
Convert a list of data into a table.
If there is a header provided to tablize it will efficiently yield each row as needed. If no header is provided, tablize will need to process each row in the data in order to construct a complete header. Thus, if you have a lot of data and want to stream it, you should probably provide a header to the renderer (using the header
attribute, or via the renderer_context
).
Source code in src/firefighter/api/renderer.py
TSVRenderer ¤
Bases: CSVRenderer
Renderer which serializes to TSV.
Methods:
-
tablize
–Convert a list of data into a table.
tablize ¤
tablize(data: Any, header: Any | None = None, labels: Any | None = None) -> Generator[list[Any], None, None]
Convert a list of data into a table.
If there is a header provided to tablize it will efficiently yield each row as needed. If no header is provided, tablize will need to process each row in the data in order to construct a complete header. Thus, if you have a lot of data and want to stream it, you should probably provide a header to the renderer (using the header
attribute, or via the renderer_context
).
Source code in src/firefighter/api/renderer.py
serializers ¤
Classes:
-
CreatableSlugRelatedField
–Like SlugRelatedField, but allows to create an object that is not present in DB.
-
GroupedModelSerializer
–Generic implementation for a model with a One2Many, where instead of a list we want the items grouped by a field, like costs or metrics.
CreatableSlugRelatedField ¤
Bases: SlugRelatedField[T]
, Generic[T]
Like SlugRelatedField, but allows to create an object that is not present in DB.
Methods:
-
run_validation
–Override the default validation to perform the validation before trying to create the object.
run_validation ¤
Override the default validation to perform the validation before trying to create the object.
Source code in src/firefighter/api/serializers.py
GroupedModelSerializer ¤
GroupedModelSerializer(child_serializer: type[ModelSerializer[T]], key_getter: Callable[[T], str] = lambda x: str(pk), **kwargs: Any)
Bases: RelatedField[T, Any, Any]
, Generic[T]
Generic implementation for a model with a One2Many, where instead of a list we want the items grouped by a field, like costs or metrics.
Source code in src/firefighter/api/serializers.py
views ¤
Modules:
incidents ¤
Classes:
-
CreateIncidentViewSet
– -
IncidentViewSet
– -
ProcessAfterResponse
–Custom DRF Response, to trigger the Slack workflow after creating the incident and returning HTTP 201.
CreateIncidentViewSet ¤
Bases: CreateModelMixin
, GenericViewSet[Incident]
Methods:
-
create
–Allow to create an incident.
create ¤
Allow to create an incident. Requires a valid Bearer token, that you can create in the back-office if you have the right permissions.
Source code in src/firefighter/api/views/incidents.py
IncidentViewSet ¤
Bases: RetrieveModelMixin
, ListModelMixin
, AdvancedGenericViewSet[Incident]
Methods:
-
list
–List all incidents. Allows to show or hide tags which is DB intensive, with the show_tags parameters.
Attributes:
-
labels
(dict[str, str]
) –Dict mapping attributes/properties to a more friendly string to be shown in the header row for CSV/TSV renders.
labels class-attribute
instance-attribute
¤
Dict mapping attributes/properties to a more friendly string to be shown in the header row for CSV/TSV renders.
E.g. labels = {"slack_channel_name": "Slack Channel"}
list ¤
List all incidents. Allows to show or hide tags which is DB intensive, with the show_tags parameters.
status
and _status__*
uses an enum:
Source code in src/firefighter/api/views/incidents.py
ProcessAfterResponse ¤
Bases: Response
Custom DRF Response, to trigger the Slack workflow after creating the incident and returning HTTP 201.